示例#1
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"));
        }
示例#2
0
        public async Task <IActionResult> Index(string userName, string dataYear)
        {
            if (userName == User.Identity.Name)
            {
                Agency ag = new Agency();
                if (User.Identity.Name != null)
                {
                    User userAgency = await _userManager.FindByNameAsync(User.Identity.Name);

                    if (userAgency != null)
                    {
                        var userAgencyRoles = await _userManager.GetRolesAsync(userAgency);

                        if (userAgencyRoles.Count > 0)
                        {
                            foreach (Agency agg in db.Agencies)
                            {
                                if (userAgencyRoles.FirstOrDefault(rol => rol == agg.Name) != null)
                                {
                                    ag = agg;
                                }
                            }
                            if (ag.Name != null)
                            {
                                List <YearEvent> yearEvents = await db.YearEvents.Where(ye => ye.AgencyId == ag.Id)
                                                              .Where(ye => ye.DataYear == dataYear)
                                                              .ToListAsync();

                                List <YearEventViewModel> yearEventsViewModel = new List <YearEventViewModel>();
                                Procenter procenter = new Procenter();
                                Pricer    pricer    = new Pricer();
                                AgencyYearPlanViewModel agencyYearPlanViewModel = new AgencyYearPlanViewModel();

                                foreach (YearEvent yearEvent in yearEvents)
                                {
                                    yearEventsViewModel.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),
                                        FullPriceBnow            = await pricer.GetFullPriceBNow(yearEvent.Id, db),
                                        FullPriceNotBnow         = await pricer.GetFullPriceNotBNow(yearEvent.Id, db),
                                        NumberPartReturnsandSent = await GetNumberPartReturnsAndSent(yearEvent.Id),
                                        TrClass                  = await Overdue.GetOverdueYearEventColor(yearEvent.Id, db)
                                    });
                                }
                                agencyYearPlanViewModel.YearEventViewModels = yearEventsViewModel;
                                agencyYearPlanViewModel.DataYears           = await DataYearFilter.GetDataYear(ag.Id, db);

                                agencyYearPlanViewModel.DataYear = dataYear;
                                agencyYearPlanViewModel.Name     = ag.Name;
                                return(View(agencyYearPlanViewModel));
                            }
                        }
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }