public ActionResult Edit(ClanWarUpsertViewModel clanWar) { ActionResult result = View(); try { ClanUser clanUser = HttpContext.GetCurrentLoginInformation(); int clanWarId = ClanWarManager.Upsert(clanWar, clanUser.id); if (clanWarId > 0) { //Insert member picks //vv List<WarRanking> rankings = new List<WarRanking>(); List <ClanWarPickViewModel> picks = new List <ClanWarPickViewModel>(); List <ClanUser> clanMembers = ClanUserManager.SelectAllByClanId(clanWar.ClanId); short i = 1; foreach (ClanUser member in clanMembers) { WarRanking ranking = new WarRanking() { clanUserId = member.id, clanWarId = clanWarId }; //vv rankings.Add(ranking); ClanWarPickViewModel pick = new ClanWarPickViewModel() { ClanUserId = member.id, ClanMemberWarPosition = i, ClanWarId = clanWarId, PickVS = i }; picks.Add(pick); i++; } //vv RankingsManager.Upsert(rankings); ClanWarPicksManager.Upsert(picks); } //TODO //vv an Else here should display a message stating that the war was not inserted (and no exception apparently) result = RedirectToAction("Index"); } catch { result = View(clanWar); } return(result); }
public ActionResult AddAttack(int id, int warId) { ClanMemberStatsViewModel addSingle = new ClanMemberStatsViewModel() { ClanWarId = warId }; List <ClanUser> clanUsers = ClanUserManager.SelectAllByClanId(id); ViewBag.AvailableAttacks = RankingsManager.SelectAttacksAvailableForWar(warId).ToDictionary(key => key.clanUserId, value => clanUsers.Where(p => p.id == value.clanUserId).Select(p => p.name).Single()); return(PartialView("_ClanMemberStatsViewModel", addSingle)); }
public RankingsUpsertViewModel(int warId, int clanId, bool isOverall) { _clanMemberStats = new List <ClanMemberStatsViewModel>(); List <WarRanking> warRankings = new List <WarRanking>(); if (isOverall) { warRankings = RankingsManager.SelectRankingsByClanId(clanId); if (warRankings.Any() && warRankings.Count > 0) { var rankingTotals = warRankings.GroupBy(g => g.clanUserId).Select(p => new ClanMemberStatsViewModel { ClanUserId = p.Key, ClanId = clanId, TotalAttacks = (short)p.Count(), AttacksWon = (short)p.Count(r => r.attackWin), TotalHeroicDefense = (short)p.Sum(r => Convert.ToInt16(r.heroicDefense)), TotalHeroicAttack = (short)p.Sum(r => Convert.ToInt16(r.heroicAttack)), AttacksDefended = (short)p.Sum(r => r.attacksDefended), AttacksOn = (short)p.Sum(r => r.attacksOn), Stars = (short)p.Sum(r => r.stars), Xp = (short)p.Sum(r => r.xp) }); _clanMemberStats = rankingTotals.ToList(); foreach (ClanMemberStatsViewModel memberStats in _clanMemberStats) { short wars = 0; wars = (short)warRankings.Where(p => p.clanUserId == memberStats.ClanUserId).Select(p => p.clanWarId).Distinct().Count(); memberStats.WarsCount = wars; } int attacksCount = warRankings.Count(); _clanWarStats = _clanMemberStats.GroupBy(g => g.ClanId).Select(p => new ClanMemberStatsViewModel { ClanId = p.Key, ClanWarId = 0, WarsCount = (short)p.Count(), TotalAttacks = (short)attacksCount, AttacksWon = (short)p.Sum(r => r.AttacksWon), TotalHeroicDefense = (short)p.Sum(r => Convert.ToInt16(r.TotalHeroicDefense)), TotalHeroicAttack = (short)p.Sum(r => Convert.ToInt16(r.TotalHeroicAttack)), AttacksDefended = (short)p.Sum(r => r.AttacksDefended), AttacksOn = (short)p.Sum(r => r.AttacksOn), Stars = (short)p.Sum(r => r.Stars), Xp = (short)p.Sum(r => r.Xp) }).Single(); } } else { warRankings = RankingsManager.SelectRankingsByClanWarId(warId); foreach (WarRanking ranking in warRankings) { _clanMemberStats.Add(ClanMemberStatsViewModel.ConvertToClanMemberStats(ranking)); } if (warRankings.Any() && warRankings.Count > 0) { _clanWarStats = _clanMemberStats.GroupBy(g => g.ClanWarId).Select(p => new ClanMemberStatsViewModel { ClanId = clanId, ClanWarId = p.Key, WarsCount = 1, AttacksWon = (short)p.Sum(r => r.AttacksWon), TotalAttacks = (short)p.Count(), TotalHeroicDefense = (short)p.Sum(r => Convert.ToInt16(r.TotalHeroicDefense)), TotalHeroicAttack = (short)p.Sum(r => Convert.ToInt16(r.TotalHeroicAttack)), AttacksDefended = (short)p.Sum(r => r.AttacksDefended), AttacksOn = (short)p.Sum(r => r.AttacksOn), Stars = (short)p.Sum(r => r.Stars), Xp = (short)p.Sum(r => r.Xp) }).Single(); } List <ClanUser> clanUsers = ClanUserManager.SelectAllByClanId(clanId); List <Models.ClanWarPick> availableAttacks = RankingsManager.SelectAttacksAvailableForWar(warId); _availableAttacks = availableAttacks.ToDictionary(key => key.clanUserId, value => clanUsers.Where(p => p.id == value.clanUserId).Select(p => p.name).Single()); } }