public UserWithRolesOutputModel ConvertUserPositionDTOToUserWithRolesOutputModel(UserPositionDTO user) // нужен ли foreach? { List <string> userRoles = new List <string>(); foreach (RoleIdDTO n in user.Roles) { if (n != null) { userRoles.Add(n.Name); } } UserWithRolesOutputModel userOut = new UserWithRolesOutputModel(user.Id, user.FirstName, user.LastName, user.BirthDate, user.Login, user.Password, user.Email, user.Phone, userRoles); return(userOut); }
public IActionResult GetUserById(int id) { UserMapper mapper = new UserMapper(); AdminDataAccess adm = new AdminDataAccess(); UserWithRolesOutputModel user = new UserWithRolesOutputModel(); UserPositionDTO getUser = adm.GetUserWithRolesByUserId(id); if (getUser == null) { return(BadRequest("Такого пользователя не существует")); } else { user = mapper.ConvertUserPositionDTOToUserWithRolesOutputModel(getUser); return(Ok(user)); } }