public ActionResult EditPlayer(int managerId, int[] playerIds, int[] playerSubs) { if (playerSubs == null) { playerSubs = new int[0]; } var manager = db.Managers.Include(x => x.Players).Where(x => x.ManagerId == managerId).FirstOrDefault(); if (manager != null) { var selectedPlayers = new HashSet <int>(playerIds.Where(x => x != 0)); var currentPlayers = new HashSet <int>(manager.Players.Select(x => x.PlayerId)); foreach (var currentPlayer in currentPlayers) { if (!selectedPlayers.Contains(currentPlayer)) { db.ManagerPlayers.Remove(manager.Players.Where(x => x.PlayerId == currentPlayer).FirstOrDefault()); } } foreach (var selectedPlayer in selectedPlayers) { if (!currentPlayers.Contains(selectedPlayer)) { ManagerPlayer managerPlayer = new ManagerPlayer(selectedPlayer, managerId); db.ManagerPlayers.Add(managerPlayer); } } var selectedSubs = new HashSet <int>(playerSubs.Where(x => x != 0)); var currentSubs = new HashSet <int>(manager.Players.Where(x => x.Substitute).Select(x => x.PlayerId)); foreach (var currentSub in currentSubs) { if (!selectedSubs.Contains(currentSub)) { ManagerPlayer managerPlayer = manager.Players.Where(x => x.PlayerId == currentSub).FirstOrDefault(); managerPlayer.ToggleSubstitute(); } } foreach (var selectedSub in selectedSubs) { if (!currentSubs.Contains(selectedSub)) { ManagerPlayer managerPlayer = manager.Players.Where(x => x.PlayerId == selectedSub).FirstOrDefault(); managerPlayer.ToggleSubstitute(); } } } db.SaveChanges(); return(Content("Ok")); }
public ActionResult Upload(HttpPostedFileBase file, int managerId) { if (file != null) { var image = new byte[file.ContentLength]; file.InputStream.Read(image, 0, image.Length); Manager manager = db.Managers.Find(managerId); manager.SetImage(image); db.SaveChanges(); } return(RedirectToAction("Details", "Manager", new { id = managerId })); }
public ActionResult Send(int gameWeekId) { emailService.Send(gameWeekSerializer.DeSerialize(gameWeekId, "GameWeek"), ControllerContext); auditService.Log("Email", "Game Week Email Sent", User.Identity.Name, "Game Week Email Sent", gameWeekId); db.SaveChanges(); return Content("Ok"); }
public void Update(TeamSheet teamSheet) { foreach (var team in teamSheet.Teams) { var managerId = db.Managers.Where(x => x.Alias == team.Manager).Select(x => x.ManagerId).FirstOrDefault(); if (managerId != 0) { db.ManagerGoalKeepers.RemoveRange(db.ManagerGoalKeepers.Where(x => x.ManagerId == managerId)); db.ManagerPlayers.RemoveRange(db.ManagerPlayers.Where(x => x.ManagerId == managerId)); MapTeams(team, managerId); MapPlayers(team, managerId); } } db.SaveChanges(); }
public string Upload(HttpPostedFileBase file) { string filePath = Path.Combine(path, string.Format("PlayersList_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss"))); file.SaveAs(filePath); DeleteCurrent(); Load(playerListReader.Read(filePath)); File.Delete(filePath); if (unmatched.Count == 0) { db.SaveChanges(); return("Success"); } else { return(Unmatched()); } }
public ActionResult Clear() { var goals = db.Goals; foreach (var goal in goals) { db.Goals.Remove(goal); } db.Database.ExecuteSqlCommand("DBCC CHECKIDENT('Results.Goals', RESEED, 0)"); var conceded = db.Conceded; foreach (var concede in conceded) { db.Conceded.Remove(concede); } db.Database.ExecuteSqlCommand("DBCC CHECKIDENT('Results.Conceded', RESEED, 0)"); var managerPlayers = db.ManagerPlayers; foreach (var managerPlayer in managerPlayers) { db.ManagerPlayers.Remove(managerPlayer); } db.Database.ExecuteSqlCommand("DBCC CHECKIDENT('DreamLeague.ManagerPlayers', RESEED, 0)"); var managerGoalKeepers = db.ManagerGoalKeepers; foreach (var managerGoalKeeper in managerGoalKeepers) { db.ManagerGoalKeepers.Remove(managerGoalKeeper); } db.Database.ExecuteSqlCommand("DBCC CHECKIDENT('DreamLeague.ManagerGoalKeepers', RESEED, 0)"); var fixtures = db.Fixtures; foreach (var fixture in fixtures) { db.Fixtures.Remove(fixture); } db.Database.ExecuteSqlCommand("DBCC CHECKIDENT('Cup.Fixtures', RESEED, 0)"); var groups = db.Groups; foreach (var group in groups) { db.Groups.Remove(group); } db.Database.ExecuteSqlCommand("DBCC CHECKIDENT('Cup.Groups', RESEED, 0)"); var audits = db.Audit; foreach (var audit in audits) { db.Audit.Remove(audit); } db.Database.ExecuteSqlCommand("DBCC CHECKIDENT('DreamLeague.Audit', RESEED, 0)"); var gameWeeks = db.GameWeeks; foreach (var gameWeek in gameWeeks) { gameWeek.SetIncomplete(); } db.SaveChanges(); gameWeekSerializer.DeleteAll("GameWeek"); cupWeekSerializer.DeleteAll("CupWeek"); teamSheetService.DeleteAll(); return(Content("Ok")); }
public ActionResult Index(ResultsSheet resultsSheet) { var managerCupWeeks = gameWeekService.ManagerCupWeeks(resultsSheet.GameWeekId); var date = DateTime.UtcNow; foreach (var goalKeeper in resultsSheet.GoalKeepers) { bool substitute = false; if (goalKeeper.SubstitutePlayed) { substitute = true; } if (goalKeeper.Conceded > 0) { for (int i = 0; i < goalKeeper.Conceded; i++) { Concede concede = new Concede(goalKeeper.GoalKeeper.TeamId, resultsSheet.GameWeekId, goalKeeper.GoalKeeper.ManagerId, substitute); concede.Created = date; concede.CreatedBy = User.Identity.Name; db.Conceded.Add(concede); var team = db.Teams.Where(x => x.TeamId == concede.TeamId).FirstOrDefault(); auditService.Log("Concede", "Concede Added", User.Identity.Name, string.Format("Goal conceded for {0} ({1})", team?.Name, team?.ManagerGoalKeepers?.FirstOrDefault()?.Manager?.Name ?? "Unattached"), resultsSheet.GameWeekId); } } if (managerCupWeeks.Exists(x => x.ManagerId == goalKeeper.GoalKeeper.ManagerId)) { if (goalKeeper.CupConceded > 0) { for (int i = 0; i < goalKeeper.CupConceded; i++) { Concede concede = new Concede(goalKeeper.Substitute.TeamId, resultsSheet.GameWeekId, goalKeeper.Substitute.ManagerId, substitute, true); concede.Created = date; concede.CreatedBy = User.Identity.Name; db.Conceded.Add(concede); var team = db.Teams.Where(x => x.TeamId == concede.TeamId).FirstOrDefault(); auditService.Log("Concede", "Concede Added", User.Identity.Name, string.Format("Cup goal conceded for {0} ({1})", team?.Name, team?.ManagerGoalKeepers?.FirstOrDefault()?.Manager?.Name ?? "Unattached"), resultsSheet.GameWeekId); } } } } foreach (var player in resultsSheet.Players) { if (player.Goals > 0) { for (int i = 0; i < player.Goals; i++) { Goal goal = new Goal(player.Player.PlayerId, resultsSheet.GameWeekId, player.Player.ManagerId); goal.Created = date; goal.CreatedBy = User.Identity.Name; db.Goals.Add(goal); var playerT = db.Players.Where(x => x.PlayerId == goal.PlayerId).FirstOrDefault(); auditService.Log("Goal", "Goal Added", User.Identity.Name, string.Format("Goal scored for {0} ({1})", playerT?.FullName, playerT?.ManagerPlayers.FirstOrDefault()?.Manager?.Name ?? "Unattached"), resultsSheet.GameWeekId); } } if (managerCupWeeks.Exists(x => x.ManagerId == player.Player.ManagerId)) { if (player.CupGoals > 0) { for (int i = 0; i < player.CupGoals; i++) { Goal goal = new Goal(player.Player.PlayerId, resultsSheet.GameWeekId, player.Player.ManagerId, true); goal.Created = date; goal.CreatedBy = User.Identity.Name; db.Goals.Add(goal); var playerT = db.Players.Where(x => x.PlayerId == goal.PlayerId).FirstOrDefault(); auditService.Log("Goal", "Goal Added", User.Identity.Name, string.Format("Cup goal scored for {0} ({1})", playerT?.FullName, playerT?.ManagerPlayers.FirstOrDefault()?.Manager?.Name ?? "Unattached"), resultsSheet.GameWeekId); } } } } var gameWeek = db.GameWeeks.Find(resultsSheet.GameWeekId); gameWeek.SetComplete(); db.SaveChanges(); gameWeekSummaryService.Create(resultsSheet.GameWeekId); cupWeekSummaryService.Create(resultsSheet.GameWeekId); return(RedirectToAction("Index", "Result", new { gameWeekId = resultsSheet.GameWeekId })); }