예제 #1
0
        public ActionResult Create(NewAssignmentViewModel model)
        {
            var repository = new AssignedCourseRepository(context);

            try
            {
                if (ModelState.IsValid)
                {
                    var assignedCourse = MapperHelper.Map <AssignedCourse>(model);
                    assignedCourse.isCompleted = false;
                    repository.Insert(assignedCourse);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                model.CoursesList    = PopulateCourses(model.CourseId);
                model.IndividualList = PopulateInviduals(model.IndividualId);
                return(View(model));
            }
            catch (Exception ex)
            {
                model.CoursesList    = PopulateCourses(model.CourseId);
                model.IndividualList = PopulateInviduals(model.IndividualId);
                return(View(model));
            }
        }
        public ActionResult NewAssignment(NewAssignmentCoursesViewModel model)
        {
            var repository = new AssignedCourseRepository(context);

            try {
                if (ModelState.IsValid)
                {
                    var entity = MapperHelper.Map <AssignedCourse>(model);
                    entity.IsCompleted = false;
                    repository.Insert(entity);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                model.CoursesList    = PopulateCourses(model.CourseId);
                model.IndividualList = PopulateIndividuals(model.IndividualId);
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
                return(View(model));
            }
            return(View(model));
        }