public ActionResult EditPost(Grouppost requestPost) { var id = requestPost.GroupId; var idpost = requestPost.Id; try { if (ModelState.IsValid) { Grouppost post = db.Groupposts.Find(id, idpost); if (TryUpdateModel(post)) { post.Content = requestPost.Content; post.Date = DateTime.Now; db.SaveChanges(); } return(RedirectToAction("ShowPost", new { id, idpost })); } else { return(View(requestPost)); } } catch (Exception e) { return(View()); } }
public ActionResult EditPost(int id, int idpost) { Grouppost post = db.Groupposts.Find(id, idpost); ViewBag.Post = post; if (User.IsInRole("Admin")) { ViewBag.Group = db.Groups.Find(id); return(View(post)); } else { var user = db.Members.Find(id, User.Identity.GetUserId()); if (post.UserId == User.Identity.GetUserId() | User.IsInRole("Admin") | user.Role == "Admin1") { return(View(post)); } else { TempData["message"] = "You don't have the rights to edit this post!"; return(RedirectToAction("Index")); } } }
public ActionResult ShowPost(int id, int idpost) { Grouppost post = db.Groupposts.Find(id, idpost); var user = db.Members.Find(id, User.Identity.GetUserId()); if (!User.Identity.IsAuthenticated) { ViewBag.Owner = false; } else if (user == null) { ViewBag.Owner = false; } else if (post.UserId == User.Identity.GetUserId() | User.IsInRole("Admin") | user.Role == "Admin1") { ViewBag.Owner = true; } else { ViewBag.Owner = false; } if (User.IsInRole("Admin")) { ViewBag.Owner = true; } ViewBag.Post = post; return(View(post)); }
public ActionResult NewPost(Grouppost post) { Grouppost postare = new Grouppost(); postare.GroupId = post.GroupId; postare.Content = post.Content; postare.Date = post.Date; postare.UserId = User.Identity.GetUserId(); Random random = new Random(); postare.Id = random.Next(); while (postare.Id == null) { postare.Id = random.Next(); } if (postare.Id != null) { db.Groupposts.Add(postare); db.SaveChanges(); } TempData["message"] = "New post added!"; return(RedirectToAction("Show", new { id = postare.GroupId })); }
public ActionResult NewPost(int id) { var user = db.Members.Find(id, User.Identity.GetUserId()); if (user != null) { Grouppost post = new Grouppost(); post.UserId = User.Identity.GetUserId(); post.GroupId = id; return(View(post)); } else { return(View()); } }
public ActionResult DeletePost(int id, int idpost) { Grouppost post = db.Groupposts.Find(id, idpost); var user = db.Members.Find(id, User.Identity.GetUserId()); if (post.UserId == User.Identity.GetUserId() | User.IsInRole("Admin") | user.Role == "Admin1") { db.Groupposts.Remove(post); db.SaveChanges(); TempData["message"] = "The post was deleted!"; return(RedirectToAction("Index")); } else { TempData["message"] = "You don't have the rights to delete this post!"; return(RedirectToAction("Index")); } }