public ActionResult Add(Post post) { if (ModelState.IsValid) { post.Created = DateTime.Now; post.LastModified = DateTime.Now; //post.Status = 1; post.Author = 1; MudHookNotifications.Set(new Notification("success", "Your new post has been added")); repo.AddPost(post); return RedirectToAction("Index"); } else { var allErrors = ModelState.Values.SelectMany(v => v.Errors); string message = ""; foreach (var e in allErrors) { message += e.ErrorMessage + ","; } MudHookNotifications.Set(new Notification("error", message.TrimEnd())); } return View(post); }
public ActionResult Edit(Post post) { if (ModelState.IsValid) { repo.EditPost(post); MudHookNotifications.Set(new Notification("success", "Your post has been updated.")); return RedirectToAction("Index"); } return View(post); }
public void AddPost(Post post) { db.Posts.Add(post); }
public void EditPost(Post post) { db.Entry(post).State = EntityState.Modified; Save(); }