diff --git a/MVCUI/Controllers/TeamsController.cs b/MVCUI/Controllers/TeamsController.cs index 3ba3a16..0bc5b7e 100644 --- a/MVCUI/Controllers/TeamsController.cs +++ b/MVCUI/Controllers/TeamsController.cs @@ -36,8 +36,7 @@ namespace MVCUI.Controllers { try { - // TODO: Add insert logic here - if(ModelState.IsValid && model.SelectedTeamMembers.Count > 0) + if(ModelState.IsValid && model.SelectedTeamMembers.Count > 0) { TeamModel t = new TeamModel(); t.TeamName = model.TeamName; diff --git a/MVCUI/Controllers/TournamentsController.cs b/MVCUI/Controllers/TournamentsController.cs new file mode 100644 index 0000000..649d639 --- /dev/null +++ b/MVCUI/Controllers/TournamentsController.cs @@ -0,0 +1,69 @@ +using MVCUI.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using System.Web.Services.Description; +using TrackerLibrary; +using TrackerLibrary.Models; + +namespace MVCUI.Controllers +{ + public class TournamentsController : Controller + { + // GET: Tournaments + public ActionResult Index() + { + return RedirectToAction("Index", "Home"); + } + + public ActionResult Create() + { + TournamentMVCModel input = new TournamentMVCModel(); + List allTeams = GlobalConfig.Connection.GetTeam_All(); + List allPrizes = GlobalConfig.Connection.GetPrizes_All(); + + input.EnteredTeams = allTeams.Select(x => new SelectListItem { Text = x.TeamName, Value = x.Id.ToString() }).ToList(); + input.Prizes = allPrizes.Select(x => new SelectListItem { Text = x.PlaceName, Value = x.Id.ToString() }).ToList(); + + return View(input); + } + + // POST: Tournament/Create + [ValidateAntiForgeryToken()] + [HttpPost] + public ActionResult Create(TournamentMVCModel model) + { + try + { + if (ModelState.IsValid && model.SelectedEnteredTeams.Count > 0) + { + TournamentModel t = new TournamentModel(); + t.TournamentName = model.TournamentName; + t.EntryFee = model.EntryFee; + t.EnteredTeams = model.SelectedEnteredTeams.Select(x => new TeamModel { Id = int.Parse(x) }).ToList(); + t.Prizes = model.SelectedPrizes.Select(x => new PrizeModel { Id = int.Parse(x) }).ToList(); + + TournamentLogic.CreateRounds(t); + + GlobalConfig.Connection.CreateTournament(t); + + t.AlertUsersToNewRound(); + + return RedirectToAction("Index","Home"); + } + else + { + return RedirectToAction("Create"); + } + } + catch(Exception ex) + { + + var fel = ex; + return View(); + } + } + } +} \ No newline at end of file diff --git a/MVCUI/MVCUI.csproj b/MVCUI/MVCUI.csproj index cca28bb..0346dda 100644 --- a/MVCUI/MVCUI.csproj +++ b/MVCUI/MVCUI.csproj @@ -51,6 +51,9 @@ ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\ObjectDumper.NET.2.5.20033.1\lib\net45\ObjectDumping.dll + @@ -126,10 +129,12 @@ + Global.asax + @@ -273,6 +278,7 @@ + diff --git a/MVCUI/Models/TournamentMVCModel.cs b/MVCUI/Models/TournamentMVCModel.cs new file mode 100644 index 0000000..a45c759 --- /dev/null +++ b/MVCUI/Models/TournamentMVCModel.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using TrackerLibrary.Models; + +namespace MVCUI.Models +{ + public class TournamentMVCModel + { + [Display(Name = "Tournament Name")] + [StringLength(100, MinimumLength = 2)] + [Required] + public string TournamentName { get; set; } + /// + /// The amount of money each team needs to put up to enter + /// + [Display(Name = "Entry Fee")] + [DataType(DataType.Currency)] + [Required] + public decimal EntryFee { get; set; } + /// + /// The set of teams that have entered + /// + [Display(Name = "Entered Teams")] + public List EnteredTeams { get; set; } = new List(); + /// + /// The list of prizes for various places + /// + public List SelectedEnteredTeams { get; set; } = new List(); + + [Display(Name = "Prizes")] + public List Prizes { get; set; } = new List(); + public List SelectedPrizes { get; set; } = new List(); + + } +} \ No newline at end of file diff --git a/MVCUI/Views/Home/Index.cshtml b/MVCUI/Views/Home/Index.cshtml index 050d02b..ba7a316 100644 --- a/MVCUI/Views/Home/Index.cshtml +++ b/MVCUI/Views/Home/Index.cshtml @@ -6,35 +6,35 @@ -
-
-
-

Office Fun!

-

Track your in office tournament easily and have a great time doing it.

-

Create a tournament

+
+
+
+

Office Fun!

+

Track your in office tournament easily and have a great time doing it.

+

@Html.ActionLink("Create a Tournament", "Create", "Tournaments", new { area = "" }, new { @class = "btn btn-primary btn-lg" })

+
+
+
+

Play with friends

+

+ Get a team and get started today on a new tournament. +

-
-
-

Play with friends

-

- Get a team and get started today on a new tournament. -

-
-
-

Win prizes

-

Set up a tournament with prizes for first and second place and compete to win.

-
+
+

Win prizes

+

Set up a tournament with prizes for first and second place and compete to win.

-
-

Current Tournament

-
+
+

Current Tournament

+ -
+ +
-
\ No newline at end of file +
\ No newline at end of file diff --git a/MVCUI/Views/Shared/_Layout.cshtml b/MVCUI/Views/Shared/_Layout.cshtml index 413ccb1..52eb781 100644 --- a/MVCUI/Views/Shared/_Layout.cshtml +++ b/MVCUI/Views/Shared/_Layout.cshtml @@ -33,14 +33,9 @@ - @* - *@
+
diff --git a/MVCUI/Views/Tournaments/Create.cshtml b/MVCUI/Views/Tournaments/Create.cshtml new file mode 100644 index 0000000..4da026e --- /dev/null +++ b/MVCUI/Views/Tournaments/Create.cshtml @@ -0,0 +1,72 @@ +@model MVCUI.Models.TournamentMVCModel + +@{ + ViewBag.Title = "Create"; +} + +

+

Create New Tournament

+ +@using (Html.BeginForm()) +{ +
+ @Html.AntiForgeryToken() +
+ @Html.ValidationSummary(true, "", new { @class = "text-danger" }) +
+
+ @Html.LabelFor(model => model.TournamentName, htmlAttributes: new { @class = "control-label" }) +
+ @Html.EditorFor(model => model.TournamentName, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.TournamentName, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.EntryFee, htmlAttributes: new { @class = "control-label" }) +
+ @Html.EditorFor(model => model.EntryFee, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.EntryFee, "", new { @class = "text-danger" }) +
+
+
+
+ +
+
+
+
+ @Html.LabelFor(model => model.EnteredTeams, htmlAttributes: new { @class = "control-label" }) +
+ @foreach (var item in Model.EnteredTeams) + { +
+ +
+ } +
+
+
+ @Html.LabelFor(model => model.Prizes, htmlAttributes: new { @class = "control-label" }) +
+ @foreach (var item in Model.Prizes) + { +
+ +
+ } +
+
+
+} +
+ @Html.ActionLink("Back to List", "Index") +
+ +@section Scripts { + @Scripts.Render("~/bundles/jqueryval") +} diff --git a/MVCUI/packages.config b/MVCUI/packages.config index 1cfd80a..0354dce 100644 --- a/MVCUI/packages.config +++ b/MVCUI/packages.config @@ -13,6 +13,7 @@ + \ No newline at end of file diff --git a/TrackerLibrary/TrackerLibrary.csproj b/TrackerLibrary/TrackerLibrary.csproj index 468a692..ebf69ca 100644 --- a/TrackerLibrary/TrackerLibrary.csproj +++ b/TrackerLibrary/TrackerLibrary.csproj @@ -46,6 +46,9 @@ ..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\ObjectDumper.NET.2.5.20033.1\lib\net45\ObjectDumping.dll + diff --git a/TrackerLibrary/packages.config b/TrackerLibrary/packages.config index 54f047e..345841b 100644 --- a/TrackerLibrary/packages.config +++ b/TrackerLibrary/packages.config @@ -5,6 +5,7 @@ + \ No newline at end of file diff --git a/TrackerUI/TrackerUI.csproj b/TrackerUI/TrackerUI.csproj index 68f20fe..bbcc307 100644 --- a/TrackerUI/TrackerUI.csproj +++ b/TrackerUI/TrackerUI.csproj @@ -33,6 +33,9 @@ 4 + + ..\packages\ObjectDumper.NET.2.5.20033.1\lib\net45\ObjectDumping.dll + @@ -104,6 +107,7 @@ TournamentViewerForm.cs + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/TrackerUI/packages.config b/TrackerUI/packages.config new file mode 100644 index 0000000..a22998f --- /dev/null +++ b/TrackerUI/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file