Example #1
0
        private async Task CreatePlaqueToOfficerAsync(PlaqueToOfficerCreateOrUpdateInput input)
        {
            var plaqueToContractor = _plaqueToContractorRepository.Get(input.PlaqueToContractorId.Value);

            plaqueToContractor.LastCode = input.ToCode;
            var plaqueToOfficer = ObjectMapper.Map <PlaqueToOfficer>(input);
            await _plaqueToContractorRepository.UpdateAsync(plaqueToContractor);

            await _plaqueToOfficerRepository.InsertAsync(plaqueToOfficer);
        }
Example #2
0
        public async Task CreateOrUpdatePlaqueToOfficer(PlaqueToOfficerCreateOrUpdateInput input)
        {
            await CheckValidation(input);

            if (input.Id.HasValue)
            {
                await UpdatePlaqueToOfficerAsync(input);
            }
            else
            {
                await CreatePlaqueToOfficerAsync(input);
            }
        }
Example #3
0
        private async Task CheckValidation(PlaqueToOfficerCreateOrUpdateInput input)
        {
            if (input.PlaqueCount <= 0)
            {
                throw new UserFriendlyException(L("ThisCodeRangeHasOverlap"));
            }
            var plaqueToContractorQuery = _plaqueToContractorRepository.GetAll().AsNoTracking()
                                          .Include(x => x.PlaqueToState)
                                          .ThenInclude(x => x.PlaqueStore)
                                          .Where(x => x.Contractor.Id == input.ContractorId && x.PlaqueToState.PlaqueStore.SpeciesId == input.SpeciesInfoId && x.ToCode != x.LastCode);
            var plaqueToContractor = await plaqueToContractorQuery.FirstOrDefaultAsync(x => (x.LastCode != 0 && x.ToCode - x.LastCode >= input.PlaqueCount) || (x.LastCode == 0 && x.ToCode - x.FromCode + 1 >= input.PlaqueCount));

            if (plaqueToContractor != null)
            {
                input.FromCode             = plaqueToContractor.LastCode != 0 ? +plaqueToContractor.LastCode + 1 : plaqueToContractor.FromCode;
                input.ToCode               = input.FromCode + input.PlaqueCount.Value - 1;
                input.PlaqueToContractorId = plaqueToContractor.Id;
            }
            else
            {
                throw new UserFriendlyException(L("RemainInCodeRange", input.PlaqueCount));
            }
        }
Example #4
0
 private async Task UpdatePlaqueToOfficerAsync(PlaqueToOfficerCreateOrUpdateInput input)
 {
     var plaqueToOfficer = ObjectMapper.Map <PlaqueToOfficer>(input);
     await _plaqueToOfficerRepository.UpdateAsync(plaqueToOfficer);
 }
Example #5
0
        public async Task <PlaqueToOfficerGetForEditOutput> GetPlaqueToOfficerForEdit(NullableIdDto <int> input)
        {
            PlaqueToOfficer plaqueToOfficer = null;

            if (input.Id.HasValue)
            {
                plaqueToOfficer = await _plaqueToOfficerRepository
                                  .GetAll()
                                  .Include(x => x.PlaqueToContractor)
                                  .ThenInclude(x => x.PlaqueToState)
                                  .ThenInclude(x => x.PlaqueStore)
                                  .Include(x => x.PlaqueToContractor)
                                  .ThenInclude(x => x.Contractor)
                                  .ThenInclude(x => x.CityInfo)
                                  .ThenInclude(x => x.StateInfo)
                                  .Where(x => x.Id == input.Id.Value)
                                  .FirstOrDefaultAsync();
            }
            //Getting all available roles
            var output = new PlaqueToOfficerGetForEditOutput();

            //plaqueToOfficer
            var newPlaqueToOfficer = new PlaqueToOfficerCreateOrUpdateInput();

            newPlaqueToOfficer.SetTime = newPlaqueToOfficer.SetTime.GetShamsi();
            output.PlaqueToOfficer     = plaqueToOfficer != null
                ? ObjectMapper.Map <PlaqueToOfficerCreateOrUpdateInput>(plaqueToOfficer)
                : newPlaqueToOfficer;

            //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 if (isOfficer)
            {
                var officer = _officerRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId);
                stateInfoQuery = stateInfoQuery.Where(x => x.Id == officer.StateInfoId);
            }
            else
            {
                stateInfoQuery = stateInfoQuery.Where(x => false);
            }
            output.StateInfos = stateInfoQuery
                                .ToList()
                                .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name))
                                .ToList();

            //Contractors
            if (output.PlaqueToOfficer.StateInfoId.HasValue)
            {
                output.Contractors = _contractorRepository
                                     .GetAll()
                                     .Where(x => x.StateInfoId == output.PlaqueToOfficer.StateInfoId.Value)
                                     .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name))
                                     .ToList();
            }

            if (output.PlaqueToOfficer.ContractorId.HasValue)
            {
                //OfficerInfos
                output.Officers = _officerRepository
                                  .GetAll().Include(x => x.Contractor)
                                  .Where(x => x.Contractor.Id == output.PlaqueToOfficer.ContractorId.Value)
                                  .Select(c => new ComboboxItemDto(c.Id.ToString(),
                                                                   c.Contractor.FirmName + " " + c.NationalCode + " (" + c.Name + "," + c.Family + ")"))
                                  .ToList();
            }

            output.SpeciesInfos = _speciesInfoRepository
                                  .GetAll()
                                  .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name))
                                  .ToList();

            return(output);
        }