Exemple #1
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 });
            }
        }
Exemple #2
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 });
            }
        }