예제 #1
0
        public static ClanMemberStatsViewModel ConvertToClanMemberStats(WarRanking ranking)
        {
            ClanMemberStatsViewModel stats = new ClanMemberStatsViewModel();

            stats.Id               = ranking.id;
            stats.ClanWarId        = ranking.clanWarId;
            stats.ClanGroupId      = ranking.clanGroupId;
            stats.HasHeroicDefense = ranking.heroicDefense;
            stats.HasHeroicAttack  = ranking.heroicAttack;
            stats.AttacksDefended  = ranking.attacksDefended;
            stats.AttacksOn        = ranking.attacksOn;
            stats.Note             = ranking.note;
            stats.AddedOn          = ranking.addedOn;
            stats.UpdatedOn        = ranking.updatedOn;
            stats.ClanUserId       = ranking.clanUserId;
            stats.Stars            = ranking.stars;
            stats.OptOut           = ranking.optOut;
            stats.Xp               = ranking.xp;
            stats.AttackWin        = ranking.attackWin;
            stats.AttackOn         = ranking.attackOn;

            stats.TotalHeroicDefense = Convert.ToInt16(ranking.heroicDefense);
            stats.TotalHeroicAttack  = Convert.ToInt16(ranking.heroicAttack);

            return(stats);
        }
        public RankingsUpsertViewModel(List <ClanMemberStatsViewModel> clanMemberStatsViewModel)
        {
            _warRankings = new List <WarRanking>();

            foreach (ClanMemberStatsViewModel stats in clanMemberStatsViewModel)
            {
                _warRankings.Add(ClanMemberStatsViewModel.ConvertToWarRanking(stats));
            }
        }
        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);
        }
예제 #4
0
        public static WarRanking ConvertToWarRanking(ClanMemberStatsViewModel stats)
        {
            WarRanking ranking = new WarRanking();

            ranking.id              = stats.Id;
            ranking.clanWarId       = stats.ClanWarId;
            ranking.clanGroupId     = stats.ClanGroupId;
            ranking.heroicDefense   = stats.HasHeroicDefense;
            ranking.heroicAttack    = stats.HasHeroicAttack;
            ranking.attacksDefended = stats.AttacksDefended;
            ranking.attacksOn       = stats.AttacksOn;
            ranking.note            = stats.Note;
            ranking.addedOn         = stats.AddedOn;
            ranking.updatedOn       = stats.UpdatedOn;
            ranking.clanUserId      = stats.ClanUserId;
            ranking.stars           = stats.Stars;
            ranking.optOut          = stats.OptOut;
            ranking.xp              = stats.Xp;
            ranking.attackWin       = stats.AttackWin;
            ranking.attackOn        = stats.AttackOn;

            return(ranking);
        }
        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());
            }
        }
        public static WarRanking ConvertToWarRanking(ClanMemberStatsViewModel stats)
        {
            WarRanking ranking = new WarRanking();
            ranking.id				= stats.Id;
            ranking.clanWarId		= stats.ClanWarId;
            ranking.clanGroupId		= stats.ClanGroupId;
            ranking.heroicDefense	= stats.HasHeroicDefense;
            ranking.heroicAttack	= stats.HasHeroicAttack;
            ranking.attacksDefended = stats.AttacksDefended;
            ranking.attacksOn		= stats.AttacksOn;
            ranking.note			= stats.Note;
            ranking.addedOn			= stats.AddedOn;
            ranking.updatedOn		= stats.UpdatedOn;
            ranking.clanUserId		= stats.ClanUserId;
            ranking.stars			= stats.Stars;
            ranking.optOut			= stats.OptOut;
            ranking.xp				= stats.Xp;
            ranking.attackWin		= stats.AttackWin;
            ranking.attackOn		= stats.AttackOn;

            return ranking;
        }
        public static ClanMemberStatsViewModel ConvertToClanMemberStats(WarRanking ranking)
        {
            ClanMemberStatsViewModel stats = new ClanMemberStatsViewModel();
            stats.Id				= ranking.id;
            stats.ClanWarId			= ranking.clanWarId;
            stats.ClanGroupId		= ranking.clanGroupId;
            stats.HasHeroicDefense	= ranking.heroicDefense;
            stats.HasHeroicAttack	= ranking.heroicAttack;
            stats.AttacksDefended	= ranking.attacksDefended;
            stats.AttacksOn			= ranking.attacksOn;
            stats.Note				= ranking.note;
            stats.AddedOn			= ranking.addedOn;
            stats.UpdatedOn			= ranking.updatedOn;
            stats.ClanUserId		= ranking.clanUserId;
            stats.Stars				= ranking.stars;
            stats.OptOut			= ranking.optOut;
            stats.Xp				= ranking.xp;
            stats.AttackWin			= ranking.attackWin;
            stats.AttackOn			= ranking.attackOn;

            stats.TotalHeroicDefense	= Convert.ToInt16(ranking.heroicDefense);
            stats.TotalHeroicAttack		= Convert.ToInt16(ranking.heroicAttack);

            return stats;
        }
        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());
            }
        }