public async Task <string> FinishRegistration(FinishRegistrationModel model) { var user = await _userManager.FindByIdAsync(_userContext.GetUserId()); if (user == null) { throw new NotFoundException("User not found"); } var gym = model.OwnGym == true ? await SaveNewGym(model.GymName, model.CountryId) : await _institutionsRepository.Get(model.InstitutionId ?? 0); var entity = new UserRoleRequest { RoleId = model.RoleId, UserId = _userContext.GetUserId(), Status = UserRoleRequestStatus.Pending, InstitutionId = gym.Id }; await _userRoleRequestsRepository.Save(entity); user.InstitutionId = gym.Id; user.CountryId = model.CountryId; user.Surname = model.Surname; user.FirstName = model.FirstName; await _userManager.UpdateAsync(user); await _userManager.AddToRoleAsync(user, "Guest"); var roles = await _userManager.GetRolesAsync(user); return(_tokenGenerator.GenerateToken(user, roles)); }
public async Task <InstitutionResponseModel> Get(int id) { var institution = await _repository.Get(id); return(_mapper.Map <InstitutionResponseModel>(institution)); }