public ActionResult Edit(string id) { var identity = new Identity(id); var entity = entityById.Get<Topic>(identity); if(entity == null) return new HttpStatusCodeResult(404); var model = new EditTopicModel(entity, groupsSortedByName.Execute()); return View(model); }
public ActionResult Edit(EditTopicModel model) { if (!ModelState.IsValid) return View(model); var entity = entityById.Get<Topic>((Identity) model.TopicId); ModelToEntity(model, entity); updateTopicCommand.Execute(entity); return RedirectToAction("Index"); }
private static void ModelToEntity(EditTopicModel model, Topic entity) { entity.Name = model.Name; entity.Description = model.Description; if (!string.IsNullOrEmpty(model.Group)) { entity.GroupId = (Identity)model.Group; } }
public ActionResult Create(EditTopicModel model) { if (!ModelState.IsValid) return View(model); var topic = new Topic(); ModelToEntity(model, topic); createTopicCommand.Execute(topic); return RedirectToAction("Index"); }
public ActionResult Edit(EditTopicModel model) { if (!ModelState.IsValid) { return(View(model)); } var entity = entityById.Get <Topic>((Identity)model.TopicId); ModelToEntity(model, entity); updateTopicCommand.Execute(entity); return(RedirectToAction("Index")); }
public ActionResult Create(EditTopicModel model) { if (!ModelState.IsValid) { return(View(model)); } var topic = new Topic(); ModelToEntity(model, topic); createTopicCommand.Execute(topic); return(RedirectToAction("Index")); }
public ActionResult Edit(string id) { var identity = new Identity(id); var entity = entityById.Get <Topic>(identity); if (entity == null) { return(new HttpStatusCodeResult(404)); } var model = new EditTopicModel(entity, groupsSortedByName.Execute()); return(View(model)); }
public async Task <IActionResult> Edit([FromRoute] int id, [FromBody] EditTopicModel model) { if (model == null || !ModelState.IsValid) { return(InvalidRequest()); } model.ID = id; var result = await TopicService.Edit(model); if (result.Success) { return(Success(result.Data)); } else { return(Error(result.ErrorMessage)); } }
public async Task <ActionResult> Edit(EditTopicModel model) { if (ModelState.IsValid) { var topic = await db.Topics.FindAsync(model.TopicId); if (topic == null) { return(HttpNotFound()); } topic.IsActive = model.IsActive; topic.Name = model.Name; db.Entry(topic).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }
// GET: Topics/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Topic topic = await db.Topics.FindAsync(id); if (topic == null) { return(HttpNotFound()); } var model = new EditTopicModel { IsActive = topic.IsActive, Name = topic.Name, TopicId = topic.TopicId }; return(View(model)); }
private static void ModelToEntity(EditTopicModel model, Topic entity) { entity.Name = model.Name; entity.Description = model.Description; if (!string.IsNullOrEmpty(model.Group)) { entity.GroupId = (Identity) model.Group; } }
public ActionResult Create() { var model = new EditTopicModel(this.groupsSortedByName.Execute()); return View(model); }
public ActionResult Create() { var model = new EditTopicModel(this.groupsSortedByName.Execute()); return(View(model)); }
public async Task <OperationResult <TopicModel> > Edit(EditTopicModel model) { var entity = await BlogContext.Topics.SingleOrDefaultAsync(t => t.ID == model.ID); if (entity == null) { return(OperationResult <TopicModel> .Failure(L["The article does not exists"].Value)); } using (var tran = await BlogContext.Database.BeginTransactionAsync()) { List <CategoryTopic> deletedCategoryTopicList = await BlogContext.CategoryTopics.Where(t => t.TopicID == model.ID).ToListAsync(); BlogContext.RemoveRange(deletedCategoryTopicList); List <TagTopic> deletedTagTopicList = await BlogContext.TagTopics.Where(t => t.TopicID == model.ID).ToListAsync(); BlogContext.RemoveRange(deletedTagTopicList); await BlogContext.SaveChangesAsync(); model.CategoryList = (model.CategoryList ?? new int[0]).Distinct().ToArray(); model.TagList = (model.TagList ?? new string[0]).Distinct().ToArray(); List <Category> categoryEntityList = await BlogContext.Categories.Where(t => model.CategoryList.Contains(t.ID)).ToListAsync(); List <Tag> tagEntityList = await BlogContext.Tags.Where(t => model.TagList.Contains(t.Keyword)).ToListAsync(); model.Alias = await this.GenerateAlias(model.ID, model.Alias, model.Title); model.Summary = this.GenerateSummary(model.Summary, model.Content); foreach (var tag in model.TagList) { if (!tagEntityList.Any(t => t.Keyword == tag)) { var tagEntity = new Tag { Keyword = tag }; BlogContext.Tags.Add(tagEntity); tagEntityList.Add(tagEntity); } } entity.Title = model.Title; entity.Content = model.Content; entity.Status = model.Status; entity.Alias = model.Alias; entity.Summary = model.Summary; entity.EditDate = model.Date ?? DateTime.Now; entity.AllowComment = model.AllowComment; List <CategoryTopic> categoryTopicList = categoryEntityList.Select(t => new CategoryTopic { Category = t, Topic = entity }).ToList(); BlogContext.CategoryTopics.AddRange(categoryTopicList); List <TagTopic> tagTopicList = tagEntityList.Select(t => new TagTopic { Tag = t, Topic = entity }).ToList(); BlogContext.TagTopics.AddRange(tagTopicList); await BlogContext.SaveChangesAsync(); tran.Commit(); } BlogContext.RemoveCategoryCache(); BlogContext.RemoveTagCache(); var topicModel = (await this.Transform(entity)).First(); return(new OperationResult <TopicModel>(topicModel)); }