private async Task CreateUnionEmployeeAsync(UnionEmployeeCreateOrUpdateInput input) { var nationalCode = input.NationalCode.Replace("-", ""); var user = new User { IsActive = true, ShouldChangePasswordOnNextLogin = true, UserName = input.UserName, EmailAddress = input.UserName + "@mgnsys.ir", Name = input.Name, Surname = input.Family }; user.Password = _passwordHasher.HashPassword(user, nationalCode); CheckErrors(await UserManager.CreateAsync(user)); await CurrentUnitOfWork.SaveChangesAsync(); var officerRole = _roleManager.GetRoleByName(StaticRoleNames.Host.StateAdmin); long userId = user.ToUserIdentifier().UserId; user.Roles = new List <UserRole>(); user.Roles.Add(new UserRole(null, user.Id, officerRole.Id)); if (userId > 0) { var unionEmployee = ObjectMapper.Map <UnionEmployee>(input); unionEmployee.UserId = userId; await _unionEmployeeRepository.InsertAsync(unionEmployee); } else { throw new UserFriendlyException(L("AnErrorOccurred")); } }
public async Task CreateOrUpdateUnionEmployee(UnionEmployeeCreateOrUpdateInput input) { await CheckValidation(input); if (input.Id.HasValue) { await UpdateUnionEmployeeAsync(input); } else { await CreateUnionEmployeeAsync(input); } }
private async Task UpdateUnionEmployeeAsync(UnionEmployeeCreateOrUpdateInput input) { var user = await UserManager.GetUserByIdAsync(input.UserId); user.Name = input.Name; user.Surname = input.Family; user.UserName = input.UserName; user.EmailAddress = input.UserName + "@mgnsys.ir"; CheckErrors(await UserManager.UpdateAsync(user)); await CurrentUnitOfWork.SaveChangesAsync(); var unionEmployee = ObjectMapper.Map <UnionEmployee>(input); await _unionEmployeeRepository.UpdateAsync(unionEmployee); }
public async Task <UnionEmployeeCreateOrUpdateInput> GetUnionEmployeeForEdit(int unionInfoId, NullableIdDto <int> input) { var output = new UnionEmployeeCreateOrUpdateInput(); output.UnionInfoId = unionInfoId; if (input.Id.HasValue) { var unionEmployee = await _unionEmployeeRepository.GetAll() .Include(x => x.User) .FirstOrDefaultAsync(x => x.Id == input.Id.Value); if (unionEmployee != null) { ObjectMapper.Map <UnionEmployee, UnionEmployeeCreateOrUpdateInput>(unionEmployee, output); } } return(output); }
private async Task CheckValidation(UnionEmployeeCreateOrUpdateInput input) { }