Exemplo n.º 1
0
        public JsonResult Edit(int topicId, CreateTopicModel model)
        {
            try
            {
                var topic = new Topic { Id = topicId };
                topic.UpdateFromModel(model);

                AddValidationErrorsToModelState(Validator.ValidateTopic(topic).Errors);
                if (ModelState.IsValid)
                {
                    topic = Storage.UpdateTopic(topic);

                    var viewTopic = topic.ToViewTopicModel(Storage);
                    var discipline = Storage.GetTopic(topicId).Chapter.Discipline; // TODO: FatTony;wtf?
                    return Json(new { success = true, topicId = topicId, topicRow = PartialViewAsString("TopicRow", viewTopic), disciplineId = discipline.Id, error = discipline.IsValid ? string.Empty : Validator.GetValidationError(discipline) });
                }

                var m = new CreateTopicModel(Storage.GetCourses(), topic);
                return Json(new { success = false, topicId = topicId, html = PartialViewAsString("Edit", m) });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, html = ex.Message });
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit(int topicId)
        {
            var topic = Storage.GetTopic(topicId);
            var model = new CreateTopicModel(Storage.GetCourses(), topic);

            return PartialView("Edit", model);
        }
Exemplo n.º 3
0
        public static void UpdateFromModel(this Topic topic, CreateTopicModel model)
        {
            var testTopicType = model.TestCourseId == Constants.TestWithoutCourseId
                                    ? TopicTypeEnum.TestWithoutCourse
                                    : model.TestCourseId == Constants.NoCourseId
                                          ? (TopicTypeEnum?)null
                                          : TopicTypeEnum.Test;
            var theoryTopicType = model.TheoryCourseId == Constants.NoCourseId
                                      ? (TopicTypeEnum?)null
                                      : TopicTypeEnum.Theory;

            topic.ChapterRef = model.ChapterId;
            topic.Name = model.TopicName;
            topic.TestCourseRef = model.TestCourseId != Constants.NoCourseId
                                      ? model.TestCourseId
                                      : (int?)null;
            topic.TestTopicTypeRef = (int?)testTopicType;
            topic.TheoryCourseRef = model.TheoryCourseId != Constants.NoCourseId
                                        ? model.TheoryCourseId
                                        : (int?)null;
            topic.TheoryTopicTypeRef = (int?)theoryTopicType;
        }
Exemplo n.º 4
0
        public JsonResult Create(CreateTopicModel model)
        {
            try
            {
                var topic = new Topic();
                topic.UpdateFromModel(model);

                AddValidationErrorsToModelState(Validator.ValidateTopic(topic).Errors);
                if (ModelState.IsValid)
                {
                    Storage.AddTopic(topic);
                    var viewTopic = topic.ToViewTopicModel(Storage);
                    return Json(new { success = true, chapterId = model.ChapterId, topicRow = PartialViewAsString("TopicRow", viewTopic) });
                }

                var m = new CreateTopicModel(Storage.GetCourses(), topic);
                return Json(new { success = false, chapterId = model.ChapterId, html = PartialViewAsString("Create", m) });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, html = ex.Message });
            }
        }
Exemplo n.º 5
0
        public ActionResult Create(int chapterId)
        {
            var model = new CreateTopicModel(Storage.GetCourses(), new Topic());

            return PartialView("Create", model);
        }