From e6c0552be8363a597d2427c2ef1fcb73672ed6e1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 7 May 2017 09:37:41 -0400 Subject: [PATCH] LeaveGroup action --- Project-Unite/Controllers/GroupsController.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Project-Unite/Controllers/GroupsController.cs b/Project-Unite/Controllers/GroupsController.cs index 5213349..264b0e6 100644 --- a/Project-Unite/Controllers/GroupsController.cs +++ b/Project-Unite/Controllers/GroupsController.cs @@ -30,6 +30,19 @@ public ActionResult JoinGroup(string id) return RedirectToAction("ViewGroup", "Groups", new { id = id }); } + [Authorize] + public ActionResult LeaveGroup() + { + var db = new ApplicationDbContext(); + var user = db.Users.FirstOrDefault(x => x.Id == User.Identity.GetUserId()); + var group = db.Groups.FirstOrDefault(x => x.Id == user.GroupId); + if (group == null) + return new HttpStatusCodeResult(404); + user.GroupId = ""; + db.SaveChanges(); + return RedirectToAction("ViewGroup", "Groups", new { id = group.Id }); + + } [Authorize] public ActionResult ViewGroup(string id)