private async Task CreatePlaqueToStateAsync(PlaqueToStateCreateOrUpdateInput input) { var plaqueStore = _plaqueStoreRepository.Get(input.PlaqueStoreId.Value); plaqueStore.LastCode = input.ToCode; var plaqueToState = ObjectMapper.Map <PlaqueToState>(input); await _plaqueStoreRepository.UpdateAsync(plaqueStore); await _plaqueToStateRepository.InsertAsync(plaqueToState); }
public async Task CreateOrUpdatePlaqueToState(PlaqueToStateCreateOrUpdateInput input) { await CheckValidation(input); if (input.Id.HasValue) { await UpdatePlaqueToStateAsync(input); } else { await CreatePlaqueToStateAsync(input); } }
private async Task CheckValidation(PlaqueToStateCreateOrUpdateInput input) { if (input.PlaqueCount <= 0) { throw new UserFriendlyException(L("ThisCodeRangeHasOverlap")); } var plaqueStoreQuery = _plaqueStoreRepository.GetAll().AsNoTracking() .Where(x => x.SpeciesId == input.SpeciesInfoId && x.ToCode != x.LastCode); var plaqueStore = await plaqueStoreQuery.FirstOrDefaultAsync(x => (x.LastCode != 0 && x.ToCode - x.LastCode >= input.PlaqueCount) || (x.LastCode == 0 && x.ToCode - x.FromCode + 1 >= input.PlaqueCount)); if (plaqueStore != null) { input.FromCode = plaqueStore.LastCode != 0 ? +plaqueStore.LastCode + 1 : plaqueStore.FromCode; input.ToCode = input.FromCode + input.PlaqueCount.Value - 1; input.PlaqueStoreId = plaqueStore.Id; } else { throw new UserFriendlyException(L("RemainInCodeRange", input.PlaqueCount)); } }
public async Task <PlaqueToStateGetForEditOutput> GetPlaqueToStateForEdit(NullableIdDto <int> input) { PlaqueToState plaqueToState = null; if (input.Id.HasValue) { plaqueToState = await _plaqueToStateRepository .GetAll() .Include(x => x.PlaqueStore) .Where(x => x.Id == input.Id.Value) .FirstOrDefaultAsync(); } //Getting all available roles var output = new PlaqueToStateGetForEditOutput(); //plaqueToState var newPlaqueToState = new PlaqueToStateCreateOrUpdateInput(); newPlaqueToState.SetTime = newPlaqueToState.SetTime.GetShamsi(); output.PlaqueToState = plaqueToState != null ? ObjectMapper.Map <PlaqueToStateCreateOrUpdateInput>(plaqueToState) : newPlaqueToState; //StateInfos var user = await UserManager.GetUserByIdAsync(AbpSession.GetUserId()); var isAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.Admin); var isSysAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.SysAdmin); var isStateAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.StateAdmin); var isCityAdmin = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.CityAdmin); var isOfficer = await UserManager.IsInRoleAsync(user, StaticRoleNames.Host.Officer); var stateInfoQuery = _stateInfoRepository.GetAll(); if (isAdmin || isSysAdmin) { stateInfoQuery = stateInfoQuery; } else if (isStateAdmin) { var union = _unionInfoRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId); stateInfoQuery = stateInfoQuery.Where(x => x.Id == union.StateInfoId); } else if (isCityAdmin) { var contractor = _contractorRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId); stateInfoQuery = stateInfoQuery.Where(x => x.Id == contractor.StateInfoId); } else { stateInfoQuery = stateInfoQuery.Where(x => false); } output.StateInfos = stateInfoQuery .ToList() .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name)) .ToList(); output.SpeciesInfos = _speciesInfoRepository .GetAll() .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name)) .ToList(); return(output); }
private async Task UpdatePlaqueToStateAsync(PlaqueToStateCreateOrUpdateInput input) { var plaqueToState = ObjectMapper.Map <PlaqueToState>(input); await _plaqueToStateRepository.UpdateAsync(plaqueToState); }