MVC-kopplingen till tournament tracker är klar
This commit is contained in:
1759
MVCUI/Content/bootstrap.css
vendored
1759
MVCUI/Content/bootstrap.css
vendored
File diff suppressed because it is too large
Load Diff
2
MVCUI/Content/bootstrap.min.css
vendored
2
MVCUI/Content/bootstrap.min.css
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,7 @@
|
||||
using MVCUI.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
@ -18,9 +19,153 @@ namespace MVCUI.Controllers
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken()]
|
||||
public ActionResult EditTournamentMatchup(MatchupMVCModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
List<TournamentModel> tournaments = GlobalConfig.Connection.GetTournament_All();
|
||||
TournamentModel t = tournaments.Where(x => x.Id == model.TournamentId).First();
|
||||
|
||||
MatchupModel foundMatchup = new MatchupModel();
|
||||
foreach (var round in t.Rounds)
|
||||
{
|
||||
foreach (var matchup in round)
|
||||
{
|
||||
if (matchup.Id == model.MatchupId)
|
||||
{
|
||||
foundMatchup = matchup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < foundMatchup.Entries.Count; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
foundMatchup.Entries[i].Score = model.FirstTeamScore;
|
||||
}
|
||||
else if (i == 1)
|
||||
{
|
||||
foundMatchup.Entries[i].Score = model.SecondTeamScore;
|
||||
}
|
||||
}
|
||||
|
||||
TournamentLogic.UpdateTournamentResults(t);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return RedirectToAction("Details", "Tournaments", new { id = model.TournamentId, roundId = model.RoundNumber });
|
||||
|
||||
}
|
||||
|
||||
public ActionResult Details(int id, int roundId = 0)
|
||||
{
|
||||
List<TournamentModel> tournaments = GlobalConfig.Connection.GetTournament_All();
|
||||
try
|
||||
{
|
||||
TournamentMVCDetailsModel input = new TournamentMVCDetailsModel();
|
||||
TournamentModel t = tournaments.Where(x => x.Id == id).First();
|
||||
input.TournamentName = t.TournamentName;
|
||||
|
||||
var orderedRounds = t.Rounds.OrderBy(x => x.First().MatchupRound).ToList();
|
||||
bool activeFound = false;
|
||||
|
||||
for (int i = 0; i < orderedRounds.Count; i++)
|
||||
{
|
||||
RoundStatus status = RoundStatus.Locked;
|
||||
|
||||
if (!activeFound)
|
||||
{
|
||||
if (orderedRounds[i].TrueForAll(x => x.Winner != null))
|
||||
{
|
||||
status = RoundStatus.Complete;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = RoundStatus.Active;
|
||||
activeFound = true;
|
||||
if (roundId == 0)
|
||||
{
|
||||
roundId = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
input.Rounds.Add(new RoundMVCModel { RoundName = $"Round {i + 1}", Status = status, RoundNumber = i + 1 });
|
||||
}
|
||||
|
||||
input.Matchups = GetMatchups(orderedRounds[roundId - 1], id, roundId);
|
||||
|
||||
return View(input);
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
}
|
||||
|
||||
private List<MatchupMVCModel> GetMatchups(List<MatchupModel> input, int tournamentId, int roundId = 0)
|
||||
{
|
||||
List<MatchupMVCModel> output = new List<MatchupMVCModel>();
|
||||
|
||||
foreach (var item in input)
|
||||
{
|
||||
int teamTwoId = 0;
|
||||
string teamOneName = "";
|
||||
string teamTwoName = "Bye";
|
||||
double teamTwoScore = 0;
|
||||
|
||||
if (item.Entries.Count == null)
|
||||
{
|
||||
teamOneName = "To Be Determined";
|
||||
}
|
||||
else
|
||||
{
|
||||
teamOneName = item.Entries[0].TeamCompeting.TeamName;
|
||||
}
|
||||
|
||||
if (item.Entries.Count > 1)
|
||||
{
|
||||
teamTwoId = item.Entries[1].Id;
|
||||
if (item.Entries[1].TeamCompeting == null)
|
||||
{
|
||||
teamTwoName = "To Be Determined";
|
||||
}
|
||||
else
|
||||
{
|
||||
teamTwoName = item.Entries[1].TeamCompeting.TeamName;
|
||||
}
|
||||
teamTwoScore = item.Entries[1].Score;
|
||||
}
|
||||
|
||||
output.Add(new MatchupMVCModel
|
||||
{
|
||||
MatchupId = item.Id,
|
||||
TournamentId = tournamentId,
|
||||
RoundNumber = roundId,
|
||||
FirstTeamMatchupEntryId = item.Entries[0].Id,
|
||||
FirstTeamName = teamOneName,
|
||||
FirstTeamScore = item.Entries[0].Score,
|
||||
SecondTeamMatchupEntryId = teamTwoId,
|
||||
SecondTeamName = teamTwoName,
|
||||
SecondTeamScore = teamTwoScore
|
||||
});
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public ActionResult Create()
|
||||
{
|
||||
TournamentMVCModel input = new TournamentMVCModel();
|
||||
TournamentMVCCreateModel input = new TournamentMVCCreateModel();
|
||||
List<TeamModel> allTeams = GlobalConfig.Connection.GetTeam_All();
|
||||
List<PrizeModel> allPrizes = GlobalConfig.Connection.GetPrizes_All();
|
||||
|
||||
@ -33,17 +178,22 @@ namespace MVCUI.Controllers
|
||||
// POST: Tournament/Create
|
||||
[ValidateAntiForgeryToken()]
|
||||
[HttpPost]
|
||||
public ActionResult Create(TournamentMVCModel model)
|
||||
public ActionResult Create(TournamentMVCCreateModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ModelState.IsValid && model.SelectedEnteredTeams.Count > 0)
|
||||
{
|
||||
List<PrizeModel> allPrizes = GlobalConfig.Connection.GetPrizes_All();
|
||||
List<TeamModel> allTeams = GlobalConfig.Connection.GetTeam_All();
|
||||
|
||||
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();
|
||||
t.EnteredTeams = model.SelectedEnteredTeams.Select(x => allTeams.Where(y => y.Id == int.Parse(x)).First()).ToList();
|
||||
t.Prizes = model.SelectedPrizes.Select(x => allPrizes.Where(y => y.Id == int.Parse(x)).First()).ToList();
|
||||
//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);
|
||||
|
||||
@ -51,14 +201,14 @@ namespace MVCUI.Controllers
|
||||
|
||||
t.AlertUsersToNewRound();
|
||||
|
||||
return RedirectToAction("Index","Home");
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction("Create");
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
var fel = ex;
|
||||
|
||||
14
MVCUI/Helpers/Enums.cs
Normal file
14
MVCUI/Helpers/Enums.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace MVCUI
|
||||
{
|
||||
public enum RoundStatus
|
||||
{
|
||||
Active,
|
||||
Locked,
|
||||
Complete
|
||||
}
|
||||
}
|
||||
@ -133,8 +133,12 @@
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Helpers\Enums.cs" />
|
||||
<Compile Include="Models\MatchupMVCModel.cs" />
|
||||
<Compile Include="Models\RoundMVCModel.cs" />
|
||||
<Compile Include="Models\TeamMVCModel.cs" />
|
||||
<Compile Include="Models\TournamentMVCModel.cs" />
|
||||
<Compile Include="Models\TournamentMVCCreateModel.cs" />
|
||||
<Compile Include="Models\TournamentMVCDetailsModel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -279,6 +283,8 @@
|
||||
<Content Include="Views\Prizes\Index.cshtml" />
|
||||
<Content Include="Views\Prizes\Create.cshtml" />
|
||||
<Content Include="Views\Tournaments\Create.cshtml" />
|
||||
<Content Include="Views\Tournaments\Details.cshtml" />
|
||||
<Content Include="Views\Shared\_EditMatchup.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
|
||||
20
MVCUI/Models/MatchupMVCModel.cs
Normal file
20
MVCUI/Models/MatchupMVCModel.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace MVCUI.Models
|
||||
{
|
||||
public class MatchupMVCModel
|
||||
{
|
||||
public int MatchupId { get; set; }
|
||||
public int TournamentId { get; set; }
|
||||
public int RoundNumber { get; set; }
|
||||
public int FirstTeamMatchupEntryId { get; set; }
|
||||
public string FirstTeamName { get; set; }
|
||||
public double FirstTeamScore { get; set; }
|
||||
public int SecondTeamMatchupEntryId { get; set; }
|
||||
public string SecondTeamName { get; set; }
|
||||
public double SecondTeamScore { get; set; }
|
||||
}
|
||||
}
|
||||
14
MVCUI/Models/RoundMVCModel.cs
Normal file
14
MVCUI/Models/RoundMVCModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace MVCUI.Models
|
||||
{
|
||||
public class RoundMVCModel
|
||||
{
|
||||
public int RoundNumber { get; set; }
|
||||
public string RoundName { get; set; }
|
||||
public RoundStatus Status { get; set; }
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,7 @@ using TrackerLibrary.Models;
|
||||
|
||||
namespace MVCUI.Models
|
||||
{
|
||||
public class TournamentMVCModel
|
||||
public class TournamentMVCCreateModel
|
||||
{
|
||||
[Display(Name = "Tournament Name")]
|
||||
[StringLength(100, MinimumLength = 2)]
|
||||
20
MVCUI/Models/TournamentMVCDetailsModel.cs
Normal file
20
MVCUI/Models/TournamentMVCDetailsModel.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace MVCUI.Models
|
||||
{
|
||||
public class TournamentMVCDetailsModel
|
||||
{
|
||||
[Display(Name = "Tournament Name")]
|
||||
public string TournamentName { get; set; }
|
||||
|
||||
public List<RoundMVCModel> Rounds { get; set; } = new List<RoundMVCModel>();
|
||||
|
||||
//List of matchups
|
||||
public List<MatchupMVCModel> Matchups { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@ -31,7 +31,7 @@
|
||||
<ul class="list-unstyled tourney-display">
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<li><a href="/">@item.TournamentName</a></li>
|
||||
<li>@Html.ActionLink(item.TournamentName,"Details","Tournaments",new { id=item.Id },new { })</li>
|
||||
}
|
||||
|
||||
</ul>
|
||||
|
||||
38
MVCUI/Views/Shared/_EditMatchup.cshtml
Normal file
38
MVCUI/Views/Shared/_EditMatchup.cshtml
Normal file
@ -0,0 +1,38 @@
|
||||
@model MVCUI.Models.MatchupMVCModel
|
||||
|
||||
@using (Html.BeginForm("EditTournamentMatchup", "Tournaments"))
|
||||
{
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
@Html.HiddenFor(model => model.MatchupId)
|
||||
@Html.HiddenFor(model => model.FirstTeamMatchupEntryId)
|
||||
@Html.HiddenFor(model => model.SecondTeamMatchupEntryId)
|
||||
@Html.HiddenFor(model => model.TournamentId)
|
||||
@Html.HiddenFor(model => model.RoundNumber)
|
||||
|
||||
<div class="form-horizontal">
|
||||
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
|
||||
<div class="form-group">
|
||||
<label class="control-label">@Model.FirstTeamName</label>
|
||||
<div class="">
|
||||
@Html.EditorFor(model => model.FirstTeamScore, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.FirstTeamScore, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label">@Model.SecondTeamName</label>
|
||||
<div class="">
|
||||
@Html.EditorFor(model => model.SecondTeamScore, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.SecondTeamScore, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<input type="submit" value="Score Match" class="btn btn-default" />
|
||||
</div>
|
||||
</div>
|
||||
<hr class="alert-danger" />
|
||||
</div>
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
@model MVCUI.Models.TournamentMVCModel
|
||||
@model MVCUI.Models.TournamentMVCCreateModel
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Create";
|
||||
|
||||
52
MVCUI/Views/Tournaments/Details.cshtml
Normal file
52
MVCUI/Views/Tournaments/Details.cshtml
Normal file
@ -0,0 +1,52 @@
|
||||
@model MVCUI.Models.TournamentMVCDetailsModel
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Details";
|
||||
}
|
||||
|
||||
<h2>Tournament: @Html.DisplayFor(model => model.TournamentName)</h2>
|
||||
|
||||
<div>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<h2>@Html.DisplayNameFor(model => model.Rounds)</h2>
|
||||
<ul class="list-unstyled tourney-display">
|
||||
@foreach (var item in Model.Rounds)
|
||||
{
|
||||
<li>
|
||||
@Html.ActionLink(item.RoundName, "Details", "Tournaments", new { roundId = item.RoundNumber }, new { })
|
||||
|
||||
@if (item.Status == RoundStatus.Complete)
|
||||
{
|
||||
<span class="label label-default">completed</span>
|
||||
}
|
||||
else if (item.Status == RoundStatus.Active)
|
||||
{
|
||||
<span class="label label-success">active</span>
|
||||
}
|
||||
else if (item.Status == RoundStatus.Locked)
|
||||
{
|
||||
<span class="label label-danger">locked</span>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<div class="row">
|
||||
@foreach (var item in Model.Matchups)
|
||||
{
|
||||
<div class="col-md-6">
|
||||
@Html.Partial("_EditMatchup", item)
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
|
||||
@Html.ActionLink("Back to List", "Index")
|
||||
</p>
|
||||
@ -7,7 +7,9 @@
|
||||
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
|
||||
<appSettings>
|
||||
<add key="webpages:Enabled" value="false" />
|
||||
</appSettings>
|
||||
<system.web.webPages.razor>
|
||||
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
|
||||
<pages pageBaseType="System.Web.Mvc.WebViewPage">
|
||||
@ -22,9 +24,7 @@
|
||||
</pages>
|
||||
</system.web.webPages.razor>
|
||||
|
||||
<appSettings>
|
||||
<add key="webpages:Enabled" value="false" />
|
||||
</appSettings>
|
||||
|
||||
|
||||
<system.webServer>
|
||||
<handlers>
|
||||
|
||||
@ -9,12 +9,27 @@
|
||||
<add key="webpages:Enabled" value="false" />
|
||||
<add key="ClientValidationEnabled" value="true" />
|
||||
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
|
||||
<add key="filePath" value="D:\data\TournamentTracker" />
|
||||
<!--<add key="filePath" value="C:\AppData\TournamentTracker"/>-->
|
||||
<add key="greaterWins" value="1" />
|
||||
<add key="senderEmail" value="tommy@oeman.se" />
|
||||
<add key="senderDisplayName" value="Tommy Öman" />
|
||||
<add key="smsAccountSid" value="AC722d9a6f2c7812a1eb4e091426ca5581" />
|
||||
<add key="smsAuthToken" value="8383d2239d043690984c7b80a8b0a704" />
|
||||
<add key="smsFromPhoneNumber" value="+12058462699" />
|
||||
</appSettings>
|
||||
<connectionStrings>
|
||||
<!--<add name="Tournaments" connectionString="Server=TOMMYASUS\SQLEXPR2017;Database=Tournaments;Trusted_Connection=True;" providerName="System.Data.SqlClient"/>-->
|
||||
<add name="Tournaments" connectionString="Server=.\SQLEXPR2017;Database=Tournaments;Trusted_Connection=True;" providerName="System.Data.SqlClient" />
|
||||
<!--Data Source=TOMMYASUS\SQLEXPR2017;Initial Catalog=Tournaments;Integrated Security=True-->
|
||||
</connectionStrings>
|
||||
<system.net>
|
||||
<mailSettings>
|
||||
<smtp deliveryMethod="Network">
|
||||
<network host="127.0.0.1" userName="tfoman" password="testing" port="25" enableSsl="false" />
|
||||
</smtp>
|
||||
</mailSettings>
|
||||
</system.net>
|
||||
<system.web>
|
||||
<compilation debug="true" targetFramework="4.7.2" />
|
||||
<httpRuntime targetFramework="4.7.2" />
|
||||
|
||||
@ -35,7 +35,7 @@ namespace TrackerLibrary
|
||||
{
|
||||
foreach (MatchupModel rm in round)
|
||||
{
|
||||
if (rm.Winner == null && (rm.Entries.Any(x => x.Score != 0) || rm.Entries.Count == 1))
|
||||
if ((rm.Entries.Any(x => x.Score != 0) || rm.Entries.Count == 1))
|
||||
{
|
||||
toScore.Add(rm);
|
||||
}
|
||||
@ -108,7 +108,20 @@ namespace TrackerLibrary
|
||||
|
||||
if (p.CellPhoneNumber.Length > 0)
|
||||
{
|
||||
SMSLogic.SendSMSMessage(p.CellPhoneNumber, $"You have a new matchup with {competitor.TeamCompeting.TeamName}");
|
||||
try
|
||||
{
|
||||
if (competitor != null)
|
||||
{
|
||||
SMSLogic.SendSMSMessage(p.CellPhoneNumber, $"You have a new matchup with {competitor.TeamCompeting.TeamName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
SMSLogic.SendSMSMessage(p.CellPhoneNumber, $"You have a bye week for your first round.");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user