Nu går det fint att skapa tournaments med teams och prizes

This commit is contained in:
2020-05-06 22:58:06 +02:00
parent 9596d9aa47
commit dc4162db95
12 changed files with 228 additions and 35 deletions

View File

@ -36,7 +36,6 @@ namespace MVCUI.Controllers
{ {
try try
{ {
// TODO: Add insert logic here
if(ModelState.IsValid && model.SelectedTeamMembers.Count > 0) if(ModelState.IsValid && model.SelectedTeamMembers.Count > 0)
{ {
TeamModel t = new TeamModel(); TeamModel t = new TeamModel();

View File

@ -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<TeamModel> allTeams = GlobalConfig.Connection.GetTeam_All();
List<PrizeModel> 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();
}
}
}
}

View File

@ -51,6 +51,9 @@
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="ObjectDumping, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ObjectDumper.NET.2.5.20033.1\lib\net45\ObjectDumping.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
@ -126,10 +129,12 @@
<Compile Include="Controllers\PeopleController.cs" /> <Compile Include="Controllers\PeopleController.cs" />
<Compile Include="Controllers\PrizesController.cs" /> <Compile Include="Controllers\PrizesController.cs" />
<Compile Include="Controllers\TeamsController.cs" /> <Compile Include="Controllers\TeamsController.cs" />
<Compile Include="Controllers\TournamentsController.cs" />
<Compile Include="Global.asax.cs"> <Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon> <DependentUpon>Global.asax</DependentUpon>
</Compile> </Compile>
<Compile Include="Models\TeamMVCModel.cs" /> <Compile Include="Models\TeamMVCModel.cs" />
<Compile Include="Models\TournamentMVCModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -273,6 +278,7 @@
<Content Include="Views\Teams\Create.cshtml" /> <Content Include="Views\Teams\Create.cshtml" />
<Content Include="Views\Prizes\Index.cshtml" /> <Content Include="Views\Prizes\Index.cshtml" />
<Content Include="Views\Prizes\Create.cshtml" /> <Content Include="Views\Prizes\Create.cshtml" />
<Content Include="Views\Tournaments\Create.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />

View File

@ -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; }
/// <summary>
/// The amount of money each team needs to put up to enter
/// </summary>
[Display(Name = "Entry Fee")]
[DataType(DataType.Currency)]
[Required]
public decimal EntryFee { get; set; }
/// <summary>
/// The set of teams that have entered
/// </summary>
[Display(Name = "Entered Teams")]
public List<SelectListItem> EnteredTeams { get; set; } = new List<SelectListItem>();
/// <summary>
/// The list of prizes for various places
/// </summary>
public List<string> SelectedEnteredTeams { get; set; } = new List<string>();
[Display(Name = "Prizes")]
public List<SelectListItem> Prizes { get; set; } = new List<SelectListItem>();
public List<string> SelectedPrizes { get; set; } = new List<string>();
}
}

View File

@ -11,7 +11,7 @@
<div class="jumbotron"> <div class="jumbotron">
<h1>Office Fun!</h1> <h1>Office Fun!</h1>
<p class="lead">Track your in office tournament easily and have a great time doing it.</p> <p class="lead">Track your in office tournament easily and have a great time doing it.</p>
<p><a href="https://asp.net" class="btn btn-primary btn-lg">Create a tournament</a></p> <p>@Html.ActionLink("Create a Tournament", "Create", "Tournaments", new { area = "" }, new { @class = "btn btn-primary btn-lg" })</p>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">

View File

@ -33,14 +33,9 @@
<li class="nav-item"> <li class="nav-item">
@Html.ActionLink("Prizes", "Index", "Prizes", new { area = "" }, new { @class = "nav-link text-light" }) @Html.ActionLink("Prizes", "Index", "Prizes", new { area = "" }, new { @class = "nav-link text-light" })
</li> </li>
@*<li class="nav-item">
@Html.ActionLink("About", "About", "Home", new { area = "" }, new { @class = "nav-link text-light" })
</li>
<li class="nav-item">
@Html.ActionLink("Contact", "Contact", "Home", new { area = "" }, new { @class = "nav-link text-light" })
</li>*@
</ul> </ul>
</div> </div>
</div>
</nav> </nav>
</header> </header>
<div class="container"> <div class="container">

View File

@ -0,0 +1,72 @@
@model MVCUI.Models.TournamentMVCModel
@{
ViewBag.Title = "Create";
}
<p> </p>
<h2 class="">Create New Tournament</h2>
@using (Html.BeginForm())
{
<div class="row">
@Html.AntiForgeryToken()
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="col-md-4">
<div class="form-group">
@Html.LabelFor(model => model.TournamentName, htmlAttributes: new { @class = "control-label" })
<div class="">
@Html.EditorFor(model => model.TournamentName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TournamentName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EntryFee, htmlAttributes: new { @class = "control-label" })
<div class="">
@Html.EditorFor(model => model.EntryFee, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EntryFee, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="">
<input type="submit" value="Create" class="btn btn-dark" />
</div>
</div>
</div>
<div class="col-md-4">
@Html.LabelFor(model => model.EnteredTeams, htmlAttributes: new { @class = "control-label" })
<div class="">
@foreach (var item in Model.EnteredTeams)
{
<div class="checkbox">
<label>
<input type="checkbox" name="SelectedEnteredTeams" value="@item.Value" /> @item.Text
</label>
</div>
}
</div>
</div>
<div class="col-md-4">
@Html.LabelFor(model => model.Prizes, htmlAttributes: new { @class = "control-label" })
<div class="">
@foreach (var item in Model.Prizes)
{
<div class="checkbox">
<label>
<input type="checkbox" name="SelectedPrizes" value="@item.Value" /> @item.Text
</label>
</div>
}
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

View File

@ -13,6 +13,7 @@
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net472" /> <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net472" />
<package id="Modernizr" version="2.8.3" targetFramework="net472" /> <package id="Modernizr" version="2.8.3" targetFramework="net472" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" /> <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
<package id="ObjectDumper.NET" version="2.5.20033.1" targetFramework="net472" />
<package id="popper.js" version="1.16.0" targetFramework="net472" /> <package id="popper.js" version="1.16.0" targetFramework="net472" />
<package id="WebGrease" version="1.6.0" targetFramework="net472" /> <package id="WebGrease" version="1.6.0" targetFramework="net472" />
</packages> </packages>

View File

@ -46,6 +46,9 @@
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="ObjectDumping, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ObjectDumper.NET.2.5.20033.1\lib\net45\ObjectDumping.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" /> <Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />

View File

@ -5,6 +5,7 @@
<package id="Microsoft.IdentityModel.Logging" version="1.1.2" targetFramework="net472" /> <package id="Microsoft.IdentityModel.Logging" version="1.1.2" targetFramework="net472" />
<package id="Microsoft.IdentityModel.Tokens" version="5.1.2" targetFramework="net472" /> <package id="Microsoft.IdentityModel.Tokens" version="5.1.2" targetFramework="net472" />
<package id="Newtonsoft.Json" version="10.0.1" targetFramework="net472" /> <package id="Newtonsoft.Json" version="10.0.1" targetFramework="net472" />
<package id="ObjectDumper.NET" version="2.5.20033.1" targetFramework="net472" />
<package id="System.IdentityModel.Tokens.Jwt" version="5.1.2" targetFramework="net472" /> <package id="System.IdentityModel.Tokens.Jwt" version="5.1.2" targetFramework="net472" />
<package id="Twilio" version="5.39.1" targetFramework="net472" /> <package id="Twilio" version="5.39.1" targetFramework="net472" />
</packages> </packages>

View File

@ -33,6 +33,9 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ObjectDumping, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ObjectDumper.NET.2.5.20033.1\lib\net45\ObjectDumping.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
@ -104,6 +107,7 @@
<EmbeddedResource Include="TournamentViewerForm.resx"> <EmbeddedResource Include="TournamentViewerForm.resx">
<DependentUpon>TournamentViewerForm.cs</DependentUpon> <DependentUpon>TournamentViewerForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ObjectDumper.NET" version="2.5.20033.1" targetFramework="net472" />
</packages>