예제 #1
0
 public ActionResult AddEdit(RuneViewModel model)
 {
     if (ModelState.IsValid)
     {
         var rune = _context.Runes.Find(model.Id);
         if (rune == null)
         {
             rune = new Data.Models.Runes();
             _context.Runes.Add(rune);
         }
         rune.Name         = model.Name;
         rune.Description  = model.Description;
         rune.Sort         = model.Sort;
         rune.LevelRune    = model.Level;
         rune.RuneCategory = _context.RuneCategories.FirstOrDefault(x => x.Id == model.RuneCategoryId);
         if (model.Image != null && model.Image.Length > 0)
         {
             using (var ms = new MemoryStream())
             {
                 model.Image.CopyTo(ms);
                 var bytearray = ms.ToArray();
                 rune.Logo = string.Format("data:{1};base64,{0}",
                                           Convert.ToBase64String(bytearray),
                                           model.Image.ContentType);
             }
         }
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(model));
 }
예제 #2
0
        // GET: RuneCategoriesController/Create
        public ActionResult AddEdit(int id)
        {
            var model = new RuneViewModel();
            var rune  = _context.Runes.Where(x => x.Id == id)
                        .Include(x => x.RuneCategory)
                        .FirstOrDefault();

            if (rune != null)
            {
                model.Id             = id;
                model.Name           = rune.Name;
                model.Description    = rune.Description;
                model.ImageSrc       = rune.Logo;
                model.Sort           = rune.Sort;
                model.Level          = rune.LevelRune;
                model.RuneCategoryId = rune.RuneCategory.Id;
            }
            model.AllRuneCategories = _context.RuneCategories.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            }).ToList();
            return(View(model));
        }
예제 #3
0
        private async Task <ChampionStatsViewModel> ReturnChampionStatsViewModel(string id)
        {
            var dbChampion = await this.db.Champions
                             .Include(x => x.Passive)
                             .Include(x => x.BestAbilities).ThenInclude(x => x.Abilities).ThenInclude(x => x.PerLevelStats)
                             .Include(x => x.BestStartingItems).ThenInclude(x => x.Items)
                             .Include(x => x.BestItems).ThenInclude(x => x.Items)
                             .Include(x => x.BestRunes).ThenInclude(x => x.Runes)
                             .Include(x => x.BestSummonerSpells).ThenInclude(x => x.SummonerSpells)
                             .Include(x => x.ChampionCounters)
                             .Include(x => x.ChampionRoles)
                             .AsSplitQuery()
                             .FirstOrDefaultAsync <Champion>(x => x.Id == id);

            var dbChampionRole = dbChampion.ChampionRoles.FirstOrDefault();

            // Champion
            ChampionStatsViewModel championToAdd = new ChampionStatsViewModel
            {
                Name     = dbChampion.Name,
                ImageUrl = dbChampion.ImageUrl,
                IsFree   = dbChampion.IsFree,
                Passive  = new ChampionPassiveViewModel
                {
                    Name        = dbChampion.Passive.Name,
                    ChampionId  = dbChampion.Passive.ChampionId,
                    Description = dbChampion.Passive.Description,
                    ImageUrl    = dbChampion.Passive.ImageUrl,
                },

                ChampionRole = new ChampionRoleViewModel
                {
                    WinRate      = dbChampionRole.WinRate,
                    BanRate      = dbChampionRole.BanRate,
                    PickRate     = dbChampionRole.PickRate,
                    TotalMatches = dbChampionRole.TotalMatches,
                    Role         = dbChampionRole.Role.ToString(),
                    Tier         = dbChampionRole.Tier,
                    ImagePath    = $"/images/roles/{dbChampionRole.Role.ToString().ToLower()}.png",
                },
            };

            // Abilities
            var dbBestAbilities = dbChampion.BestAbilities.FirstOrDefault();

            var championAbilitiesToAdd = new ChampionAbilitiesViewModel
            {
                WinRate      = dbBestAbilities.WinRate,
                TotalMatches = dbBestAbilities.TotalMatches,
            };

            var abilityPriority = dbBestAbilities.SkillPriority.Split(", ");

            for (int i = 0; i < abilityPriority.Length; i++)
            {
                string abilityName = abilityPriority[i];
                var    ability     = dbBestAbilities.Abilities.FirstOrDefault(x => x.AbilityType.ToString() == abilityName);

                var abilityToAdd = new BaseAbilityViewModel
                {
                    AbilityType = ability.AbilityType.ToString(),
                    Description = ability.Description,
                    ImageUrl    = ability.ImageUrl,
                    MaxRank     = ability.MaxRank,
                    Name        = ability.Name,
                    IsFirst     = i == 0 ? false : true,
                };

                var dbStatsPerLevel = ability.PerLevelStats;

                foreach (var stats in ability.PerLevelStats)
                {
                    var statsToAdd = new PerLevelStatViewModel
                    {
                        Level          = stats.Level,
                        Cooldown       = stats.Cooldown,
                        Cost           = stats.Cost,
                        CostsPerSecond = stats.CostsPerSecond,
                        Range          = stats.Range,
                    };

                    abilityToAdd.PerLevelStats.Add(statsToAdd);
                }

                championAbilitiesToAdd.Abilities.Add(abilityToAdd);
            }

            championToAdd.BestAbilities.Add(championAbilitiesToAdd);

            // Summoner Spells
            var dbBestSummonerSpells = dbChampion.BestSummonerSpells.FirstOrDefault();

            var championSummonerSpellsToAdd = new ChampionSummonerSpellsViewModel
            {
                WinRate      = dbBestSummonerSpells.WinRate,
                TotalMatches = dbBestSummonerSpells.TotalMatches,
            };

            var summonerSpellPriority = dbBestSummonerSpells.SummonerSpellPriority.Split(", ");

            for (int i = 0; i < summonerSpellPriority.Length; i++)
            {
                string summonerSpellName = summonerSpellPriority[i];
                var    spell             = dbBestSummonerSpells.SummonerSpells.FirstOrDefault(x => x.Name == summonerSpellName);

                var summonerSpellToAdd = new SummonerSpellViewModel
                {
                    Name         = spell.Name,
                    Description  = spell.Description,
                    BaseCooldown = spell.BaseCooldown,
                    ImageUrl     = spell.ImageUrl,
                    Tooltip      = spell.Tooltip,
                };

                championSummonerSpellsToAdd.SummonerSpells.Add(summonerSpellToAdd);
            }

            championToAdd.BestSummonerSpells.Add(championSummonerSpellsToAdd);

            // Starting Items
            var dbBestStarterItems = dbChampion.BestStartingItems.FirstOrDefault();

            var championStarterItemsToAdd = new ChampionStarterItemsViewModel
            {
                WinRate  = dbBestStarterItems.WinRate,
                PickRate = dbBestStarterItems.PickRate,
            };

            var startingItemPriority = dbBestStarterItems.ItemPriority.Split(", ").Where(x => x != string.Empty).ToArray();

            for (int i = 0; i < startingItemPriority.Length; i++)
            {
                string itemName = startingItemPriority[i];
                var    item     = dbBestStarterItems.Items.FirstOrDefault(x => x.Name == itemName);

                var itemToAdd = new ItemViewModel
                {
                    Name        = item.Name,
                    Description = item.Description,
                    ImageUrl    = item.ImageUrl,
                    FullCost    = item.FullCost,
                };

                championStarterItemsToAdd.Items.Add(itemToAdd);
            }

            championToAdd.BestStartingItems.Add(championStarterItemsToAdd);

            // Main Items
            var dbBestItems = dbChampion.BestItems.FirstOrDefault();

            var championItemsToAdd = new ChampionItemsViewModel
            {
                WinRate = dbBestStarterItems.WinRate,
            };

            var itemPriority = dbBestItems.ItemPriority.Split(", ");

            for (int i = 0; i < itemPriority.Length; i++)
            {
                string itemName = itemPriority[i];
                var    item     = dbBestItems.Items.FirstOrDefault(x => x.Name == itemName);

                var itemToAdd = new ItemViewModel
                {
                    Name        = item.Name,
                    Description = item.Description,
                    ImageUrl    = item.ImageUrl,
                    FullCost    = item.FullCost,
                };

                championItemsToAdd.Items.Add(itemToAdd);
            }

            championToAdd.BestItems.Add(championItemsToAdd);

            // ChampionRunes
            var dbBestRunes = dbChampion.BestRunes.FirstOrDefault();

            var championRunesToAdd = new ChampionRunesViewModel
            {
                WinRate           = dbBestRunes.WinRate,
                TotalMatches      = dbBestRunes.TotalMatches,
                MainRuneTree      = dbBestRunes.MainRuneTree.ToString(),
                SecondaryRuneTree = dbBestRunes.SecondaryRuneTree.ToString(),
            };

            foreach (var rune in dbBestRunes.Runes)
            {
                var runeToAdd = new RuneViewModel
                {
                    Name             = rune.Name,
                    ShortDescription = rune.ShortDescription,
                    ImageUrl         = rune.ImageUrl,
                    IsKeystone       = rune.IsKeystone,
                    RunePath         = rune.RunePathId,
                    IsActive         = true,
                };

                championRunesToAdd.Runes.Add(runeToAdd);
            }

            var dbBestStatRunes = await this.db.ChampionsRunes.Where(x => x.ChampionId == id).Include(x => x.StatRunes).AsSplitQuery().FirstOrDefaultAsync <ChampionRunes>();

            foreach (var statRune in dbBestStatRunes.StatRunes)
            {
                var statRuneToAdd = new StatRuneViewModel
                {
                    Description = statRune.Description,
                    ImagePath   = statRune.ImagePath,
                    RowId       = statRune.RowId,
                    RuneType    = statRune.RuneType.ToString(),
                    IsActive    = true,
                };

                championRunesToAdd.StatRunes.Add(statRuneToAdd);
            }

            championToAdd.BestRunes.Add(championRunesToAdd);

            // ChampionCounters
            foreach (var counterChampion in dbChampion.ChampionCounters)
            {
                var counterChampionToAdd = new ChampionCounterViewModel
                {
                    CounterChapmionKey  = counterChampion.CounterChapmionKey,
                    CounterChampionName = counterChampion.CounterChampionName,
                    ImageUrl            = counterChampion.ImageUrl,
                    TotalMatches        = counterChampion.TotalMatches,
                    WinRate             = counterChampion.WinRate,
                };

                championToAdd.ChampionCounters.Add(counterChampionToAdd);
            }

            // Runes
            var primaryRunes   = this.db.Runes.Where(x => x.RunePathId == dbBestRunes.MainRuneTree.ToString()).ToList();
            var secondaryRunes = this.db.Runes.Where(x => x.RunePathId == dbBestRunes.SecondaryRuneTree.ToString() && !x.IsKeystone).ToList();

            int counterPrimaryRunes = 0;

            foreach (var primaryRune in primaryRunes.OrderBy(x => x.Row).ThenBy(x => x.Count))
            {
                var primaryRuneToAdd = new RuneViewModel
                {
                    Name             = primaryRune.Name,
                    IsKeystone       = primaryRune.IsKeystone,
                    ImageUrl         = primaryRune.ImageUrl,
                    ShortDescription = primaryRune.ShortDescription,
                    RunePath         = primaryRune.RunePathId,
                    IsActive         = championToAdd.BestRunes.FirstOrDefault()
                                       .Runes
                                       .Any(x => x.Name == primaryRune.Name),
                };

                if (!primaryRuneToAdd.IsActive)
                {
                    primaryRuneToAdd.ImageUrl = $"/images/runes/grayscaled/{primaryRune.RunePathId}/{this.sanitizerService.RemoveSpacesAndSymbols(primaryRune.Name)}.png";
                }

                if (primaryRuneToAdd.IsKeystone)
                {
                    championToAdd.PrimaryRunesKeystoneRow.Add(primaryRuneToAdd);
                }
                else if (counterPrimaryRunes < 3)
                {
                    championToAdd.PrimaryRunesSecondRow.Add(primaryRuneToAdd);
                    counterPrimaryRunes++;
                }
                else if (counterPrimaryRunes >= 3 && counterPrimaryRunes < 6)
                {
                    championToAdd.PrimaryRunesThirdRow.Add(primaryRuneToAdd);
                    counterPrimaryRunes++;
                }
                else if (counterPrimaryRunes >= 6)
                {
                    championToAdd.PrimaryRunesFourthRow.Add(primaryRuneToAdd);
                }
            }

            int counterSecondaryRunes = 0;

            foreach (var secondaryRune in secondaryRunes.OrderBy(x => x.Row).ThenBy(x => x.Count))
            {
                var secondaryRuneToAdd = new RuneViewModel
                {
                    Name             = secondaryRune.Name,
                    IsKeystone       = secondaryRune.IsKeystone,
                    ImageUrl         = secondaryRune.ImageUrl,
                    ShortDescription = secondaryRune.ShortDescription,
                    RunePath         = secondaryRune.RunePathId,
                    IsActive         = championToAdd.BestRunes.FirstOrDefault()
                                       .Runes
                                       .Any(x => x.Name == secondaryRune.Name),
                };

                if (!secondaryRuneToAdd.IsActive)
                {
                    secondaryRuneToAdd.ImageUrl = $"/images/runes/grayscaled/{secondaryRune.RunePathId}/{this.sanitizerService.RemoveSpacesAndSymbols(secondaryRune.Name)}.png";
                }

                if (counterSecondaryRunes < 3)
                {
                    championToAdd.SecondaryRunesSecondRow.Add(secondaryRuneToAdd);
                    counterSecondaryRunes++;
                }
                else if (counterSecondaryRunes >= 3 && counterSecondaryRunes < 6)
                {
                    championToAdd.SecondaryRunesThirdRow.Add(secondaryRuneToAdd);
                    counterSecondaryRunes++;
                }
                else if (counterSecondaryRunes >= 6)
                {
                    championToAdd.SecondaryRunesFourthRow.Add(secondaryRuneToAdd);
                }
            }

            // Stat Runes
            var statRunes = this.db.StatRunes.ToList();

            statRunes.Reverse();

            int counterStatRunes = 0;

            foreach (var statRune in statRunes)
            {
                var statRuneToAdd = new StatRuneViewModel
                {
                    RowId       = statRune.RowId,
                    RuneType    = statRune.RuneType.ToString(),
                    Description = statRune.Description,
                    ImagePath   = statRune.ImagePath,
                    IsActive    = championToAdd.BestRunes.FirstOrDefault()
                                  .StatRunes
                                  .Any(x => x.RowId == statRune.RowId && x.Description == statRune.Description),
                };

                if (!statRuneToAdd.IsActive)
                {
                    statRuneToAdd.ImagePath = statRuneToAdd.ImagePath.Insert(18, "/grayscaled/GS");
                }

                if (counterStatRunes < 3)
                {
                    championToAdd.StatRunesFirstRow.Add(statRuneToAdd);
                    counterStatRunes++;
                }
                else if (counterStatRunes >= 3 && counterStatRunes < 6)
                {
                    championToAdd.StatRunesSecondRow.Add(statRuneToAdd);
                    counterStatRunes++;
                }
                else if (counterStatRunes >= 6)
                {
                    championToAdd.StatRunesThirdRow.Add(statRuneToAdd);
                    counterStatRunes++;
                }
            }

            return(championToAdd);
        }