From 47a8fdc9c725bfa468e77366e6d136400ef5e947 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 7 May 2017 09:31:55 -0400 Subject: [PATCH] View Group page --- Project-Unite/ACL.cs | 6 +++ Project-Unite/Controllers/GroupsController.cs | 11 ++++++ Project-Unite/Project-Unite.csproj | 1 + Project-Unite/Views/Groups/ViewGroup.cshtml | 37 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 Project-Unite/Views/Groups/ViewGroup.cshtml diff --git a/Project-Unite/ACL.cs b/Project-Unite/ACL.cs index cc1c511..ce3bb15 100644 --- a/Project-Unite/ACL.cs +++ b/Project-Unite/ACL.cs @@ -109,6 +109,12 @@ public static IHtmlString TopicLinkFor(this HtmlHelper hpr, string topicId) return hpr.ActionLink(topic.Subject, "ViewTopic", "Forum", new { id = topic.Discriminator }, null); } + public static string GetUserGroup(string uid) + { + var db = new ApplicationDbContext(); + return db.Users.FirstOrDefault(x => x.Id == uid).GroupId; + } + public static string ResolveUserLinksInMarkdown(string mkdn) { string[] words = mkdn.Split(' '); diff --git a/Project-Unite/Controllers/GroupsController.cs b/Project-Unite/Controllers/GroupsController.cs index 96aa401..e3f0907 100644 --- a/Project-Unite/Controllers/GroupsController.cs +++ b/Project-Unite/Controllers/GroupsController.cs @@ -15,5 +15,16 @@ public ActionResult Index() var db = new ApplicationDbContext(); return View(db.Groups); } + + [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); + } } } \ No newline at end of file diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj index e70f34c..24f4579 100644 --- a/Project-Unite/Project-Unite.csproj +++ b/Project-Unite/Project-Unite.csproj @@ -590,6 +590,7 @@ + diff --git a/Project-Unite/Views/Groups/ViewGroup.cshtml b/Project-Unite/Views/Groups/ViewGroup.cshtml new file mode 100644 index 0000000..8409e0a --- /dev/null +++ b/Project-Unite/Views/Groups/ViewGroup.cshtml @@ -0,0 +1,37 @@ +@model Project_Unite.Models.Group +@{ + ViewBag.Title = Model.Name + " - Groups "; +} +@using Microsoft.AspNet.Identity; + +
+

[@Model.ShortName] @Model.Name

+
+ + +
+
+ @Html.Markdown(Model.Description) +
+
+ @if (ACL.GetUserGroup(User.Identity.GetUserId()) == Model.Id) + { + @Html.ActionLink("Leave", "LeaveGroup", "Groups", null, new { @class = "btn btn-default" }) + } + else + { + @if (Model.Publicity == 0 || Model.Publicity == 2) + { + @Html.ActionLink("Join", "JoinGroup", "Groups", new { id = Model.Id }, new { @class = "btn btn-default" }) + } + } +
+ @if(Model.Publicity > 1) + { +

This group is private.

+ +

Please respect that. Do not share this group link with anyone not authorized by the group administrators.

+ } +
+
+