summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-05-07 10:04:12 -0400
committerMichael <[email protected]>2017-05-07 10:04:12 -0400
commitca5954e7d2b9c2040f6f421816778d8203161563 (patch)
treebb31a48e7632f78e7a1a3d21ac43658dd278c636
parente6c0552be8363a597d2427c2ef1fcb73672ed6e1 (diff)
downloadproject-unite-ca5954e7d2b9c2040f6f421816778d8203161563.tar.gz
project-unite-ca5954e7d2b9c2040f6f421816778d8203161563.tar.bz2
project-unite-ca5954e7d2b9c2040f6f421816778d8203161563.zip
Create group page
-rw-r--r--Project-Unite/Controllers/GroupsController.cs65
-rw-r--r--Project-Unite/Models/Group.cs60
-rw-r--r--Project-Unite/Project-Unite.csproj1
-rw-r--r--Project-Unite/Views/Groups/CreateGroup.cshtml50
-rw-r--r--Project-Unite/Views/Groups/Index.cshtml4
5 files changed, 179 insertions, 1 deletions
diff --git a/Project-Unite/Controllers/GroupsController.cs b/Project-Unite/Controllers/GroupsController.cs
index 264b0e6..d171d98 100644
--- a/Project-Unite/Controllers/GroupsController.cs
+++ b/Project-Unite/Controllers/GroupsController.cs
@@ -18,6 +18,71 @@ namespace Project_Unite.Controllers
}
[Authorize]
+ public ActionResult CreateGroup()
+ {
+ //NOPE. I'm not circumming to the ways of Victor Tran. CURLY BRACES ON THEIR OWN LINE.
+ var model = new GroupViewModel();
+ return View(model);
+ }
+
+ private bool ValidateHex(string hex)
+ {
+ if (!(hex.Length == 3 || hex.Length == 6))
+ return false;
+ string hexallowed = "0123456789abcdef";
+ foreach(var c in hex.ToLower().ToCharArray())
+ {
+ if (!hexallowed.Contains(c))
+ return false;
+ }
+ return true;
+ }
+
+ [Authorize]
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult CreateGroup(GroupViewModel model)
+ {
+ var result = ValidateHex(model.BannerColorHex);
+
+ if(result == false)
+ {
+ ModelState.AddModelError("BannerColorHex", new Exception("Invalid hexadecimal color code."));
+ }
+
+ if (!ModelState.IsValid)
+ return View(model);
+
+ var db = new ApplicationDbContext();
+ var group = new Group();
+ group.Id = Guid.NewGuid().ToString();
+ group.Name = model.Name;
+ group.ShortName = model.ShortName;
+ group.Description = model.Description;
+ switch (model.Publicity)
+ {
+ case "public":
+ group.Publicity = 0;
+ break;
+ case "publici":
+ group.Publicity = 1;
+ break;
+ case "private":
+ group.Publicity = 2;
+ break;
+ case "privatei":
+ group.Publicity = 3;
+ break;
+ }
+ group.RawReputation = 0.00;
+ group.BannerColorHex = model.BannerColorHex;
+
+ db.Groups.Add(group);
+ db.SaveChanges();
+ return RedirectToAction("JoinGroup", "Groups", new { id = group.Id });
+ }
+
+ [Authorize]
public ActionResult JoinGroup(string id)
{
var db = new ApplicationDbContext();
diff --git a/Project-Unite/Models/Group.cs b/Project-Unite/Models/Group.cs
index da5b277..3ecf2f3 100644
--- a/Project-Unite/Models/Group.cs
+++ b/Project-Unite/Models/Group.cs
@@ -1,19 +1,79 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
+using System.Web.Mvc;
namespace Project_Unite.Models
{
+ public class GroupViewModel
+ {
+ public List<SelectListItem> Publicities
+ {
+ get
+ {
+ return new List<SelectListItem>
+ {
+ new SelectListItem { Value="public", Text="Public"},
+ new SelectListItem { Value="publici", Text="Public (Invite Only)"},
+ new SelectListItem { Value="private", Text="Private"},
+ new SelectListItem { Value="privatei", Text="Private (Invite Only)" }
+ };
+ }
+ }
+
+ [Required]
+ [MaxLength(25, ErrorMessage = "Your group's name must have a maximum of 25 characters in it.")]
+ [MinLength(5, ErrorMessage = "You must set a name with at least 5 characters in it.")]
+ public string Name { get; set; }
+
+ [Required]
+ public string Publicity { get; set; }
+
+ [Required]
+ [MaxLength(6, ErrorMessage = "Hexadecimal color values can only have 6 or less digits.")]
+ [MinLength(3, ErrorMessage = "Hexadecimal color values must have at least 3 digits.")]
+ public string BannerColorHex { get; set; }
+
+ [Required]
+ [AllowHtml]
+ public string Description { get; set; }
+
+ [Required]
+ [MaxLength(4, ErrorMessage = "Your Short Name can only have 4 characters. Think of it like an acronym.")]
+ public string ShortName { get; set; }
+
+ }
+
+
public class Group
{
+ [Required]
public string Id { get; set; }
+
+ [Required]
+ [MaxLength(25, ErrorMessage ="Your group's name must have a maximum of 25 characters in it.")]
+ [MinLength(5, ErrorMessage ="You must set a name with at least 5 characters in it.")]
public string Name { get; set; }
+
+ [Required]
public int Publicity { get; set; }
+
+ [Required]
+ [MaxLength(6, ErrorMessage ="Hexadecimal color values can only have 6 or less digits.")]
+ [MinLength(3, ErrorMessage ="Hexadecimal color values must have at least 3 digits.")]
public string BannerColorHex { get; set; }
+
+ [Required]
+ [AllowHtml]
public string Description { get; set; }
+
+ [Required]
+ [MaxLength(4, ErrorMessage ="Your Short Name can only have 4 characters. Think of it like an acronym.")]
public string ShortName { get; set; }
+ [Required]
public double RawReputation { get; set; }
public ApplicationUser[] Users
diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj
index 24f4579..11604fa 100644
--- a/Project-Unite/Project-Unite.csproj
+++ b/Project-Unite/Project-Unite.csproj
@@ -591,6 +591,7 @@
<Content Include="Views\Stats\Codepoints.cshtml" />
<Content Include="Views\Groups\Index.cshtml" />
<Content Include="Views\Groups\ViewGroup.cshtml" />
+ <Content Include="Views\Groups\CreateGroup.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
diff --git a/Project-Unite/Views/Groups/CreateGroup.cshtml b/Project-Unite/Views/Groups/CreateGroup.cshtml
new file mode 100644
index 0000000..3b26f86
--- /dev/null
+++ b/Project-Unite/Views/Groups/CreateGroup.cshtml
@@ -0,0 +1,50 @@
+@model Project_Unite.Models.GroupViewModel
+@{
+ ViewBag.Title = "Create a group";
+}
+
+<h2>Create a group</h2>
+
+<p>This page allows you to create a group. Note that when you create the group, you will leave your current group if you are in one.</p>
+
+@using (Html.BeginForm())
+{
+ <div class="panel panel-danger">
+ <div class="panel-body">
+ @Html.ValidationSummary()
+ </div>
+ </div>
+
+
+ @Html.AntiForgeryToken()
+ <table class="table">
+ <tr>
+ <td style="width:25%">
+ <strong>Group name:</strong>
+ </td>
+ <td>@Html.TextBoxFor(Model=>Model.Name, new{@class="form-control"})</td>
+ </tr>
+ <tr><td><strong>Short name:</strong>
+ <p>Your "Short Name" is simply a tag for your group. Think of a neat acronym to go with your group. Something clever that can fit in 4 characters or less.</p>
+ </td>
+ <td>@Html.TextBoxFor(Model=>Model.ShortName, new { @class = "form-control" })</td>
+ </tr>
+ <tr>
+ <td><strong>Group description:</strong></td>
+ <td>@Html.TextAreaFor(Model=>Model.Description)</td>
+ </tr>
+ <tr>
+ <td><strong>Banner color (hexadecimal):</strong></td>
+ <td>@Html.TextBoxFor(Model=>Model.BannerColorHex, new {@class="form-control"})</td>
+ </tr>
+ <tr>
+ <td><strong>Publicity:</strong></td>
+ <td>@Html.DropDownListFor(Model=>Model.Publicity, Model.Publicities, new { @class = "form-control" })
+ </tr>
+ <tr>
+ <td></td>
+ <td><input type="submit" value="Create!" class="btn btn-primary" /></td>
+ </tr>
+
+ </table>
+} \ No newline at end of file
diff --git a/Project-Unite/Views/Groups/Index.cshtml b/Project-Unite/Views/Groups/Index.cshtml
index 7364df0..f0f535f 100644
--- a/Project-Unite/Views/Groups/Index.cshtml
+++ b/Project-Unite/Views/Groups/Index.cshtml
@@ -10,7 +10,9 @@
<p>You can join one of the in-game groups from your Digital Society Control Centre, or you can join one of the many user-created groups here.</p>
-
+<ul class="nav nav-pills">
+ <li><a href="@Url.Action("CreateGroup")"><span class="glyphicon glyphicon-plus"></span> Create new group</a></li>
+</ul>
<table class="table">
<tr>