Exemplo n.º 1
0
        public async Task SetHerdCertificated(int input)
        {
            Herd herd = _herdRepository.FirstOrDefault(x => x.Id == input);

            herd.IsCertificated  = true;
            herd.CertificateDate = Clock.Now;

            await _herdRepository.UpdateAsync(herd);
        }
Exemplo n.º 2
0
        public async Task <GetHerdForEditOutput> GetHerdForEdit(NullableIdDto <int> input)
        {
            Herd herd = null;

            if (input.Id.HasValue)
            {
                herd = await _herdRepository.GetAll()
                       .Include(x => x.VillageInfo)
                       .Include(x => x.RegionInfo)
                       .Include(x => x.CityInfo)
                       .Include(x => x.StateInfo)
                       .FirstOrDefaultAsync(x => x.Id == input.Id.Value);
            }

            var output = new GetHerdForEditOutput();

            //herd
            output.Herd = herd != null
                ? ObjectMapper.Map <HerdCreateOrUpdateInput>(herd)
                : new HerdCreateOrUpdateInput();

            //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();

            if (output.Herd.StateInfoId.HasValue)
            {
                output.CityInfos = _cityInfoRepository.GetAll()
                                   .Where(x => x.StateInfoId == output.Herd.StateInfoId)
                                   .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name))
                                   .ToList();

                output.UnionInfos = _unionInfoRepository.GetAll()
                                    .Where(x => x.StateInfoId == output.Herd.StateInfoId)
                                    .Select(c => new ComboboxItemDto(c.Id.ToString(), c.UnionName))
                                    .ToList();

                output.Contractors = _contractorRepository
                                     .GetAllList()
                                     .Where(x => x.StateInfoId == output.Herd.StateInfoId)
                                     .Select(c => new ComboboxItemDto(c.Id.ToString(), c.FirmName + " (" + c.Name + "," + c.Family + ")"))
                                     .ToList();
            }

            if (output.Herd.CityInfoId.HasValue)
            {
                output.RegionInfos = _regionInfoRepository.GetAll()
                                     .Where(x => x.CityInfoId == output.Herd.CityInfoId)
                                     .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name))
                                     .ToList();
            }

            if (output.Herd.RegionInfoId.HasValue)
            {
                output.VillageInfos = _villageInfoRepository.GetAll()
                                      .Where(x => x.RegionInfoId == output.Herd.RegionInfoId)
                                      .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name))
                                      .ToList();
            }

            output.ActivityInfos = _activityInfoRepository
                                   .GetAllList()
                                   .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name))
                                   .ToList();

            return(output);
        }