JoinGroup action

This commit is contained in:
Michael 2017-05-07 09:36:02 -04:00
parent 2fdd32182c
commit 8e6196fd1d

View file

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