예제 #1
0
        public ActionResult Create(CreateAndListGroupModel model)
        {
            var db = new StudentAbsenceEntities();

            if (!db.IsGroupUnique(model.NewGroup.Name))
            {
                ModelState.AddModelError(string.Empty, "Группа с таким номером уже существует!");
            }

            if (ModelState.IsValid)
            {
                db.Group.Add(model.NewGroup);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var list = db.Group.Select(c => c).OrderBy(c => c.Name).ToList();

            ViewBag.Faculties = new SelectList(db.Faculty, "Id", "Name");
            return(View("Index", new CreateAndListGroupModel()
            {
                Groups = list, NewGroup = model.NewGroup
            }));
        }