public void CreateStateAdminRepUserProfile(StateUserProfileModel model, string username, string createdBy) { try { var creator = _userProfileRepository.GetPersonalInformationByUserName(createdBy); Mapper.CreateMap<StateUserProfileModel, UserProfile>(); _unitOfWork.BeginTransaction(); var entity = Mapper.Map<StateUserProfileModel, UserProfile>(model); entity.IsActive = entity.IsApproved = true; entity.CreatedBy = createdBy; entity.StateId = creator.StateId; entity.Username = username; entity.CreatedDate = DateTime.Now; entity.RoleId = Convert.ToInt32(RolesConstants.Enum.SetupStateAdmin); _repository.Insert(entity); _unitOfWork.Commit(); } catch (Exception) { _unitOfWork.Rollback(); throw; } }
public async Task<IHttpActionResult> CreateStateAdminRep(StateUserProfileModel model) { try { var roles = new List<string> { RolesConstants.SetupStateAdmin }; var username = _utilityService.GetUsername(model.FirstName, model.LastName); var result = await CreateApplicationUser(username, roles); if (result == null) { _userProfileService.CreateStateAdminRepUserProfile(model, username, User.Identity.Name); return Ok(); } } catch (EdLightException ex) { return BadRequest(ex.Message); } return BadRequest(ModelState); }