LeaveGroup action

This commit is contained in:
Michael 2017-05-07 09:37:41 -04:00
parent 8e6196fd1d
commit e6c0552be8

View file

@ -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)