Exemplo n.º 1
0
        protected async void FormSubmit(EditContext editContext)
        {
            Console.WriteLine(User1Id);
            Console.WriteLine(User2Id);
            Console.WriteLine(ArmyPlayer1);
            Console.WriteLine(ArmyPlayer2);
            var user1 = UserManager.Users.FirstOrDefault(ap => ap.Id == User1Id);
            var user2 = UserManager.Users.FirstOrDefault(ap => ap.Id == User2Id);
            var army1 = await ArmyRepository.GetById(int.Parse(ArmyPlayer1));

            var army2 = await ArmyRepository.GetById(int.Parse(ArmyPlayer2));

            if (user1 != null && user2 != null && army1 != null && army2 != null)
            {
                Game.Player1     = user1;
                Game.Player2     = user2;
                Game.ArmyPlayer1 = army1;
                Game.ArmyPlayer2 = army2;
            }

            if (!editContext.Validate())
            {
                return;
            }
            await GameRepository.Create(Game);

            if (Game.NoDetails)
            {
                NavigationManager.NavigateTo("game");
            }
            else
            {
                NavigationManager.NavigateTo("game/edit/" + Game.Id);
            }
        }
Exemplo n.º 2
0
        protected async void FormSubmit(EditContext editContext)
        {
            if (!editContext.Validate())
            {
                return;
            }
            await ArmyRepository.Update(Army);

            NavigationManager.NavigateTo("army");
        }
Exemplo n.º 3
0
        protected override async Task OnInitializedAsync()
        {
            Console.WriteLine(CultureInfo.CurrentCulture);
            Users  = UserManager.Users.ToList();
            Armies = await ArmyRepository.GetList();

            GameTables = await GameTableRepository.GetList();

            Scenarios = await ScenarioRepository.GetList();

            if (!string.IsNullOrEmpty(Player1) && !string.IsNullOrEmpty(Player2) && !string.IsNullOrEmpty(Date))
            {
                User1Id = Player1;
                User2Id = Player2;
                //            game.Date = DateTime.ParseExact(date, "dd-MM-yyyy",null);
            }
        }
Exemplo n.º 4
0
        protected async void FormSubmit(EditContext editContext)
        {
            var user1 = UserManager.Users.FirstOrDefault(u => u.Id == User1Id);
            var user2 = UserManager.Users.FirstOrDefault(u => u.Id == User2Id);
            var army1 = await ArmyRepository.GetById(int.Parse(ArmyPlayer1Id));

            var army2 = await ArmyRepository.GetById(int.Parse(ArmyPlayer2Id));

            if (user1 != null && user2 != null && army1 != null && army2 != null)
            {
                Game.Player1     = user1;
                Game.Player2     = user2;
                Game.ArmyPlayer1 = army1;
                Game.ArmyPlayer2 = army2;
            }

            if (editContext.Validate())
            {
                await GameRepository.Update(Game);
            }
        }
Exemplo n.º 5
0
 protected override async Task OnInitializedAsync()
 {
     Army = await ArmyRepository.GetById(Id);
 }
        protected async void DownloadXml()
        {
            var myXmlDocument = new XmlDocument();

            myXmlDocument.Load("https://raw.githubusercontent.com/BSData/wh40k/master/Tyranids.cat");
            var catalogue = myXmlDocument.GetElementsByTagName("catalogue")[0];
            var army      = await ArmyRepository.GetByBattleScribeId(catalogue.Attributes["id"].Value);

            if (army == null)
            {
                army = new Data.Models.Army
                {
                    BattleScribeId       = catalogue.Attributes["id"].Value,
                    BattleScribeRevision = catalogue.Attributes["revision"].Value,
                    Name = catalogue.Attributes["name"].Value
                };
                await ArmyRepository.Create(army);
            }

            var categoryNodeList = myXmlDocument.GetElementsByTagName("categoryEntry");

            foreach (XmlNode categoryNode in categoryNodeList)
            {
                var category = await CategoryRepository.GetByBattleScribeId(categoryNode.Attributes["id"].Value);

                var create = false;
                if (category == null)
                {
                    create   = true;
                    category = new Category();
                }

                category.Name           = HttpUtility.HtmlDecode(categoryNode.Attributes["name"].Value);
                category.BattleScribeId = categoryNode.Attributes["id"].Value;
                if (create)
                {
                    await CategoryRepository.Create(category);
                }
                else
                {
                    await CategoryRepository.Update(category);
                }
            }

            var unitList = myXmlDocument.GetElementsByTagName("selectionEntry");

            foreach (XmlNode unitNode in unitList)
            {
                if (!unitNode.Attributes["type"].Any() || unitNode.Attributes["type"].Value != "unit")
                {
                    continue;
                }
                var create = false;
                var unit   = await UnitRepository.GetByBattleScribeId(unitNode.Attributes["id"].Value);

                if (unit == null)
                {
                    create = true;
                    unit   = new Data.Models.Unit();
                }

                unit.Name           = unitNode.Attributes["name"].Value;
                unit.BattleScribeId = unitNode.Attributes["id"].Value;
                unit.Army           = army;
                if (create)
                {
                    await UnitRepository.Create(unit);
                }
                else
                {
                    await UnitRepository.Update(unit);
                }

                var categoryLinkNodes = unitNode.ChildNodes.Cast <XmlNode>()
                                        .First(nc => nc.LocalName == "categoryLinks").Cast <XmlNode>()
                                        .Where(ncc => ncc.LocalName == "categoryLink");
                foreach (var categoryLinkNode in categoryLinkNodes)
                {
                    var unitCateg = await UnitCategoryRepository.GetbyBattleScribeIds(
                        categoryLinkNode.Attributes["targetId"].Value, unitNode.Attributes["id"].Value);

                    if (unitCateg != null)
                    {
                        continue;
                    }
                    Console.WriteLine("CREATE CATEG");
                    var category =
                        await CategoryRepository.GetByBattleScribeId(categoryLinkNode.Attributes["targetId"].Value);

                    if (category == null)
                    {
                        continue;
                    }
                    unitCateg = new UnitCategory
                    {
                        Unit     = unit,
                        Category = category
                    };
                    await UnitCategoryRepository.Create(unitCateg);
                }

                var keywordNodes = unitNode.ChildNodes.Cast <XmlNode>()
                                   .FirstOrDefault(nc => nc.LocalName == "profiles")?.Cast <XmlNode>()
                                   .FirstOrDefault(ncc =>
                                                   ncc.LocalName == "profile" && ncc.Attributes["typeName"] != null &&
                                                   ncc.Attributes["typeName"].Value == "Keywords")?.Cast <XmlNode>()
                                   .FirstOrDefault(atr => atr.LocalName == "characteristics")?.Cast <XmlNode>()
                                   .Where(atr => atr.LocalName == "characteristic");
                if (keywordNodes == null)
                {
                    continue;
                }
                foreach (var keywordNode in keywordNodes)
                {
                    var keyword = await KeywordRepository.GetByName(HttpUtility.HtmlDecode(keywordNode.InnerText));

                    if (keyword == null)
                    {
                        keyword = new Keyword
                        {
                            Name = HttpUtility.HtmlDecode(keywordNode.InnerText)
                        };
                        await KeywordRepository.Create(keyword);
                    }

                    var unitKeyword = await UnitKeywordRepository.GetbyIds(keyword.Id, unit.Id);

                    if (unitKeyword != null)
                    {
                        continue;
                    }
                    unitKeyword = new UnitKeyword
                    {
                        Unit    = unit,
                        Keyword = keyword
                    };
                    await UnitKeywordRepository.Create(unitKeyword);
                }
            }
        }
Exemplo n.º 7
0
 protected override async Task OnInitializedAsync()
 {
     Armies = await ArmyRepository.GetList();
 }
Exemplo n.º 8
0
        protected override async Task OnInitializedAsync()
        {
            Users = await Task.FromResult(UserManager.Users.ToList());

            Armies = await ArmyRepository.GetList();

            Game = await GameRepository.GetById(Id);

            GameTables = await GameTableRepository.GetList();

            Scenarios = await ScenarioRepository.GetList();

            if (Game.Player1 != null)
            {
                User1Id = Game.Player1.Id;
            }
            else
            {
                User1Id = string.Empty;;
            }
            if (Game.Player2 != null)
            {
                User2Id = Game.Player2.Id;
            }
            else
            {
                User2Id = string.Empty;;
            }
            if (Game.ArmyPlayer1 != null)
            {
                ArmyPlayer1Id = Game.ArmyPlayer1.Id.ToString();
            }
            else
            {
                ArmyPlayer1Id = string.Empty;;
            }
            if (Game.ArmyPlayer2 != null)
            {
                ArmyPlayer2Id = Game.ArmyPlayer2.Id.ToString();
            }
            else
            {
                ArmyPlayer2Id = string.Empty;;
            }
            if (Game.GameTable != null)
            {
                GameTable = Game.GameTable.Id.ToString();
            }
            else
            {
                GameTable = string.Empty;;
            }
            if (Game.Scenario != null)
            {
                Scenario = Game.Scenario.Id.ToString();
            }
            else
            {
                Scenario = string.Empty;;
            }
        }