public async Task CreateOrUpdateStateInfo(StateInfoCreateOrUpdateInput input) { await CheckValidation(input); if (input.Id.HasValue) { await UpdateStateInfoAsync(input); } else { await CreateStateInfoAsync(input); } }
private async Task CheckValidation(StateInfoCreateOrUpdateInput input) { var existingObj = (await _stateInfoRepository.GetAll().AsNoTracking() .FirstOrDefaultAsync(l => l.Code == input.Code)); if (existingObj != null && existingObj.Id != input.Id) { throw new UserFriendlyException(L("ThisCodeAlreadyExists")); } existingObj = (await _stateInfoRepository.GetAll().AsNoTracking() .FirstOrDefaultAsync(l => l.Name == input.Name)); if (existingObj != null && existingObj.Id != input.Id) { throw new UserFriendlyException(L("ThisNameAlreadyExists")); } }
public async Task <StateInfoCreateOrUpdateInput> GetStateInfoForEdit(NullableIdDto <int> input) { //Getting all available roles var output = new StateInfoCreateOrUpdateInput(); if (input.Id.HasValue) { //Editing an existing user var stateInfo = await _stateInfoRepository.GetAsync(input.Id.Value); if (stateInfo != null) { ObjectMapper.Map <StateInfo, StateInfoCreateOrUpdateInput>(stateInfo, output); } } return(output); }
private async Task CreateStateInfoAsync(StateInfoCreateOrUpdateInput input) { var stateInfo = ObjectMapper.Map <StateInfo>(input); await _stateInfoRepository.InsertAsync(stateInfo); }