public ActionResult Create([Bind(Include = "GroupId,Title,Content")] Post post) { if (ModelState.IsValid) { User user = db.Users.Find(Convert.ToInt32(Session["UserID"])); post.User = user; post.PostDate = DateTime.Now; if (post.GroupId == 0) { post.GroupId = null; db.Posts.Add(post); db.SaveChanges(); return(RedirectToAction("Home", "Users")); } Group group = db.Groups.Find(post.GroupId); group.Posts.Add(post); db.Entry(group).State = group.GroupID == 0 ? EntityState.Added : EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ViewGroup", "Groups", new { groupId = group.GroupID })); } return(View(post)); }
public ActionResult AddMember(int groupId, int userId) { Group group = db.Groups.Find(groupId); User user = db.Users.Find(userId); group.Members.Add(user); db.Entry(group).State = group.GroupID == 0 ? EntityState.Added : EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ViewGroup", new { groupId = groupId })); }
public ActionResult Edit([Bind(Include = "CommentID,PostID,UserID,Title,Content,Likes")] Comment comment) { if (!IsAuthorizedToEdit(comment.CommentID)) { return(RedirectToAction("AccessDenied", "Welcome", new { ErrorMessage = "You are not authorized to edit this post" })); } if (ModelState.IsValid) { db.Entry(comment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(comment)); }
public ActionResult Edit([Bind(Include = "UserId,FirstName,LastName,Gender,Email,BirthDate,Password,Address")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); if (Session["Admin"] == null) { return(RedirectToAction("Logout", "Welcome")); } else { return(RedirectToAction("ManageUsers", "Admin")); } } return(View(user)); }