public IActionResult Index(int?currentYear, string UniversityName, string LastName, string Email, string RegistrationNumber, string DocumentName, int page = 1, string cmd = "")
        {
            int pageSize = 20;   // количество элементов на странице
            int currYear = currentYear ?? DateTime.Now.Year;
            IEnumerable <Achievement> achievements = _context.Achievements
                                                     .Include(a => a.Indicator)
                                                     .Include(a => a.Univercity)
                                                     .Where(t => t.Year == currYear)
                                                     .OrderBy(s => s.Indicator.IndicatorId1).OrderBy(s => s.Indicator.IndicatorId2);



            if (UniversityName != null)
            {
                achievements = achievements.Where(x => x.Univercity.UniversityName.ToString().Contains(UniversityName.ToString()));
            }


            //Вычисление занятых мест
            if (cmd == "CalculatePositions")
            {
                achievements = Positions.Get(achievements.ToList());
                _context.UpdateRange(achievements);
                _context.SaveChanges();
            }



            /*
             * // сортировка
             * switch (sortOrder)
             * {
             *  case SortState.IndicatorCodeDesc:
             *      achievements = achievements.OrderByDescending(s => s.Indicator.IndicatorCode);
             *      break;
             *  case SortState.UniversityNameAsc:
             *      achievements = achievements.OrderBy(s => s.Univercity.UniversityName);
             *      break;
             *  case SortState.UniversityNameDesc:
             *      achievements = achievements.OrderByDescending(s => s.Univercity.UniversityName);
             *      break;
             *  default:
             *      achievements = achievements.OrderBy(s => s.Indicator.IndicatorCode);
             *      break;
             * }
             *
             */



            int        count = achievements.Count();
            List <int> years = _context.Indicators
                               .OrderByDescending(f => f.Year)
                               .Select(f => f.Year)
                               .ToList();

            years.Insert(0, currYear); years.Insert(0, currYear + 1);

            PageViewModel pageViewModel = new PageViewModel(count, page, pageSize);

            IndexViewModel achievementsViewModel = new IndexViewModel
            {
                PageViewModel   = pageViewModel,
                Achievements    = achievements.Skip((page - 1) * pageSize).Take(pageSize).ToList(),
                FilterViewModel = new FilterViewModel(UniversityName, LastName, Email, RegistrationNumber, DocumentName),
                ListYears       = new SelectList(years.Distinct(), currYear)
            };

            return(View(achievementsViewModel));
        }
Esempio n. 2
0
        public IActionResult Index(int?currentYear, string UniversityName, string LastName, string Email, string RegistrationNumber, string DocumentName, int page = 1, SortState sortOrder = SortState.IndicatorCodeAsc, string cmd = "")
        {
            int pageSize = 20;   // количество элементов на странице
            int currYear = currentYear ?? DateTime.Now.Year;
            IEnumerable <Achievement> achievements = _context.Achievements
                                                     .Include(a => a.Indicator)
                                                     .Include(a => a.Univercity)
                                                     .Where(t => t.Year == currYear)
                                                     .OrderBy(s => s.Indicator.IndicatorCode);



            if (UniversityName != null)
            {
                achievements = achievements.Where(x => x.Univercity.UniversityName.ToString().Contains(UniversityName.ToString()));
            }


            //Вычисление занятых мест
            if (cmd == "CalculatePositions")
            {
                achievements = Positions.Get(achievements.ToList());
                _context.UpdateRange(achievements);
                _context.SaveChanges();
            }


            float[,] mest = new float[10, 2];


            float[] sum = new float[100];

            /*Фильтруем записи по критерию  год тип показателя */
            achievements = achievements.Where(x => x.Year == currentYear && x.Indicator.IndicatorId2 != null && x.Indicator.IndicatorId3 == null);

            /*Групируем по id университета */
            var resul = from c in achievements
                        group c by c.UnivercityId;

            int i = 0;
            int n = 0;

            /*находим сумму баллов каждого униывера в отдельности*/
            foreach (IGrouping <int, Achievement> group in resul)
            {
                foreach (Achievement c in group)
                {
                    sum[i] = sum[i] + c.Position;
                }

                /* mest[i, 0]-сумма баллов mest[i, 1] - id университета*/
                mest[i, 0] = sum[i];
                mest[i, 1] = i;

                i++;
                n = i;
            }


            float temp  = 0;
            float tempm = 0;
            float k     = 0;

            /*Сортируем по местам по убыванию*/
            while (k != n + 1)
            {
                for (i = 0; i < n - 1; i++)
                {
                    if (mest[i, 0] > mest[i + 1, 0])
                    {
                        temp           = mest[i, 0];
                        tempm          = mest[i, 1];
                        mest[i, 0]     = mest[i + 1, 0];
                        mest[i, 1]     = mest[i + 1, 1];
                        mest[i + 1, 0] = temp;
                        mest[i + 1, 1] = tempm;
                    }
                }
                k++;
            }

            /*Добавляем полученные записиы*/
            if (_context.Raschets.Any())
            {
            }

            else
            {
                for (i = 0; i < n; i++)
                {
                    _context.Raschets.Add(new Raschet {
                        Position = i + 1, UnivercityId = Convert.ToInt32(mest[i, 1]) + 1, SumaValue = mest[i, 0], Year = currYear
                    });
                    _context.SaveChanges();
                }
            }


            IEnumerable <Raschet> ras = _context.Raschets.Include(a => a.Univercity).Where(x => x.Year == currYear);
            int        count          = achievements.Count();
            List <int> years          = _context.Indicators
                                        .OrderByDescending(f => f.Year)
                                        .Select(f => f.Year)
                                        .ToList();

            years.Insert(0, currYear); years.Insert(0, currYear + 1);

            PageViewModel pageViewModel = new PageViewModel(count, page, pageSize);

            IndexViewModel achievementsViewModel = new IndexViewModel
            {
                PageViewModel   = pageViewModel,
                SortViewModel   = new SortViewModel(sortOrder),
                Raschets        = ras.Skip((page - 1) * pageSize).Take(pageSize).ToList(),
                FilterViewModel = new FilterViewModel(UniversityName, LastName, Email, RegistrationNumber, DocumentName),
                ListYears       = new SelectList(years.Distinct(), currYear)
            };

            return(View(achievementsViewModel));
        }