Exemplo n.º 1
0
        public ActionResult Index()
        {
            var model = new List<ClanModel>();

            using (WotKitEntities db = new WotKitEntities())
            {
                var query = from x in db.Clans
                            select new ClanModel
                            {
                                ClanId = x.ClanId,
                                Abbreviation = x.Abbreviation,
                                Name = x.Name,
                                EmblemBWTank = x.EmblemBWTank,
                                EmblemLarge = x.EmblemLarge,
                                EmblemMedium = x.EmblemMedium,
                                EmblemSmall = x.EmblemSmall,
                                CreatedAtDate = x.CreatedAtDate,
                                UpdatedAtDate = x.UpdatedAtDate
                            };

                model = query.ToList();
            }

            // TODO: Implement this, http://stackoverflow.com/a/19301623/16008, so we can set this on the models in the EF
            foreach (var item in model)
            {
                item.CreatedAtDate = DateTime.SpecifyKind(item.CreatedAtDate, DateTimeKind.Utc);
                item.UpdatedAtDate = DateTime.SpecifyKind(item.UpdatedAtDate, DateTimeKind.Utc);
            }

            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var model = new ClanDetailModel();

            using (WotKitEntities db = new WotKitEntities())
            {
                var clan = db.Clans.Where(x => x.ClanId == id).Single();

                model.Name = clan.Name;
                model.Abbreviation = clan.Abbreviation;
                model.ClanId = clan.ClanId;
                model.EmblemSmall = clan.EmblemSmall;

                var maxAsOfDate = db.ClanDetails.Where(x => x.ClanId == id).Max(x => x.AsOfDate);
                model.AsOfDate = maxAsOfDate;

                var members = from cd in db.ClanDetails
                              where cd.ClanId == id && cd.AsOfDate == maxAsOfDate
                              select new ClanMemberDetailModel
                              {
                                  Name = cd.Player.Name,
                                  Position = cd.Rolei18n,
                                  AllBattles = cd.AllBattles,
                                  ClanBattles = cd.ClanBattles,
                                  CompanyBattles = cd.CompanyBattles
                              };
                model.ClanMembers = members.ToList();
            }

            return View(model);
        }
Exemplo n.º 3
0
        public void LoadClanDetails(int clanId)
        {
            using (WotKitEntities db = new WotKitEntities())
            {
                // Get the clan and load it
                var clan = _wargamingApiService.GetClanDetails(clanId);

                // TODO: var clanInDb = Upsert(clan); // Insert or update the clan
                var clanInDb = db.Clans.Where(x => x.ClanId == clanId).SingleOrDefault();
                if (clanInDb == null)
                {
                    // Add the clan
                    clanInDb = new Clan()
                    {
                        ClanId = clanId,
                        Abbreviation = clan.Abbreviation,
                        Name = clan.Name,
                        EmblemBWTank = clan.EmblemBWTank,
                        EmblemLarge = clan.EmblemLarge,
                        EmblemMedium = clan.EmblemMedium,
                        EmblemSmall = clan.EmblemSmall,
                        CreatedAtDate = clan.CreatedAtDate,
                        UpdatedAtDate = clan.UpdatedAtDate
                    };
                    db.Clans.Add(clanInDb);
                    db.SaveChanges();
                }
                else
                {
                    // Update the clan?
                    clanInDb.UpdatedAtDate = clan.UpdatedAtDate;
                }

                // Now using the members load them
                DateTime now = DateTime.UtcNow;
                foreach (var member in clan.Members)
                {
                    // Is this dude even in the database?
                    var player = db.Players.Where(x => x.AccountDBID == member.AccountId).SingleOrDefault();
                    if (player == null)
                    {
                        // Add em
                        player = new Player() {
                            AccountDBID = member.AccountId,
                            Name = member.AccountName,
                        };
                        db.Players.Add(player);
                    }
                    db.SaveChanges();

                    // Go get details for this player
                    var playerPersonalData = _wargamingApiService.GetPlayerPersonalData(player.AccountDBID);

                    // Now we add a record for this batch taking a count of their battles
                    db.ClanDetails.Add(new ClanDetail()
                    {
                        AsOfDate = now,
                        AllBattles = playerPersonalData.All.Battles,
                        ClanId = clanInDb.ClanId,
                        ClanBattles = playerPersonalData.Clan.Battles,
                        PlayerId = player.PlayerId,
                        CompanyBattles = playerPersonalData.Company.Battles,
                        Role = member.Role,
                        Rolei18n = member.Rolei18n
                    });
                }
                db.SaveChanges();
            }
        }