mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 03:11:48 -05:00
LeaveGroup action
This commit is contained in:
parent
8e6196fd1d
commit
e6c0552be8
1 changed files with 13 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue