blob: 52133496741e80615e96998042b86568e847ef8f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using Project_Unite.Models;
namespace Project_Unite.Controllers
{
public class GroupsController : Controller
{
// GET: Groups
public ActionResult Index()
{
var db = new ApplicationDbContext();
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)
{
var db = new ApplicationDbContext();
var group = db.Groups.FirstOrDefault(x => x.Id == id);
if (group == null)
return new HttpStatusCodeResult(404);
return View(group);
}
}
}
|