コード例 #1
0
ファイル: TopicController.cs プロジェクト: supermuk/iudico
        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 });
            }
        }
コード例 #2
0
ファイル: TopicController.cs プロジェクト: supermuk/iudico
        public ActionResult Edit(int topicId)
        {
            var topic = Storage.GetTopic(topicId);
            var model = new CreateTopicModel(Storage.GetCourses(), topic);

            return PartialView("Edit", model);
        }
コード例 #3
0
ファイル: Converter.cs プロジェクト: supermuk/iudico
        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;
        }
コード例 #4
0
ファイル: TopicController.cs プロジェクト: supermuk/iudico
        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 });
            }
        }
コード例 #5
0
ファイル: TopicController.cs プロジェクト: supermuk/iudico
        public ActionResult Create(int chapterId)
        {
            var model = new CreateTopicModel(Storage.GetCourses(), new Topic());

            return PartialView("Create", model);
        }