mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-02-02 13:07:34 +00:00
Create group page
This commit is contained in:
parent
e6c0552be8
commit
ca5954e7d2
5 changed files with 182 additions and 4 deletions
|
@ -17,6 +17,71 @@ namespace Project_Unite.Controllers
|
||||||
return View(db.Groups);
|
return View(db.Groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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]
|
[Authorize]
|
||||||
public ActionResult JoinGroup(string id)
|
public ActionResult JoinGroup(string id)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,19 +1,79 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
namespace Project_Unite.Models
|
namespace Project_Unite.Models
|
||||||
{
|
{
|
||||||
public class Group
|
public class GroupViewModel
|
||||||
{
|
{
|
||||||
public string Id { get; set; }
|
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; }
|
public string Name { get; set; }
|
||||||
public int Publicity { 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; }
|
public string BannerColorHex { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[AllowHtml]
|
||||||
public string Description { get; set; }
|
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 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 double RawReputation { get; set; }
|
||||||
|
|
||||||
public ApplicationUser[] Users
|
public ApplicationUser[] Users
|
||||||
|
|
|
@ -591,6 +591,7 @@
|
||||||
<Content Include="Views\Stats\Codepoints.cshtml" />
|
<Content Include="Views\Stats\Codepoints.cshtml" />
|
||||||
<Content Include="Views\Groups\Index.cshtml" />
|
<Content Include="Views\Groups\Index.cshtml" />
|
||||||
<Content Include="Views\Groups\ViewGroup.cshtml" />
|
<Content Include="Views\Groups\ViewGroup.cshtml" />
|
||||||
|
<Content Include="Views\Groups\CreateGroup.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="App_Data\" />
|
<Folder Include="App_Data\" />
|
||||||
|
|
50
Project-Unite/Views/Groups/CreateGroup.cshtml
Normal file
50
Project-Unite/Views/Groups/CreateGroup.cshtml
Normal file
|
@ -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>
|
||||||
|
}
|
|
@ -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>
|
<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">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Add table
Reference in a new issue