public async Task <IActionResult> Create(PostCategoryEditModel model) { if (this.ModelState.IsValid) { var postCategory = new PostCategory { Name = model.Name }; this.context.PostCategories.Add(postCategory); await this.context.SaveChangesAsync(); return(this.RedirectToAction("Index")); } return(this.View(model)); }
// GET: PostCategories/Edit/5 public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(this.NotFound()); } var postCategory = await this.context.PostCategories.SingleOrDefaultAsync(m => m.Id == id); if (postCategory == null) { return(this.NotFound()); } var model = new PostCategoryEditModel { Name = postCategory.Name }; return(this.View(model)); }
public async Task <IActionResult> Edit(Guid?id, PostCategoryEditModel model) { if (id == null) { return(this.NotFound()); } var postCategory = await this.context.PostCategories.SingleOrDefaultAsync(m => m.Id == id); if (postCategory == null) { return(this.NotFound()); } if (this.ModelState.IsValid) { postCategory.Name = model.Name; await this.context.SaveChangesAsync(); return(this.RedirectToAction("Index")); } return(this.View(model)); }