public async Task CreateOrUpdateSexInfo(SexInfoCreateOrUpdateInput input) { await CheckValidation(input); if (input.Id.HasValue) { await UpdateSexInfoAsync(input); } else { await CreateSexInfoAsync(input); } }
private async Task CheckValidation(SexInfoCreateOrUpdateInput input) { var existingObj = (await _sexInfoRepository.GetAll().AsNoTracking() .FirstOrDefaultAsync(l => l.Code == input.Code)); if (existingObj != null && existingObj.Id != input.Id) { throw new UserFriendlyException(L("ThisCodeAlreadyExists")); } existingObj = (await _sexInfoRepository.GetAll().AsNoTracking() .FirstOrDefaultAsync(l => l.Name == input.Name)); if (existingObj != null && existingObj.Id != input.Id) { throw new UserFriendlyException(L("ThisNameAlreadyExists")); } }
public async Task <SexInfoCreateOrUpdateInput> GetSexInfoForEdit(NullableIdDto <int> input) { //Getting all available roles var output = new SexInfoCreateOrUpdateInput(); if (input.Id.HasValue) { //Editing an existing user var sexInfo = await _sexInfoRepository.GetAsync(input.Id.Value); if (sexInfo != null) { ObjectMapper.Map <SexInfo, SexInfoCreateOrUpdateInput>(sexInfo, output); } } return(output); }
private async Task UpdateSexInfoAsync(SexInfoCreateOrUpdateInput input) { var sexInfo = ObjectMapper.Map <SexInfo>(input); await _sexInfoRepository.UpdateAsync(sexInfo); }