예제 #1
0
 public ActionResult Create(GroupLoadVM load)
 {
     try
     {
         if (ModelState.IsValid)
         {
             unitOfWork.GroupLoads.Insert(load.GroupLoad);
             unitOfWork.Save();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException /* dex */)
     {
         //Log the error (uncomment dex variable name after DataException and add a line here to write a log.)
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
     }
     return(View("CreateGroupLoad", BuildModel(load.GroupLoad)));
 }
예제 #2
0
        private GroupLoadVM BuildModel(GroupLoad groupLoad = null)
        {
            if (groupLoad == null)
            {
                groupLoad = new GroupLoad();
            }
            var model = new GroupLoadVM
            {
                GroupLoad    = groupLoad,
                Teachers     = new SelectList(unitOfWork.Teachers.GetAllForSelectList(), "TeacherID", "FullName", groupLoad.TeacherID),
                Disciplines  = new SelectList(unitOfWork.Disciplines.GetAll(), "DisciplineID", "DisciplineName", groupLoad.DisciplineID),
                Groups       = new SelectList(unitOfWork.Groups.Get(g => g.StudyYear == groupLoad.StudyYear), "GroupNumber", "GroupNumber", groupLoad.GroupNumber),
                GroupStudies = new SelectList(unitOfWork.GroupStudies.GetAll(), "GroupClassID", "GroupClassName", groupLoad.GroupStudiesID),
                Semesters    = GetEnumSelectList(typeof(SemesterType), (int)groupLoad.Semester),
                StudyTypes   = GetEnumSelectList(typeof(StudyTypes), (int)groupLoad.StudyType),
                StudyYears   = new SelectList(Enumerable.Range(1, 4), groupLoad.StudyYear)
            };

            return(model);
        }