Beispiel #1
0
        public static void Initialize(CouncilDbContext context)
        {
            context.Database.EnsureCreated();

            // Проверка занесены ли университеты
            if (context.Universities.Any())
            {
                return;   // База данных инициализирована
            }

            context.AddRange(
                new University()
            {
                UniversityName = "ГГТУ",
                Address        = "Пр-т Октября, 48, 246746, г. Гомель, Республика Беларусь",
                Website        = "gstu.by"
            },
                new University()
            {
                UniversityName = "ГГУ",
                Address        = "ул. Советская, 104, 246019, г. Гомель, Республика Беларусь",
                Website        = "gsu.by"
            },
                new University()
            {
                UniversityName = "БелГУТ",
                Address        = "ул. Кирова, 34, 246653, г. Гомель, Республика Беларусь",
                Website        = "bsut.by"
            }

                );
            context.SaveChanges();
        }
        public async Task <IActionResult> Index(int currentYear, string action)
        {
            {
                List <int> years = _context.Indicators
                                   .OrderByDescending(f => f.Year)
                                   .Select(f => f.Year)
                                   .ToList();
                years.Insert(0, currentYear); years.Insert(0, currentYear + 1);
                var ListYears         = new SelectList(years.Distinct(), currentYear);
                var indicators        = _context.Indicators.Where(t => t.Year == currentYear).ToList();
                var achievementsCount = _context.Achievements.Where(m => m.Year == currentYear).Count();

                switch (action)
                {
                case "FillDataFromLastYear":
                    if (indicators.Count() == 0)
                    {
                        var indicatorsLastYear = _context.Indicators
                                                 .Where(y => y.Year == (currentYear - 1));
                        foreach (var ind in indicatorsLastYear)
                        {
                            ind.Year        = currentYear;
                            ind.IndicatorId = 0;
                            indicators.Add(ind);
                        }
                        _context.AddRange(indicators);
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        return(View("Message", "Для текущего года уже загружены данные!"));
                    }
                    break;

                case "FillDataForUniversities":
                    //Загрузка набора показателей дл¤ университетов на заданный год
                    string resultPublishIndicatorsForUniversities = await PublishIndicatorsForUniversities(currentYear);

                    if (resultPublishIndicatorsForUniversities == "")
                    {
                        return(Redirect("~/Admin/Achievements/Index"));
                    }
                    else
                    {
                        return(View("Message", resultPublishIndicatorsForUniversities));
                    }

                default:
                    break;
                }
                IndicatorsViewModel indicatorsViewModel = new IndicatorsViewModel()
                {
                    ListYears         = new SelectList(years.Distinct(), currentYear),
                    AchievementsCount = achievementsCount
                };
                return(View(indicatorsViewModel));
            }
        }