From 9596d9aa474d63a2e1d94c31f6757a65de97ef37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Tue, 5 May 2020 23:25:28 +0200 Subject: [PATCH] Teams creation and prizes creation are implemented --- MVCUI/Controllers/PeopleController.cs | 1 + MVCUI/Controllers/PrizesController.cs | 51 ++++++++++++++++ MVCUI/Controllers/TeamsController.cs | 59 ++++++++++++++++++ MVCUI/MVCUI.csproj | 8 ++- MVCUI/Models/TeamMVCModel.cs | 19 ++++++ MVCUI/Views/Prizes/Create.cshtml | 63 ++++++++++++++++++++ MVCUI/Views/Prizes/Index.cshtml | 46 ++++++++++++++ MVCUI/Views/Shared/_Layout.cshtml | 6 ++ MVCUI/Views/Teams/Create.cshtml | 52 ++++++++++++++++ MVCUI/Views/Teams/Index.cshtml | 43 +++++++++++++ TrackerLibrary/DataAccess/IDataConnection.cs | 1 + TrackerLibrary/DataAccess/SqlConnector.cs | 10 ++++ TrackerLibrary/DataAccess/TextConnector.cs | 7 +++ TrackerLibrary/Models/PrizeModel.cs | 20 ++++++- TrackerLibrary/Models/TeamModel.cs | 5 ++ 15 files changed, 387 insertions(+), 4 deletions(-) create mode 100644 MVCUI/Controllers/PrizesController.cs create mode 100644 MVCUI/Controllers/TeamsController.cs create mode 100644 MVCUI/Models/TeamMVCModel.cs create mode 100644 MVCUI/Views/Prizes/Create.cshtml create mode 100644 MVCUI/Views/Prizes/Index.cshtml create mode 100644 MVCUI/Views/Teams/Create.cshtml create mode 100644 MVCUI/Views/Teams/Index.cshtml diff --git a/MVCUI/Controllers/PeopleController.cs b/MVCUI/Controllers/PeopleController.cs index b7bf918..05b37e4 100644 --- a/MVCUI/Controllers/PeopleController.cs +++ b/MVCUI/Controllers/PeopleController.cs @@ -25,6 +25,7 @@ namespace MVCUI.Controllers } // POST: People/Create + [ValidateAntiForgeryToken()] [HttpPost] public ActionResult Create(PersonModel p) { diff --git a/MVCUI/Controllers/PrizesController.cs b/MVCUI/Controllers/PrizesController.cs new file mode 100644 index 0000000..8ca5b8e --- /dev/null +++ b/MVCUI/Controllers/PrizesController.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using TrackerLibrary; +using TrackerLibrary.Models; + +namespace MVCUI.Controllers +{ + public class PrizesController : Controller + { + // GET: Prizes + public ActionResult Index() + { + List allPrizes = GlobalConfig.Connection.GetPrizes_All(); + return View(allPrizes); + } + + + // GET: Prizes/Create + public ActionResult Create() + { + return View(); + } + + // POST: Prizes/Create + [ValidateAntiForgeryToken()] + [HttpPost] + public ActionResult Create(PrizeModel p) + { + try + { + if (ModelState.IsValid) + { + GlobalConfig.Connection.CreatePrize(p); + return RedirectToAction("Index"); + } + else + { + return View(); + + } + } + catch + { + return View(); + } + } + } +} \ No newline at end of file diff --git a/MVCUI/Controllers/TeamsController.cs b/MVCUI/Controllers/TeamsController.cs new file mode 100644 index 0000000..3ba3a16 --- /dev/null +++ b/MVCUI/Controllers/TeamsController.cs @@ -0,0 +1,59 @@ +using MVCUI.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using TrackerLibrary; +using TrackerLibrary.Models; + +namespace MVCUI.Controllers +{ + public class TeamsController : Controller + { + // GET: Teams + public ActionResult Index() + { + List allTeams = GlobalConfig.Connection.GetTeam_All(); + return View(allTeams); + } + + + // GET: Teams/Create + public ActionResult Create() + { + List people = GlobalConfig.Connection.GetPerson_All(); + TeamMVCModel input = new TeamMVCModel(); + + input.TeamMembers = people.Select(x => new SelectListItem { Text = x.FullName, Value = x.Id.ToString() }).ToList(); + return View(input); + } + + // POST: Teams/Create + [ValidateAntiForgeryToken()] + [HttpPost] + public ActionResult Create(TeamMVCModel model) + { + try + { + // TODO: Add insert logic here + if(ModelState.IsValid && model.SelectedTeamMembers.Count > 0) + { + TeamModel t = new TeamModel(); + t.TeamName = model.TeamName; + t.TeamMembers = model.SelectedTeamMembers.Select(x => new PersonModel { Id = int.Parse(x) }).ToList(); + GlobalConfig.Connection.CreateTeam(t); + return RedirectToAction("Index"); + } + else + { + return RedirectToAction("Create"); + } + } + catch + { + return View(); + } + } + } +} diff --git a/MVCUI/MVCUI.csproj b/MVCUI/MVCUI.csproj index 8e86820..cca28bb 100644 --- a/MVCUI/MVCUI.csproj +++ b/MVCUI/MVCUI.csproj @@ -124,9 +124,12 @@ + + Global.asax + @@ -266,10 +269,13 @@ + + + + - diff --git a/MVCUI/Models/TeamMVCModel.cs b/MVCUI/Models/TeamMVCModel.cs new file mode 100644 index 0000000..4a93758 --- /dev/null +++ b/MVCUI/Models/TeamMVCModel.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Web.Mvc; + +namespace MVCUI.Models +{ + public class TeamMVCModel + { + [Display(Name = "Team Name")] + [StringLength(100, MinimumLength = 2)] + [Required] + public string TeamName { get; set; } + [Display(Name = "Team Member List")] + public List TeamMembers { get; set; } = new List(); + + public List SelectedTeamMembers { get; set; } = new List(); + + } +} \ No newline at end of file diff --git a/MVCUI/Views/Prizes/Create.cshtml b/MVCUI/Views/Prizes/Create.cshtml new file mode 100644 index 0000000..7d7957b --- /dev/null +++ b/MVCUI/Views/Prizes/Create.cshtml @@ -0,0 +1,63 @@ +@model TrackerLibrary.Models.PrizeModel + +@{ + ViewBag.Title = "Create"; +} + +

Create A New Prize

+ + +@using (Html.BeginForm()) +{ + @Html.AntiForgeryToken() + +
+
+ @Html.ValidationSummary(true, "", new { @class = "text-danger" }) +
+ @Html.LabelFor(model => model.PlaceNumber, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.PlaceNumber, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.PlaceNumber, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.PlaceName, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.PlaceName, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.PlaceName, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.PrizeAmount, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.PrizeAmount, new { htmlAttributes = new { @class = "form-control", @value = 0 } }) + @Html.ValidationMessageFor(model => model.PrizeAmount, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.PrizePercentage, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.PrizePercentage, new { htmlAttributes = new { @class = "form-control", @value = 0 } }) + @Html.ValidationMessageFor(model => model.PrizePercentage, "", new { @class = "text-danger" }) +
+
+ +
+
+ +
+
+
+} + +
+ @Html.ActionLink("Back to List", "Index") +
+ +@section Scripts { + @Scripts.Render("~/bundles/jqueryval") +} diff --git a/MVCUI/Views/Prizes/Index.cshtml b/MVCUI/Views/Prizes/Index.cshtml new file mode 100644 index 0000000..ff87ff1 --- /dev/null +++ b/MVCUI/Views/Prizes/Index.cshtml @@ -0,0 +1,46 @@ +@model IEnumerable + +@{ + ViewBag.Title = "Index"; +} + +

View All Prizes

+ +

+ @Html.ActionLink("Create New", "Create") +

+ + + + + + + + +@foreach (var item in Model) { + + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.PlaceNumber) + + @Html.DisplayNameFor(model => model.PlaceName) + + @Html.DisplayNameFor(model => model.PrizeAmount) + + @Html.DisplayNameFor(model => model.PrizePercentage) +
+ @Html.DisplayFor(modelItem => item.PlaceNumber) + + @Html.DisplayFor(modelItem => item.PlaceName) + + @Html.DisplayFor(modelItem => item.PrizeAmount) + + @Html.DisplayFor(modelItem => item.PrizePercentage) +
diff --git a/MVCUI/Views/Shared/_Layout.cshtml b/MVCUI/Views/Shared/_Layout.cshtml index aa7a3fe..413ccb1 100644 --- a/MVCUI/Views/Shared/_Layout.cshtml +++ b/MVCUI/Views/Shared/_Layout.cshtml @@ -27,6 +27,12 @@ + + @* diff --git a/MVCUI/Views/Teams/Create.cshtml b/MVCUI/Views/Teams/Create.cshtml new file mode 100644 index 0000000..873f996 --- /dev/null +++ b/MVCUI/Views/Teams/Create.cshtml @@ -0,0 +1,52 @@ +@model MVCUI.Models.TeamMVCModel + +@{ + ViewBag.Title = "Create"; +} + +

Create New Team

+ + +@using (Html.BeginForm()) +{ + @Html.AntiForgeryToken() + +
+

TeamModel

+
+ @Html.ValidationSummary(true, "", new { @class = "text-danger" }) +
+ @Html.LabelFor(model => model.TeamName, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.TeamName, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.TeamName, "", new { @class = "text-danger" }) +
+
+
+ @Html.LabelFor(model => model.TeamMembers,htmlAttributes:new { @class = "control-label col-md-2"}) +
+ @foreach (var item in Model.TeamMembers) + { +
+ +
+ } +
+
+
+
+ +
+
+
+} + +
+ @Html.ActionLink("Back to List", "Index") +
+ +@section Scripts { + @Scripts.Render("~/bundles/jqueryval") +} diff --git a/MVCUI/Views/Teams/Index.cshtml b/MVCUI/Views/Teams/Index.cshtml new file mode 100644 index 0000000..eda86b5 --- /dev/null +++ b/MVCUI/Views/Teams/Index.cshtml @@ -0,0 +1,43 @@ +@model IEnumerable + +@{ + ViewBag.Title = "Index"; +} + +

All Teams

+ +

+ @Html.ActionLink("Create New", "Create") +

+ + + + + + +@foreach (var item in Model) { + + + + +} + +
+ @Html.DisplayNameFor(model => model.TeamName) + + @Html.DisplayNameFor(model => model.TeamMembers) +
+ @Html.DisplayFor(modelItem => item.TeamName) + + @for (int i = 0; i < item.TeamMembers.Count; i++) + { + if (i == 0) + { + @(item.TeamMembers[i].FullName); + } + else + { + @(", " + item.TeamMembers[i].FullName); + } + } +
diff --git a/TrackerLibrary/DataAccess/IDataConnection.cs b/TrackerLibrary/DataAccess/IDataConnection.cs index 6323266..7624253 100644 --- a/TrackerLibrary/DataAccess/IDataConnection.cs +++ b/TrackerLibrary/DataAccess/IDataConnection.cs @@ -15,6 +15,7 @@ namespace TrackerLibrary.DataAccess void CompleteTournament(TournamentModel model); List GetTeam_All(); List GetPerson_All(); + List GetPrizes_All(); List GetTournament_All(); } } diff --git a/TrackerLibrary/DataAccess/SqlConnector.cs b/TrackerLibrary/DataAccess/SqlConnector.cs index 63ff553..9180d0e 100644 --- a/TrackerLibrary/DataAccess/SqlConnector.cs +++ b/TrackerLibrary/DataAccess/SqlConnector.cs @@ -225,6 +225,16 @@ namespace TrackerLibrary.DataAccess return output; } + public List GetPrizes_All() + { + List output; + using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db))) + { + output = connection.Query("dbo.spPrizes_GetAll").ToList(); + } + return output; + } + public List GetTournament_All() { List output; diff --git a/TrackerLibrary/DataAccess/TextConnector.cs b/TrackerLibrary/DataAccess/TextConnector.cs index 2dedf9c..c4b14a3 100644 --- a/TrackerLibrary/DataAccess/TextConnector.cs +++ b/TrackerLibrary/DataAccess/TextConnector.cs @@ -122,6 +122,13 @@ namespace TrackerLibrary.DataAccess .ConvertToTournamentModels(); } + public List GetPrizes_All() + { + List output; + output = GlobalConfig.PrizesFile.FullFilePath().LoadFile().ConvertToPrizeModels(); + return output; + } + public void UpdateMatchup(MatchupModel model) { model.UpdateMatchupToFile(); diff --git a/TrackerLibrary/Models/PrizeModel.cs b/TrackerLibrary/Models/PrizeModel.cs index 6a92d07..e40c603 100644 --- a/TrackerLibrary/Models/PrizeModel.cs +++ b/TrackerLibrary/Models/PrizeModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Text; namespace TrackerLibrary.Models @@ -7,13 +8,26 @@ namespace TrackerLibrary.Models public class PrizeModel { - /// - /// The unique identifier for the prize - /// + /// + /// The unique identifier for the prize + /// public int Id { get; set; } + + [Display(Name = "Place Number")] + [Range(1, 100)] + [Required] public int PlaceNumber { get; set; } + + [Display(Name = "Place Name")] + [StringLength(100, MinimumLength = 3)] + [Required] public string PlaceName { get; set; } + + [Display(Name = "Prize Amount")] + [DataType(DataType.Currency)] public decimal PrizeAmount { get; set; } + + [Display(Name = "Prize Percentage")] public double PrizePercentage { get; set; } public PrizeModel() diff --git a/TrackerLibrary/Models/TeamModel.cs b/TrackerLibrary/Models/TeamModel.cs index 1557888..2f2af6c 100644 --- a/TrackerLibrary/Models/TeamModel.cs +++ b/TrackerLibrary/Models/TeamModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Text; namespace TrackerLibrary.Models @@ -7,7 +8,11 @@ namespace TrackerLibrary.Models public class TeamModel { public int Id { get; set; } + [Display(Name = "Team Member List")] public List TeamMembers { get; set; } = new List(); + [Display(Name = "Team Name")] + //[StringLength(100, MinimumLength = 2)] + //[Required] public string TeamName { get; set; } } }