Teams creation and prizes creation are implemented

This commit is contained in:
2020-05-05 23:25:28 +02:00
parent fc49f33575
commit 9596d9aa47
15 changed files with 387 additions and 4 deletions

View File

@ -25,6 +25,7 @@ namespace MVCUI.Controllers
} }
// POST: People/Create // POST: People/Create
[ValidateAntiForgeryToken()]
[HttpPost] [HttpPost]
public ActionResult Create(PersonModel p) public ActionResult Create(PersonModel p)
{ {

View File

@ -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<PrizeModel> 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();
}
}
}
}

View File

@ -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<TeamModel> allTeams = GlobalConfig.Connection.GetTeam_All();
return View(allTeams);
}
// GET: Teams/Create
public ActionResult Create()
{
List<PersonModel> 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();
}
}
}
}

View File

@ -124,9 +124,12 @@
<Compile Include="App_Start\RouteConfig.cs" /> <Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Controllers\HomeController.cs" /> <Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\PeopleController.cs" /> <Compile Include="Controllers\PeopleController.cs" />
<Compile Include="Controllers\PrizesController.cs" />
<Compile Include="Controllers\TeamsController.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="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -266,10 +269,13 @@
<Content Include="Scripts\popper-utils.js.map" /> <Content Include="Scripts\popper-utils.js.map" />
<Content Include="Views\People\Index.cshtml" /> <Content Include="Views\People\Index.cshtml" />
<Content Include="Views\People\Create.cshtml" /> <Content Include="Views\People\Create.cshtml" />
<Content Include="Views\Teams\Index.cshtml" />
<Content Include="Views\Teams\Create.cshtml" />
<Content Include="Views\Prizes\Index.cshtml" />
<Content Include="Views\Prizes\Create.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />
<Folder Include="Models\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />

View File

@ -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<SelectListItem> TeamMembers { get; set; } = new List<SelectListItem>();
public List<string> SelectedTeamMembers { get; set; } = new List<string>();
}
}

View File

@ -0,0 +1,63 @@
@model TrackerLibrary.Models.PrizeModel
@{
ViewBag.Title = "Create";
}
<h2>Create A New Prize</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.PlaceNumber, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PlaceNumber, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PlaceNumber, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.PlaceName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PlaceName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PlaceName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.PrizeAmount, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PrizeAmount, new { htmlAttributes = new { @class = "form-control", @value = 0 } })
@Html.ValidationMessageFor(model => model.PrizeAmount, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.PrizePercentage, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PrizePercentage, new { htmlAttributes = new { @class = "form-control", @value = 0 } })
@Html.ValidationMessageFor(model => model.PrizePercentage, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

View File

@ -0,0 +1,46 @@
@model IEnumerable<TrackerLibrary.Models.PrizeModel>
@{
ViewBag.Title = "Index";
}
<h2>View All Prizes</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.PlaceNumber)
</th>
<th>
@Html.DisplayNameFor(model => model.PlaceName)
</th>
<th>
@Html.DisplayNameFor(model => model.PrizeAmount)
</th>
<th>
@Html.DisplayNameFor(model => model.PrizePercentage)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.PlaceNumber)
</td>
<td>
@Html.DisplayFor(modelItem => item.PlaceName)
</td>
<td>
@Html.DisplayFor(modelItem => item.PrizeAmount)
</td>
<td>
@Html.DisplayFor(modelItem => item.PrizePercentage)
</td>
</tr>
}
</table>

View File

@ -27,6 +27,12 @@
<li class="nav-item"> <li class="nav-item">
@Html.ActionLink("People", "Index", "People", new { area = "" }, new { @class = "nav-link text-light" }) @Html.ActionLink("People", "Index", "People", new { area = "" }, new { @class = "nav-link text-light" })
</li> </li>
<li class="nav-item">
@Html.ActionLink("Teams", "Index", "Teams", new { area = "" }, new { @class = "nav-link text-light" })
</li>
<li class="nav-item">
@Html.ActionLink("Prizes", "Index", "Prizes", new { area = "" }, new { @class = "nav-link text-light" })
</li>
@*<li class="nav-item"> @*<li class="nav-item">
@Html.ActionLink("About", "About", "Home", new { area = "" }, new { @class = "nav-link text-light" }) @Html.ActionLink("About", "About", "Home", new { area = "" }, new { @class = "nav-link text-light" })
</li> </li>

View File

@ -0,0 +1,52 @@
@model MVCUI.Models.TeamMVCModel
@{
ViewBag.Title = "Create";
}
<h2>Create New Team</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>TeamModel</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.TeamName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TeamName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TeamName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TeamMembers,htmlAttributes:new { @class = "control-label col-md-2"})
<div class="col-md-10">
@foreach (var item in Model.TeamMembers)
{
<div class="checkbox">
<label>
<input type="checkbox" name="SelectedTeamMembers" value="@item.Value" /> @item.Text
</label>
</div>
}
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

View File

@ -0,0 +1,43 @@
@model IEnumerable<TrackerLibrary.Models.TeamModel>
@{
ViewBag.Title = "Index";
}
<h2>All Teams</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.TeamName)
</th>
<th>
@Html.DisplayNameFor(model => model.TeamMembers)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.TeamName)
</td>
<td>
@for (int i = 0; i < item.TeamMembers.Count; i++)
{
if (i == 0)
{
@(item.TeamMembers[i].FullName);
}
else
{
@(", " + item.TeamMembers[i].FullName);
}
}
</td>
</tr>
}
</table>

View File

@ -15,6 +15,7 @@ namespace TrackerLibrary.DataAccess
void CompleteTournament(TournamentModel model); void CompleteTournament(TournamentModel model);
List<TeamModel> GetTeam_All(); List<TeamModel> GetTeam_All();
List<PersonModel> GetPerson_All(); List<PersonModel> GetPerson_All();
List<PrizeModel> GetPrizes_All();
List<TournamentModel> GetTournament_All(); List<TournamentModel> GetTournament_All();
} }
} }

View File

@ -225,6 +225,16 @@ namespace TrackerLibrary.DataAccess
return output; return output;
} }
public List<PrizeModel> GetPrizes_All()
{
List<PrizeModel> output;
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
{
output = connection.Query<PrizeModel>("dbo.spPrizes_GetAll").ToList();
}
return output;
}
public List<TournamentModel> GetTournament_All() public List<TournamentModel> GetTournament_All()
{ {
List<TournamentModel> output; List<TournamentModel> output;

View File

@ -122,6 +122,13 @@ namespace TrackerLibrary.DataAccess
.ConvertToTournamentModels(); .ConvertToTournamentModels();
} }
public List<PrizeModel> GetPrizes_All()
{
List<PrizeModel> output;
output = GlobalConfig.PrizesFile.FullFilePath().LoadFile().ConvertToPrizeModels();
return output;
}
public void UpdateMatchup(MatchupModel model) public void UpdateMatchup(MatchupModel model)
{ {
model.UpdateMatchupToFile(); model.UpdateMatchupToFile();

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text; using System.Text;
namespace TrackerLibrary.Models namespace TrackerLibrary.Models
@ -7,13 +8,26 @@ namespace TrackerLibrary.Models
public class PrizeModel public class PrizeModel
{ {
/// <summary> /// <summary>
/// The unique identifier for the prize /// The unique identifier for the prize
/// </summary> /// </summary>
public int Id { get; set; } public int Id { get; set; }
[Display(Name = "Place Number")]
[Range(1, 100)]
[Required]
public int PlaceNumber { get; set; } public int PlaceNumber { get; set; }
[Display(Name = "Place Name")]
[StringLength(100, MinimumLength = 3)]
[Required]
public string PlaceName { get; set; } public string PlaceName { get; set; }
[Display(Name = "Prize Amount")]
[DataType(DataType.Currency)]
public decimal PrizeAmount { get; set; } public decimal PrizeAmount { get; set; }
[Display(Name = "Prize Percentage")]
public double PrizePercentage { get; set; } public double PrizePercentage { get; set; }
public PrizeModel() public PrizeModel()

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text; using System.Text;
namespace TrackerLibrary.Models namespace TrackerLibrary.Models
@ -7,7 +8,11 @@ namespace TrackerLibrary.Models
public class TeamModel public class TeamModel
{ {
public int Id { get; set; } public int Id { get; set; }
[Display(Name = "Team Member List")]
public List<PersonModel> TeamMembers { get; set; } = new List<PersonModel>(); public List<PersonModel> TeamMembers { get; set; } = new List<PersonModel>();
[Display(Name = "Team Name")]
//[StringLength(100, MinimumLength = 2)]
//[Required]
public string TeamName { get; set; } public string TeamName { get; set; }
} }
} }