Нужно предоставить WebApi доступ к UserManager<ApplicationUser> (AspNetCore.Identity).
Для этого нужно сделать mapping ApplicationUser в ApplicationUserDto.
Возникает исключение
Exception = "\nUnmapped members were found. Review the types and members below.\nAdd a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type\nFor no matching constructor, add a no-arg ctor, add optional arguments, or map all of...
Настройка AutoMapper:
public class MappingProfile : Profile
{
public MappingProfile()
{
CreateMap<ApplicationUser, ApplicationUserDto>().ReverseMap();
}
}
DTO:
public class ApplicationUserDto
{
public string Id { get; set; }
public string UserName { get; set; }
public Company Company { get; set; }
public string Name { get; set; }
public string Role { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
}
ApplicationUser:
public class ApplicationUser : IdentityUser
{
public Company Company { get; set; }
}
Вызов маппера:
[HttpGet]
public async Task<IActionResult> Get()
{
var users = _userManager.Users.Include(u => u.Company).ToList();
try
{
var usersDto = _mapper.Map<ApplicationUserDto>(users);
}
catch (Exception e)
{
Console.WriteLine(e); //!!!! ЛОВЛЮ ИСКЛЮЧЕНИЕ
}
await Task.CompletedTask;
return new JsonResult(usersDto);
}
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости