diff options
| author | Michael <[email protected]> | 2017-05-07 10:04:12 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-05-07 10:04:12 -0400 |
| commit | ca5954e7d2b9c2040f6f421816778d8203161563 (patch) | |
| tree | bb31a48e7632f78e7a1a3d21ac43658dd278c636 /Project-Unite/Controllers | |
| parent | e6c0552be8363a597d2427c2ef1fcb73672ed6e1 (diff) | |
| download | project-unite-ca5954e7d2b9c2040f6f421816778d8203161563.tar.gz project-unite-ca5954e7d2b9c2040f6f421816778d8203161563.tar.bz2 project-unite-ca5954e7d2b9c2040f6f421816778d8203161563.zip | |
Create group page
Diffstat (limited to 'Project-Unite/Controllers')
| -rw-r--r-- | Project-Unite/Controllers/GroupsController.cs | 65 |
1 files changed, 65 insertions, 0 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(); |
