示例#1
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"));
        }