public ActionResult Edit(EditPostBm post) { if (this.ModelState.IsValid) { this.service.Edit(post); return(this.RedirectToAction("All")); } var model = this.service.GetEditViewModel(post.Id); return(this.View(model)); }
public void EditPost_ShouldEditAndRedirectToAll() { var postBm = new EditPostBm() { Id = 1, Title = "нещо ново" }; this._controller.WithCallTo(adminPostsController => adminPostsController.Edit(postBm)) .ShouldRedirectTo <AdminPostsController>(c2 => c2.All()); var post = this._repository.Set.FirstOrDefault(p => p.Id == postBm.Id); Assert.AreEqual(post.Id, 1); Assert.AreEqual(post.Title, "нещо ново"); }
public void Edit(EditPostBm model) { var entity = this.posts.GetById(model.Id); entity.Title = model.Title; entity.Content = model.Content; if (model.PhotoUrl != null) { entity.Image = new Image() { Url = model.PhotoUrl }; } this.posts.Update(entity); this.posts.SaveChanges(); }