private async Task CheckValidation(PlaqueStoreCreateOrUpdateInput input) { if (input.FromCode > input.ToCode) { throw new UserFriendlyException(L("ThisCodeRangeHasOverlap")); } var species = _speciesInfoRepository.Get(input.SpeciesId.Value); if (input.FromCode < species.FromCode) { input.FromCode += species.FromCode; input.ToCode += species.FromCode; } if (input.FromCode < species.FromCode || input.FromCode > species.ToCode || input.ToCode < species.FromCode || input.ToCode > species.ToCode) { throw new UserFriendlyException(L("ThisCodeRangeShouldBe", species.Name, species.FromCode, species.ToCode)); } var existingObj = (await _plaqueStoreRepository.GetAll().AsNoTracking() .FirstOrDefaultAsync(u => (u.Id != input.Id) && ((u.FromCode.CompareTo(input.FromCode) <= 0 && u.ToCode.CompareTo(input.FromCode) >= 0) || (u.FromCode.CompareTo(input.ToCode) <= 0 && u.ToCode.CompareTo(input.ToCode) >= 0)))); if (existingObj != null && existingObj.Id != input.Id) { throw new UserFriendlyException(L("ThisCodeRangeHasOverlap", existingObj.FromCode, existingObj.ToCode)); } }
public async Task <PlaqueStoreGetForEditOutput> GetPlaqueStoreForEdit(NullableIdDto <int> input) { PlaqueStore plaqueStore = null; if (input.Id.HasValue) { plaqueStore = await _plaqueStoreRepository .GetAll() .Where(x => x.Id == input.Id.Value) .FirstOrDefaultAsync(); } //Getting all available roles var output = new PlaqueStoreGetForEditOutput(); //plaqueStore var newPlaqueStore = new PlaqueStoreCreateOrUpdateInput(); newPlaqueStore.SetTime = newPlaqueStore.SetTime.GetShamsi(); output.PlaqueStore = plaqueStore != null ? ObjectMapper.Map <PlaqueStoreCreateOrUpdateInput>(plaqueStore) : newPlaqueStore; //speciesInfo output.SpecieInfos = _speciesInfoRepository .GetAllList() .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name)) .ToList(); output.Manufacturers = _manufacturerRepository .GetAllList() .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name)) .ToList(); return(output); }
public async Task CreateOrUpdatePlaqueStore(PlaqueStoreCreateOrUpdateInput input) { await CheckValidation(input); if (input.Id.HasValue) { await UpdatePlaqueStoreAsync(input); } else { await CreatePlaqueStoreAsync(input); } }
private async Task CreatePlaqueStoreAsync(PlaqueStoreCreateOrUpdateInput input) { var plaqueStore = ObjectMapper.Map <PlaqueStore>(input); await _plaqueStoreRepository.InsertAsync(plaqueStore); }