Example #1
0
        public void AgencyFilter_Default_Constructor()
        {
            // Arrange
            // Act
            var filter = new AgencyFilter();

            // Assert
            filter.Page.Should().Be(1);
            filter.Quantity.Should().Be(10);
            filter.Id.Should().BeNull();
            filter.ParentId.Should().Be(0);
            filter.IsDisabled.Should().BeNull();
            filter.Name.Should().BeNull();
            filter.Sort.Should().BeNull();
        }
Example #2
0
        public async Task <ProcessResult <int> > CountAsync(AgencyFilter filter)
        {
            IQueryable <Agency> q = context.Agencies;

            q = SetFilter(q, filter);

            Func <Task <int> > action = async() =>
            {
                var countItems = await q.CountAsync();

                return(countItems);
            };

            return(await Process.RunAsync(action));
        }
Example #3
0
        /// <summary>
        /// Get a page of agencies from the datasource.
        /// The filter will allow queries to search for the following property values; Name, Description, ParentId.
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public Paged <Agency> Get(AgencyFilter filter = null)
        {
            this.User.ThrowIfNotAuthorized(Permissions.SystemAdmin);

            var query = this.Context.Agencies.AsNoTracking();

            if (filter != null)
            {
                if (filter.Page < 1)
                {
                    filter.Page = 1;
                }
                if (filter.Quantity < 1)
                {
                    filter.Quantity = 1;
                }
                if (filter.Quantity > 50)
                {
                    filter.Quantity = 50;
                }
                if (filter.Sort == null)
                {
                    filter.Sort = new string[] { }
                }
                ;

                if (!string.IsNullOrWhiteSpace(filter.Name))
                {
                    query = query.Where(a => EF.Functions.Like(a.Name, $"%{filter.Name}%"));
                }
                if (filter.IsDisabled != null)
                {
                    query = query.Where(a => a.IsDisabled == filter.IsDisabled);
                }
                if (filter.Id > 0)
                {
                    query = query.Where(a => a.Id == filter.Id);
                }

                if (filter.Sort.Any())
                {
                    query = query.OrderByProperty(filter.Sort);
                }
            }
            var agencies = query.Skip((filter.Page - 1) * filter.Quantity).Take(filter.Quantity);

            return(new Paged <Agency>(agencies.ToArray(), filter.Page, filter.Quantity, query.Count()));
        }
Example #4
0
        public async Task <IActionResult> Count(AgencyFilter filter)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _AgencyService.CountAsync(filter);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }

            return(Ok(result));
        }
Example #5
0
        public void AgencyFilter_Constructor_03()
        {
            // Arrange
            var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery("?page=2&quantity=3&id=3&parentId=6&name=test&isDisabled=true&sort=one,two");

            // Act
            var filter = new AgencyFilter(query);

            // Assert
            filter.Page.Should().Be(2);
            filter.Quantity.Should().Be(3);
            filter.Id.Should().Be(3);
            filter.ParentId.Should().Be(6);
            filter.IsDisabled.Should().Be(true);
            filter.Name.Should().Be("test");
            filter.Sort.Should().BeEquivalentTo(new[] { "one", "two" });
        }
Example #6
0
        public void AgencyFilter_Constructor_01()
        {
            // Arrange
            var page     = 2;
            var quantity = 5;

            // Act
            var filter = new AgencyFilter(page, quantity);

            // Assert
            filter.Page.Should().Be(page);
            filter.Quantity.Should().Be(quantity);
            filter.Id.Should().BeNull();
            filter.ParentId.Should().Be(0);
            filter.IsDisabled.Should().BeNull();
            filter.Name.Should().BeNull();
            filter.Sort.Should().BeNull();
        }
Example #7
0
        private IQueryable <Agency> SetFilter(IQueryable <Agency> q, AgencyFilter f)
        {
            if (f == null)
            {
                return(q);
            }
            if (!String.IsNullOrEmpty(f.searchString))
            {
                q = q.Where(s => (
                                s.Name.Contains(f.searchString) ||
                                s.Represent.Contains(f.searchString) ||
                                s.Email.Contains(f.searchString) ||
                                s.Phone.Contains(f.searchString)
                                ));
            }

            return(q);
        }
Example #8
0
        public void AgencyFilter_Constructor_02()
        {
            // Arrange
            var page       = 2;
            var quantity   = 5;
            var id         = 3;
            var parentId   = 3;
            var name       = "name";
            var isDisabled = true;
            var sort       = new[] { "one" };

            // Act
            var filter = new AgencyFilter(page, quantity, id, name, parentId, isDisabled, sort);

            // Assert
            filter.Page.Should().Be(page);
            filter.Quantity.Should().Be(quantity);
            filter.Id.Should().Be(id);
            filter.ParentId.Should().Be(parentId);
            filter.IsDisabled.Should().Be(isDisabled);
            filter.Name.Should().Be(name);
            filter.Sort.Should().BeEquivalentTo(sort);
        }
 async public Task <IEnumerable <VAgency> > GetAgencyList(AgencyFilter filter) =>
 await Db.GetListSpAsync <VAgency, AgencyFilter>(filter);
 async public Task <PagingResult <VAgency> > GetPagingAgencyList(Paging paging, AgencyFilter filter) =>
 await Db.GetPagingListSpAsync <VAgency, AgencyFilter>(paging, filter);
Example #11
0
        public async Task <IActionResult> Index(string userName, string dataYear)
        {
            if (userName == User.Identity.Name)
            {
                if (User.Identity.Name != null)
                {
                    List <YearEvent> yearEvents = await db.YearEvents.Where(y => y.DataYear == dataYear).ToListAsync();

                    if (yearEvents.Count == 0)
                    {
                        dataYear   = DateTime.Now.Year.ToString();
                        yearEvents = await db.YearEvents.Where(y => y.DataYear == dataYear).ToListAsync();

                        if (yearEvents.Count == 0)
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }

                    List <Agency> agencies = await db.Agencies.ToListAsync();

                    agencies = AgencyFilter.GetAgenciesFilterYearEvent(agencies, yearEvents);

                    var agenciessort = from a in agencies
                                       orderby a.Name
                                       select a;// сортировка по имени учреждения
                    agencies = agenciessort.ToList();

                    if (agencies != null)
                    {
                        List <YearEventViewModel> YearEventViewModels = new List <YearEventViewModel>();

                        Procenter procenter = new Procenter();
                        foreach (YearEvent yearEvent in yearEvents)
                        {
                            YearEventViewModels.Add(new YearEventViewModel()
                            {
                                Id             = yearEvent.Id,
                                AgencyId       = yearEvent.AgencyId,
                                Number         = yearEvent.Number,
                                EventText      = yearEvent.EventText,
                                FirstQuarter   = yearEvent.FirstQuarter,
                                SecondQuarter  = yearEvent.SecondQuarter,
                                ThirdQuarter   = yearEvent.ThirdQuarter,
                                FourthQuarter  = yearEvent.FourthQuarter,
                                Unit           = yearEvent.Unit,
                                Section        = yearEvent.Section,
                                SubSection     = yearEvent.SubSection,
                                SubSection1    = yearEvent.SubSection1,
                                TypeSection    = yearEvent.TypeSection,
                                DataYear       = yearEvent.DataYear,
                                PartYearEvents = await db.PartYearEvents.Where(p => p.YearEventId == yearEvent.Id).ToListAsync(),
                                Procent        = await procenter.GetProcentYearEvent(yearEvent.Id, db),
                                TrClass        = await Overdue.GetOverdueYearEventColor(yearEvent.Id, db)
                            });
                        }
                        Pricer pricer = new Pricer();
                        Doner  doner  = new Doner();
                        List <AgencyYearPlanViewModel> agencyYearPlanViewModels = new List <AgencyYearPlanViewModel>();
                        foreach (Agency ag in agencies)
                        {
                            agencyYearPlanViewModels.Add(new AgencyYearPlanViewModel()
                            {
                                Id   = ag.Id,
                                Name = ag.Name,
                                YearEventViewModels = YearEventViewModels.Where(y => y.AgencyId == ag.Id).ToList(),
                                FullDonePlan        = await db.YearEvents.Where(y => y.AgencyId == ag.Id).
                                                      Where(y => y.DataYear == dataYear).
                                                      CountAsync(),
                                NowDonePlan      = await doner.GetYearAgencyDoneNow(ag, db, dataYear),
                                Procent          = await procenter.GetProcentAgency(ag.Id, db, dataYear),
                                FullPriceBnow    = await pricer.GetFullPriceBNowAgency(ag.Id, db, dataYear),
                                FullPriceNotBnow = await pricer.GetFullPriceNotBNowAgency(ag.Id, db, dataYear)
                            });
                        }

                        TotalYearPlanViewModel totalYearPlanViewModel = new TotalYearPlanViewModel();
                        totalYearPlanViewModel.AgencyYearPlanViewModels = agencyYearPlanViewModels;
                        totalYearPlanViewModel.Procent = await procenter.GetProcentTotal(agencies, db, dataYear);

                        totalYearPlanViewModel.FullDonePlan = await doner.GetYearPlanCount(agencies, db, dataYear);

                        totalYearPlanViewModel.NowDonePlan = await doner.GetYearPlanDoneCount(agencies, db, dataYear);

                        totalYearPlanViewModel.FullPriceBnow = await pricer.GetFullPriceBNowTotal(agencies, db, dataYear);

                        totalYearPlanViewModel.FullPriceNotBnow = await pricer.GetFullPriceNotBNowTotal(agencies, db, dataYear);

                        totalYearPlanViewModel.FullPrice = totalYearPlanViewModel.FullPriceBnow + totalYearPlanViewModel.FullPriceNotBnow;
                        totalYearPlanViewModel.DataYear  = dataYear;
                        totalYearPlanViewModel.DataYears = await db.DataYears.ToListAsync();

                        return(View(totalYearPlanViewModel));
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }