Example #1
0
        public IActionResult Post([FromBody] University university)
        {
            if (university == null)
            {
                return(BadRequest());
            }

            _context.Universities.Add(university);
            _context.SaveChanges();
            return(Ok(university));
        }
Example #2
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();
        }
Example #3
0
        // GET: Achievements
        public IActionResult Index(int?currentYear, int page = 1, SortState sortOrder = SortState.IndicatorCodeAsc, string cmd = "")
        {
            int pageSize = 10;   // количество элементов на странице
            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 (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);

            AchievementsViewModel achievementsViewModel = new AchievementsViewModel
            {
                PageViewModel = pageViewModel,
                SortViewModel = new SortViewModel(sortOrder),
                Achievements  = achievements.Skip((page - 1) * pageSize).Take(pageSize).ToList(),
                ListYears     = new SelectList(years.Distinct(), currYear)
            };

            return(View(achievementsViewModel));
        }
        public string Create([Bind("IndicatorId1,IndicatorId2,IndicatorId3,IndicatorName,IndicatorUnit,IndicatorType,IndicatorDescription,Year")] Indicator indicator)
        {
            string msg = "Модель не прошла валидацию";

            if (ModelState.IsValid)
            {
                _context.Add(indicator);
                _context.SaveChanges();
                msg = "Сохранено";
                return(msg);
            }
            return(msg);
        }