예제 #1
0
        public async Task <ICollection <Donation> > GetDonations(string id)
        {
            var tag = Utils.LinkIdToTag(id);

            var data = new List <Donation>();

            var clan = await api.GetClan(tag, false, false);

            if (clan.MemberList != null)
            {
                foreach (var member in clan.MemberList)
                {
                    data.Add(new Donation
                    {
                        Tag      = member.Tag,
                        Name     = member.Name,
                        Donated  = member.Donations,
                        Received = member.DonationsReceived
                    });
                }
            }

            return(data);
        }
예제 #2
0
        protected async Task <Clan> GetDetails(string tag)
        {
            var clan = new Clan
            {
                Tag        = tag,
                Name       = "Clan not found",
                MemberList = new List <Member>()
            };

            try
            {
                var clans = db.Clans.Where(c => c.Tag == tag).ToList();
                if (clans.Count > 0)
                {
                    clan = clans.First();

                    clan.MemberList = db.Members.Where(m => m.ClanTag == clan.Tag).OrderBy(m => m.ClanRank).ToList();

                    if (clan.IsWarLogPublic)
                    {
                        clan.Wars = db.Wars.Where(w => w.ClanTag == tag && w.PreparationStartTime < Constants.MaxVisibleSearchTime).OrderByDescending(w => w.EndTime).ToList();
                    }
                    else
                    {
                        clan.Wars = this.GetPrivateWars(tag);
                    }
                }
                else
                {
                    var wars = this.GetPrivateWars(tag);
                    if (wars.Count > 0)
                    {
                        clan = await api.GetClan(tag, true, true);

                        if (clan.Wars != null && clan.Wars.Count > 0)
                        {
                            var syncTimes  = db.WarSyncs.Select(s => new { s.Start, s.Finish }).ToArray();
                            var validities = db.ClanValidities.ToList();
                            var warLookup  = wars.ToDictionary(w => string.Format("{0}{1}", w.OpponentTag, w.EndTime.Date));
                            foreach (var war in clan.Wars)
                            {
                                var warKey = string.Format("{0}{1}", war.OpponentTag, war.EndTime.Date);
                                if (!warLookup.TryGetValue(warKey, out War clanWar))
                                {
                                    var synced = syncTimes.Where(s => s.Start <= war.PreparationStartTime && s.Finish >= war.PreparationStartTime).FirstOrDefault();
                                    if (synced != null && (war.TeamSize == Constants.WAR_SIZE1 || war.TeamSize == Constants.WAR_SIZE2))
                                    {
                                        war.Synced = true;
                                    }

                                    wars.Add(war);
                                    clanWar = war;
                                }

                                var matched = validities.Where(v => v.Tag == war.OpponentTag && v.ValidFrom <= war.PreparationStartTime && v.ValidTo >= war.PreparationStartTime).FirstOrDefault();
                                if (matched != null)
                                {
                                    clanWar.Matched = true;
                                }
                            }
                            clan.Wars = wars.OrderByDescending(w => w.PreparationStartTime).ToList();
                        }
                        else
                        {
                            clan.Wars = wars;
                        }
                    }
                    else
                    {
                        clan = await api.GetClan(tag, true, true);
                    }
                }
            }
            catch (Exception e)
            {
                clan.Description = e.Message;
            }
            return(clan);
        }