Пример #1
0
        public JsonResult Create( CreateCurriculumModel model ) {
            try {
                var curriculum = new Curriculum();
                curriculum.UpdateFromModel(model);

                AddValidationErrorsToModelState(Validator.ValidateCurriculum(curriculum).Errors);

                if (ModelState.IsValid) {
                    var id = Storage.AddCurriculum(curriculum);
                    var createdCurriculum = Storage.GetCurriculum(id);
                    return Json(new {
                        success = true,
                        curriculumRow = PartialViewAsString("CurriculumRow", new ViewCurriculumModel {
                            Id = createdCurriculum.Id,
                            GroupName = Storage.GetGroup(createdCurriculum.UserGroupRef) != null ? Storage.GetGroup(createdCurriculum.UserGroupRef).Name : string.Empty,
                            DisciplineName = Storage.GetDiscipline(createdCurriculum.DisciplineRef).Name,
                            StartDate = Converter.ToString(createdCurriculum.StartDate),
                            EndDate = Converter.ToString(createdCurriculum.EndDate),
                            IsValid = createdCurriculum.IsValid
                            })
                        });
                }
                model = curriculum.ToCreateCurriculumModel(Storage, true);
                return Json(new {
                    success = false,
                    html = PartialViewAsString("Create", model)
                    });
            } catch (Exception ex) {
                return Json(new {success = false, html = ex.Message});
            }
        }
Пример #2
0
        public ActionResult Create(int disciplineId, CreateCurriculumModel createAssignmentModel)
        {
            try
            {
                Curriculum curriculum = new Curriculum();
                curriculum.UserGroupRef = createAssignmentModel.GroupId;
                curriculum.DisciplineRef = disciplineId;

                AddValidationErrorsToModelState(Validator.ValidateCurriculum(curriculum).Errors);

                if (ModelState.IsValid)
                {
                    Storage.AddCurriculum(curriculum);

                    return RedirectToAction("Index");
                }
                else
                {
                    SaveValidationErrors();

                    return RedirectToAction("Create");
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #3
0
 public static void UpdateFromModel(this Curriculum curriculum, CreateCurriculumModel model)
 {
     curriculum.UserGroupRef = model.GroupId;
     if (model.DisciplineId > 0)
         curriculum.DisciplineRef = model.DisciplineId;
     curriculum.StartDate = model.SetTimeline ? model.StartDate : (DateTime?)null;
     curriculum.EndDate = model.SetTimeline ? model.EndDate : (DateTime?)null;
 }
Пример #4
0
        public ActionResult Create(int disciplineId)
        {
            LoadValidationErrors();

            var groups = Storage.GetNotAssignedGroups(disciplineId);
            var discipline = Storage.GetDiscipline(disciplineId);
            var model = new CreateCurriculumModel(groups, 0, null, null);

            ViewData["DisciplineName"] = discipline.Name;
            return View(model);
        }
Пример #5
0
        public ActionResult Create(CreateCurriculumModel model)
        {
            var curriculum = new Curriculum();
            curriculum.UpdateFromModel(model);

            AddValidationErrorsToModelState(Validator.ValidateCurriculum(curriculum).Errors);

            if (ModelState.IsValid)
            {
                Storage.AddCurriculum(curriculum);
                return RedirectToAction("Index");
            }
            model = curriculum.ToCreateCurriculumModel(Storage, true);
            return View(model);
        }
Пример #6
0
        public ActionResult Edit(int curriculumId, CreateCurriculumModel model)
        {
            var curriculum = Storage.GetCurriculum(curriculumId);
            curriculum.UpdateFromModel(model);
            curriculum.DisciplineRef = curriculum.DisciplineRef;

            AddValidationErrorsToModelState(Validator.ValidateCurriculum(curriculum).Errors);

            if (ModelState.IsValid)
            {
                Storage.UpdateCurriculum(curriculum);
                return RedirectToRoute("Curriculums", new { action = "Index" });
            }
            model = curriculum.ToCreateCurriculumModel(Storage, false);
            return View(model);
        }
Пример #7
0
        public ActionResult Create(int disciplineId)
        {
            try
            {
                LoadValidationErrors();

                IEnumerable<Group> groups = Storage.GetNotAssignedGroups(disciplineId);
                Discipline discipline = Storage.GetDiscipline(disciplineId);
                CreateCurriculumModel createAssignmentModel = new CreateCurriculumModel(groups, 0);

                ViewData["DisciplineName"] = discipline.Name;
                return View(createAssignmentModel);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #8
0
        public ActionResult Create(int disciplineId, CreateCurriculumModel model)
        {
            var curriculum = new Curriculum()
            {
                UserGroupRef = model.GroupId,
                DisciplineRef = disciplineId,
                StartDate = model.SetDate ? model.StartDate : (DateTime?)null,
                EndDate = model.SetDate ? model.EndDate : (DateTime?)null
            };

            AddValidationErrorsToModelState(Validator.ValidateCurriculum(curriculum).Errors);

            if (ModelState.IsValid)
            {
                Storage.AddCurriculum(curriculum);
                return RedirectToAction("Index");
            }
            else
            {
                SaveValidationErrors();
                return RedirectToAction("Create");
            }
        }
Пример #9
0
        public ActionResult Edit(int curriculumId, CreateCurriculumModel editAssignmentModel)
        {
            try
            {
                Curriculum curriculum = new Curriculum();
                curriculum.UserGroupRef = editAssignmentModel.GroupId;
                curriculum.Id = curriculumId;

                AddValidationErrorsToModelState(Validator.ValidateCurriculum(curriculum).Errors);

                if (ModelState.IsValid)
                {
                    Storage.UpdateCurriculum(curriculum);

                    return RedirectToRoute("Curriculums", new { action = "Index", DisciplineId = Session["DisciplineId"] });
                }
                else
                {
                    SaveValidationErrors();

                    return RedirectToAction("Create");
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #10
0
        public ActionResult Edit(int curriculumId)
        {
            try
            {
                LoadValidationErrors();

                Curriculum curriculum = Storage.GetCurriculum(curriculumId);
                int disciplineId = curriculum.DisciplineRef;
                Discipline discipline = Storage.GetDiscipline(disciplineId);
                int assignmentGroupId = curriculum.UserGroupRef;
                IEnumerable<Group> groups = Storage.GetNotAssignedGroupsWithCurrentGroup(disciplineId, assignmentGroupId);
                CreateCurriculumModel editAssignmentModel = new CreateCurriculumModel(groups, assignmentGroupId);

                Session["DisciplineId"] = disciplineId;
                ViewData["DisciplineName"] = discipline.Name;
                return View(editAssignmentModel);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #11
0
        public ActionResult Edit(int curriculumId)
        {
            LoadValidationErrors();

            var curriculum = Storage.GetCurriculum(curriculumId);
            var disciplineId = curriculum.DisciplineRef;
            var discipline = Storage.GetDiscipline(disciplineId);
            var groupId = curriculum.UserGroupRef;
            var groups = Storage.GetNotAssignedGroupsWithCurrentGroup(disciplineId, groupId);
            var model = new CreateCurriculumModel(groups, groupId, curriculum.StartDate, curriculum.EndDate);

            Session["DisciplineId"] = disciplineId;
            ViewData["DisciplineName"] = discipline.Name;
            return View(model);
        }
Пример #12
0
        public ActionResult Edit(int curriculumId, CreateCurriculumModel model)
        {
            var curriculum = Storage.GetCurriculum(curriculumId);
            curriculum.UserGroupRef = model.GroupId;
            curriculum.StartDate = model.SetDate ? model.StartDate : (DateTime?)null;
            curriculum.EndDate = model.SetDate ? model.EndDate : (DateTime?)null;

            AddValidationErrorsToModelState(Validator.ValidateCurriculum(curriculum).Errors);

            if (ModelState.IsValid)
            {
                Storage.UpdateCurriculum(curriculum);
                return RedirectToRoute("Curriculums", new { action = "Index", DisciplineId = Session["DisciplineId"] });
            }
            else
            {
                SaveValidationErrors();
                return RedirectToAction("Create");
            }
        }