mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-23 01:32:16 +00:00
JoinGroup action
This commit is contained in:
parent
2fdd32182c
commit
8e6196fd1d
1 changed files with 15 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using Microsoft.AspNet.Identity;
|
||||||
using Project_Unite.Models;
|
using Project_Unite.Models;
|
||||||
|
|
||||||
namespace Project_Unite.Controllers
|
namespace Project_Unite.Controllers
|
||||||
|
@ -16,6 +17,20 @@ public ActionResult Index()
|
||||||
return View(db.Groups);
|
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]
|
[Authorize]
|
||||||
public ActionResult ViewGroup(string id)
|
public ActionResult ViewGroup(string id)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue