public ActionResult EssaysUpdate([DataSourceRequest]DataSourceRequest request, EssayViewModel essay) { if (this.ModelState.IsValid) { var entity = this.Mapper.Map<Essay>(essay); this.essays.Update(entity); } return this.Json(new[] { essay }.ToDataSourceResult(request, this.ModelState)); }
public ActionResult Edit(EssayViewModel model) { if (this.ModelState.IsValid) { var studentId = this.User.Identity.GetUserId(); var updateModel = this.Mapper.Map<Essay>(model); updateModel.AuthorId = studentId; this.essays.Update(updateModel); return this.RedirectToAction(nameof(this.Review)); } return this.View(model); }
public void TestRouteStudentEssayEditPost() { const string Url = "/Student/Essay/Edit"; var model = new EssayViewModel() { Content = "Something", Title = "Test" }; var jsonBody = JsonConvert.SerializeObject(model); this.RouteCollection .ShouldMap(Url) .WithJsonBody(jsonBody) .To<EssayController>(c => c.Edit()); }
public ActionResult EssaysDestroy([DataSourceRequest]DataSourceRequest request, EssayViewModel essay) { this.essays.Delete(essay.AuthorId); return this.Json(new[] { essay }.ToDataSourceResult(request, this.ModelState)); }