diff --git a/Project-Unite/Controllers/GroupsController.cs b/Project-Unite/Controllers/GroupsController.cs index e3f0907..5213349 100644 --- a/Project-Unite/Controllers/GroupsController.cs +++ b/Project-Unite/Controllers/GroupsController.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Web; using System.Web.Mvc; +using Microsoft.AspNet.Identity; using Project_Unite.Models; namespace Project_Unite.Controllers @@ -16,6 +17,20 @@ public ActionResult Index() return View(db.Groups); } + [Authorize] + public ActionResult JoinGroup(string id) + { + var db = new ApplicationDbContext(); + var user = db.Users.FirstOrDefault(x => x.Id == User.Identity.GetUserId()); + var group = db.Groups.FirstOrDefault(x => x.Id == id); + if (group == null) + return new HttpStatusCodeResult(404); + user.GroupId = id; + db.SaveChanges(); + return RedirectToAction("ViewGroup", "Groups", new { id = id }); + } + + [Authorize] public ActionResult ViewGroup(string id) {