Skip to content

Instantly share code, notes, and snippets.

@sumitkharche
Created January 6, 2020 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumitkharche/128ec5ae078db9a66b6860b9b280b899 to your computer and use it in GitHub Desktop.
Save sumitkharche/128ec5ae078db9a66b6860b9b280b899 to your computer and use it in GitHub Desktop.
StudentController
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
namespace automapper_sample.Controllers
{
[Route("api/[controller]")]
public class StudentController : Controller
{
private readonly IMapper _mapper;
public StudentController(IMapper mapper)
{
_mapper = mapper;
}
// GET: api/<controller>
[HttpGet]
public Student Get()
{
StudentDTO studentDTO = new StudentDTO()
{
Name = "Student 1",
Age = 25,
City = "New York"
};
return _mapper.Map<Student>(studentDTO);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment