Now it is possible to finnish a tournament with scores and mails

This commit is contained in:
2020-04-20 23:44:09 +02:00
parent 5d0d891024
commit ac1d5371f2
9 changed files with 144 additions and 7 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using TrackerLibrary.Models;
@ -77,7 +78,6 @@ namespace TrackerLibrary
return;
}
List<string> to = new List<string>();
string subject;
StringBuilder body = new StringBuilder();
@ -101,10 +101,10 @@ namespace TrackerLibrary
body.AppendLine("~Tournament Tracker");
}
to.Add(p.EmailAddress);
string to = p.EmailAddress;
EmailLogic.SendEmail( to, subject, body.ToString()); ;
EmailLogic.SendEmail(to, subject, body.ToString()); ;
}
private static int CheckCurrentRound(this TournamentModel model)
@ -116,7 +116,98 @@ namespace TrackerLibrary
{
output += 1;
}
else
{
return output;
}
}
// Tournament is complete
CpmpleteTournament(model);
return output - 1;
}
private static void CpmpleteTournament(TournamentModel model)
{
GlobalConfig.Connection.CompleteTournament(model);
TeamModel winners = model.Rounds.Last().First().Winner;
TeamModel runnerUp = model.Rounds.Last().First().Entries.Where(x => x.TeamCompeting != winners).First().TeamCompeting;
decimal winnerPrize = 0;
decimal runnerUpPrize = 0;
if (model.Prizes.Count > 0)
{
decimal totalIncome = model.EnteredTeams.Count * model.EntryFee;
PrizeModel firstPlacePrize = model.Prizes.Where(x => x.PlaceNumber == 1).FirstOrDefault();
PrizeModel secondPlacePrize = model.Prizes.Where(x => x.PlaceNumber == 2).FirstOrDefault();
if (firstPlacePrize != null)
{
winnerPrize = firstPlacePrize.CalculatePrizePayout(totalIncome);
}
if (secondPlacePrize != null)
{
runnerUpPrize = secondPlacePrize.CalculatePrizePayout(totalIncome);
}
}
// Send Email to all tournament
List<string> to = new List<string>();
string subject;
StringBuilder body = new StringBuilder();
subject = $"In {model.TournamentName}, {winners.TeamName} has won";
body.AppendLine("<h1>We have a WINNER!</h1>");
body.AppendLine("<p>Congratulations to our winner on a great tournament.</p>");
body.AppendLine("<br />");
if (winnerPrize > 0)
{
body.AppendLine($"<p>{winners.TeamName} will receive ${winnerPrize}</p>");
}
if (runnerUpPrize > 0)
{
body.AppendLine($"<p>{runnerUp.TeamName} will receive ${runnerUpPrize}</p>");
}
body.AppendLine("<p>Thanks for a great tournament everyone</p>");
body.AppendLine("~Tournament Tracker");
List<string> bcc = new List<string>();
foreach (TeamModel t in model.EnteredTeams)
{
foreach (PersonModel p in t.TeamMembers)
{
if (p.EmailAddress.Length > 0)
{
bcc.Add(p.EmailAddress);
}
}
}
EmailLogic.SendEmail(new List<string>(), bcc, subject, body.ToString());
model.CompleteTournament();
}
private static decimal CalculatePrizePayout(this PrizeModel prize, decimal totalIncome)
{
decimal output = 0;
if (prize.PrizeAmount > 0)
{
output = prize.PrizeAmount;
}
else
{
output = decimal.Multiply(totalIncome, Convert.ToDecimal(prize.PrizePercentage / 100));
}
return output;
}