public async Task CreateOrUpdateBirthTypeInfo(BirthTypeInfoCreateOrUpdateInput input) { await CheckValidation(input); if (input.Id.HasValue) { await UpdateBirthTypeInfoAsync(input); } else { await CreateBirthTypeInfoAsync(input); } }
private async Task CheckValidation(BirthTypeInfoCreateOrUpdateInput input) { var existingObj = (await _birthTypeInfoRepository.GetAll().AsNoTracking() .FirstOrDefaultAsync(l => l.Code == input.Code)); if (existingObj != null && existingObj.Id != input.Id) { throw new UserFriendlyException(L("ThisCodeAlreadyExists")); } existingObj = (await _birthTypeInfoRepository.GetAll().AsNoTracking() .FirstOrDefaultAsync(l => l.Name == input.Name)); if (existingObj != null && existingObj.Id != input.Id) { throw new UserFriendlyException(L("ThisNameAlreadyExists")); } }
public async Task <BirthTypeInfoCreateOrUpdateInput> GetBirthTypeInfoForEdit(NullableIdDto <int> input) { //Getting all available roles var output = new BirthTypeInfoCreateOrUpdateInput(); if (input.Id.HasValue) { //Editing an existing user var birthTypeInfo = await _birthTypeInfoRepository.GetAsync(input.Id.Value); if (birthTypeInfo != null) { ObjectMapper.Map <BirthTypeInfo, BirthTypeInfoCreateOrUpdateInput>(birthTypeInfo, output); } } return(output); }
private async Task UpdateBirthTypeInfoAsync(BirthTypeInfoCreateOrUpdateInput input) { var birthTypeInfo = ObjectMapper.Map <BirthTypeInfo>(input); await _birthTypeInfoRepository.UpdateAsync(birthTypeInfo); }