public IActionResult New() { var vm = new PostViewModel(); vm.IsNew = true; vm.CategoryList = new SelectList(this.CategoryService.All(), "Key", "Name"); vm.Model = new SaveTopicModel(); ViewBag.Title = "新主题"; return this.View("Post", vm); }
public async Task<IActionResult> New(SaveTopicModel model) { var vm = new PostViewModel(); vm.CategoryList = new SelectList(this.CategoryService.All(), "Key", "Name"); vm.Model = model; if (!ModelState.IsValid) { return this.Notice(Core.Resource.Messages.ModelStateNotValid); } var result = await this.TopicService.Add(model); if (result.Success) { return this.RedirectToAction("Index", "Topic", new { id = result.Data }); } else { return this.Notice(result.ErrorMessage); } }
public async Task<IActionResult> Edit(int id) { var topic = await this.TopicService.Get(id); if (topic == null || !this.SecurityManager.CanOperateTopic(topic)) { return this.Forbid(); } ViewBag.Title = "编辑主题"; var vm = new PostViewModel(); vm.CategoryList = new SelectList(this.CategoryService.All(), "Key", "Name", topic.Category.Key); vm.Model = new SaveTopicModel { Category = topic.Category.Key, Content = topic.Content, Title = topic.Title }; return this.View("Post", vm); }