예제 #1
0
        // GET: ItemsController
        public ActionResult Index(int?cid, int?vscid)
        {
            ChampionViewModel mainChamp = null;
            MatchUpViewModel  vscVM     = null;

            if (cid.HasValue)
            {
                mainChamp = _context.Champions
                            .Include(x => x.Spells)
                            .Include(x => x.SummonerSpellD)
                            .Include(x => x.SummonerSpellF)
                            .Where(x => x.Id == cid)
                            .Select(x => new ChampionViewModel
                {
                    Id       = x.Id,
                    ImageSrc = x.Logo,
                    Name     = x.Name,
                    SpellP   = x.Spells.Where(s => s.SpellType == "P").Select(s => new SpellViewModel
                    {
                        Name        = s.Name,
                        Description = s.Description,
                        ImageSrc    = s.Logo
                    }).FirstOrDefault(),
                    SpellQ = x.Spells.Where(s => s.SpellType == "Q").Select(s => new SpellViewModel
                    {
                        Name        = s.Name,
                        Description = s.Description,
                        ImageSrc    = s.Logo
                    }).FirstOrDefault(),
                    SpellW = x.Spells.Where(s => s.SpellType == "W").Select(s => new SpellViewModel
                    {
                        Name        = s.Name,
                        Description = s.Description,
                        ImageSrc    = s.Logo
                    }).FirstOrDefault(),
                    SpellE = x.Spells.Where(s => s.SpellType == "E").Select(s => new SpellViewModel
                    {
                        Name        = s.Name,
                        Description = s.Description,
                        ImageSrc    = s.Logo
                    }).FirstOrDefault(),
                    SpellR = x.Spells.Where(s => s.SpellType == "R").Select(s => new SpellViewModel
                    {
                        Name        = s.Name,
                        Description = s.Description,
                        ImageSrc    = s.Logo
                    }).FirstOrDefault(),
                    SummonerSpellD = new SummonerSpellViewModel
                    {
                        Name        = x.SummonerSpellD.Name,
                        Description = x.SummonerSpellD.Description,
                        ImageSrc    = x.SummonerSpellD.Logo
                    },
                    SummonerSpellF = new SummonerSpellViewModel
                    {
                        Name        = x.SummonerSpellF.Name,
                        Description = x.SummonerSpellF.Description,
                        ImageSrc    = x.SummonerSpellF.Logo
                    },
                    AllSummonerSpells = _context.SummonerSpells.Select(s => new SelectListItem
                    {
                        Value = x.Id.ToString(),
                        Text  = x.Name
                    }).ToList(),
                })
                            .FirstOrDefault();
                var matchUp = _context.MatchUps
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.PrimaryMainRune)
                              .ThenInclude(x => x.RuneCategory)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.PrimaryRune1)
                              .ThenInclude(x => x.RuneCategory)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.PrimaryRune2)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.PrimaryRune3)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.SecondaryRune1)
                              .ThenInclude(x => x.RuneCategory)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.SecondaryRune2)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.SecondaryRune3)
                              .Include(x => x.ItemSets)
                              .ThenInclude(x => x.Item)
                              .Include(x => x.VsChampion)
                              .Where(x => x.MainChampion.Id == cid && ((!vscid.HasValue && x.VsChampion == null) || (x.VsChampion.Id == vscid)))
                              .FirstOrDefault();
                vscVM = new MatchUpViewModel
                {
                    Id           = matchUp.Id,
                    VsChampionId = vscid,
                    VsChampion   = matchUp.VsChampion == null ? null : new ChampionViewModel {
                        ImageSrc = matchUp.VsChampion.Logo,
                        Name     = matchUp.VsChampion.Name
                    },
                    PrimaryRuneCategoryId   = matchUp.MainChampionRunes.PrimaryMainRune.RuneCategory.Id,
                    SecondaryRuneCategoryId = matchUp.MainChampionRunes.SecondaryRune1.RuneCategory.Id,
                    PrimaryMainRuneId       = matchUp.MainChampionRunes.PrimaryMainRune.Id,
                    PrimaryLevel1RuneId     = matchUp.MainChampionRunes.PrimaryRune1.Id,
                    PrimaryLevel2RuneId     = matchUp.MainChampionRunes.PrimaryRune2.Id,
                    PrimaryLevel3RuneId     = matchUp.MainChampionRunes.PrimaryRune3.Id,
                    SecondaryLevel1RuneId   = matchUp.MainChampionRunes.SecondaryRune1.Id,
                    SecondaryLevel2RuneId   = matchUp.MainChampionRunes.SecondaryRune2.Id,
                    SecondaryLevel3RuneId   = matchUp.MainChampionRunes.SecondaryRune3.Id,
                    StrongerEarly           = matchUp.StrongerEarly,
                    StrongerMid             = matchUp.StrongerMid,
                    StrongerLate            = matchUp.StrongerLate,
                    Items = matchUp.ItemSets.Select(y => new ItemViewModel
                    {
                        Name        = y.Item.Name,
                        ImageSrc    = y.Item.Logo,
                        Description = y.Item.Description
                    }),
                    AllRuneCategories = _context.RuneCategories.Select(y => new RuneCategoriesViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllSecondaryRuneCategories = _context.RuneCategories.Select(y => new RuneCategoriesViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllMainRunes = _context.MainRunes
                                   .Where(y => y.RuneCategory.Id == matchUp.MainChampionRunes.PrimaryMainRune.RuneCategory.Id)
                                   .OrderBy(y => y.Sort)
                                   .Select(y => new MainRunesViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }).ToList(),
                    AllLevel1Runes = _context.Runes
                                     .Where(y => y.LevelRune == 1 && y.RuneCategory.Id == matchUp.MainChampionRunes.PrimaryMainRune.RuneCategory.Id)
                                     .OrderBy(y => y.Sort)
                                     .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllLevel2Runes = _context.Runes
                                     .Where(y => y.LevelRune == 2 && y.RuneCategory.Id == matchUp.MainChampionRunes.PrimaryMainRune.RuneCategory.Id)
                                     .OrderBy(y => y.Sort)
                                     .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllLevel3Runes = _context.Runes
                                     .Where(y => y.LevelRune == 3 && y.RuneCategory.Id == matchUp.MainChampionRunes.PrimaryMainRune.RuneCategory.Id)
                                     .OrderBy(y => y.Sort)
                                     .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllLevel1SecondaryRunes = _context.Runes
                                              .Where(y => y.LevelRune == 1 && y.RuneCategory.Id == matchUp.MainChampionRunes.SecondaryRune1.RuneCategory.Id)
                                              .OrderBy(y => y.Sort)
                                              .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllLevel2SecondaryRunes = _context.Runes
                                              .Where(y => y.LevelRune == 2 && y.RuneCategory.Id == matchUp.MainChampionRunes.SecondaryRune1.RuneCategory.Id)
                                              .OrderBy(y => y.Sort)
                                              .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllLevel3SecondaryRunes = _context.Runes
                                              .Where(y => y.LevelRune == 3 && y.RuneCategory.Id == matchUp.MainChampionRunes.SecondaryRune1.RuneCategory.Id)
                                              .OrderBy(y => y.Sort)
                                              .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                };
            }
            MainPageViewModel model = new MainPageViewModel
            {
                cid         = cid,
                vscid       = vscid,
                Champion    = mainChamp,
                VsChampion  = vscVM,
                AllVsChamps = _context.MatchUps.Include(x => x.VsChampion).Where(x => x.MainChampion.Id == cid).Select(x => new MatchUpViewModel
                {
                    WinRate    = x.WinRate,
                    VsChampion = new ChampionViewModel
                    {
                        Id       = x.VsChampion.Id,
                        Name     = x.VsChampion.Name,
                        ImageSrc = x.VsChampion.Logo
                    }
                }).ToList()
            };


            return(View(model));
        }
예제 #2
0
        private void AddAllCollections(MatchUpViewModel model, int cid)
        {
            model.AllChampions = _context.Champions.Where(x => x.Id != cid).Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            }).ToList();
            model.AllRuneCategories = _context.RuneCategories.Select(x => new RuneCategoriesViewModel
            {
                Id          = x.Id,
                ImageSrc    = x.Logo,
                Description = x.Description
            }).ToList();
            model.AllMainRunes = _context.MainRunes
                                 .Include(x => x.RuneCategory)
                                 .OrderBy(x => x.Sort)
                                 .Select(x => new MainRunesViewModel
            {
                Id             = x.Id,
                RuneCategoryId = x.RuneCategory.Id,
                ImageSrc       = x.Logo,
                Description    = x.Description
            }).ToList();

            #region Rune Levels
            model.AllLevel1Runes = _context.Runes
                                   .Where(x => x.LevelRune == 1)
                                   .Include(x => x.RuneCategory)
                                   .OrderBy(x => x.Sort)
                                   .Select(x => new RuneViewModel
            {
                Id             = x.Id,
                RuneCategoryId = x.RuneCategory.Id,
                ImageSrc       = x.Logo,
                Description    = x.Description
            }).ToList();

            model.AllLevel2Runes = _context.Runes
                                   .Where(x => x.LevelRune == 2)
                                   .Include(x => x.RuneCategory)
                                   .OrderBy(x => x.Sort)
                                   .Select(x => new RuneViewModel
            {
                Id             = x.Id,
                RuneCategoryId = x.RuneCategory.Id,
                ImageSrc       = x.Logo,
                Description    = x.Description
            }).ToList();

            model.AllLevel3Runes = _context.Runes
                                   .Where(x => x.LevelRune == 3)
                                   .Include(x => x.RuneCategory)
                                   .OrderBy(x => x.Sort)
                                   .Select(x => new RuneViewModel
            {
                Id             = x.Id,
                RuneCategoryId = x.RuneCategory.Id,
                ImageSrc       = x.Logo,
                Description    = x.Description
            }).ToList();
            #endregion


            model.AllSecondaryRuneCategories = _context.RuneCategories
                                               .Select(x => new RuneCategoriesViewModel
            {
                Id          = x.Id,
                ImageSrc    = x.Logo,
                Description = x.Description
            }).ToList();



            model.AllLevel1SecondaryRunes = _context.Runes
                                            .Where(x => x.LevelRune == 1)
                                            .Include(x => x.RuneCategory)
                                            .OrderBy(x => x.Sort)
                                            .Select(x => new RuneViewModel
            {
                Id             = x.Id,
                RuneCategoryId = x.RuneCategory.Id,
                ImageSrc       = x.Logo,
                Description    = x.Description
            }).ToList();

            model.AllLevel2SecondaryRunes = _context.Runes
                                            .Where(x => x.LevelRune == 2)
                                            .Include(x => x.RuneCategory)
                                            .OrderBy(x => x.Sort)
                                            .Select(x => new RuneViewModel
            {
                Id             = x.Id,
                RuneCategoryId = x.RuneCategory.Id,
                ImageSrc       = x.Logo,
                Description    = x.Description
            }).ToList();

            model.AllLevel3SecondaryRunes = _context.Runes
                                            .Where(x => x.LevelRune == 3)
                                            .Include(x => x.RuneCategory)
                                            .OrderBy(x => x.Sort)
                                            .Select(x => new RuneViewModel
            {
                Id             = x.Id,
                RuneCategoryId = x.RuneCategory.Id,
                ImageSrc       = x.Logo,
                Description    = x.Description
            }).ToList();
        }
예제 #3
0
        // GET: ItemsController/Create
        public ActionResult AddEdit(int cid, int id)
        {
            var model = new MatchUpViewModel
            {
                Items = new List <ItemViewModel>()
            };
            var item = _context.MatchUps.Where(c => c.Id == id)
                       .Include(x => x.VsChampion)
                       .Include(x => x.MainChampionRunes)
                       .ThenInclude(x => x.PrimaryMainRune)
                       .ThenInclude(y => y.RuneCategory)
                       .Include(x => x.MainChampionRunes)
                       .ThenInclude(x => x.PrimaryRune1)
                       .Include(x => x.MainChampionRunes)
                       .ThenInclude(x => x.PrimaryRune2)
                       .Include(x => x.MainChampionRunes)
                       .ThenInclude(x => x.PrimaryRune3)
                       .Include(x => x.MainChampionRunes)
                       .ThenInclude(x => x.SecondaryRune1)
                       .ThenInclude(y => y.RuneCategory)
                       .Include(x => x.MainChampionRunes)
                       .ThenInclude(x => x.SecondaryRune2)
                       .Include(x => x.MainChampionRunes)
                       .ThenInclude(x => x.SecondaryRune3)
                       .Include(x => x.ItemSets)
                       .ThenInclude(x => x.Item)
                       .FirstOrDefault();

            if (item != null)
            {
                model.Id            = id;
                model.ItemIDs       = string.Join(",", item.ItemSets.Select(x => x.Item.Id));
                model.VsChampionId  = item.VsChampion?.Id;
                model.WinRate       = item.WinRate;
                model.StrongerEarly = item.StrongerEarly;
                model.StrongerMid   = item.StrongerMid;
                model.StrongerLate  = item.StrongerLate;
                model.Items         = item.ItemSets
                                      .OrderBy(x => x.Sort)
                                      .Select(x => new ItemViewModel
                {
                    Id          = x.Item.Id,
                    Name        = x.Item.Name,
                    Description = x.Item.Description,
                    ImageSrc    = x.Item.Logo
                });
                model.PrimaryMainRuneId       = item.MainChampionRunes.PrimaryMainRune.Id;
                model.PrimaryLevel1RuneId     = item.MainChampionRunes.PrimaryRune1.Id;
                model.PrimaryLevel2RuneId     = item.MainChampionRunes.PrimaryRune2.Id;
                model.PrimaryLevel3RuneId     = item.MainChampionRunes.PrimaryRune3.Id;
                model.SecondaryLevel1RuneId   = item.MainChampionRunes.SecondaryRune1.Id;
                model.SecondaryLevel2RuneId   = item.MainChampionRunes.SecondaryRune2.Id;
                model.SecondaryLevel3RuneId   = item.MainChampionRunes.SecondaryRune3.Id;
                model.PrimaryRuneCategoryId   = item.MainChampionRunes.PrimaryMainRune.RuneCategory.Id;
                model.SecondaryRuneCategoryId = item.MainChampionRunes.SecondaryRune1.RuneCategory.Id;
            }
            AddAllCollections(model, cid);

            ViewData["cid"] = cid;
            return(View(model));
        }
예제 #4
0
        public ActionResult AddEdit(int cid, MatchUpViewModel model)
        {
            var ids = model.ItemIDs?
                      .Split(",", StringSplitOptions.RemoveEmptyEntries)
                      .Select(x => int.Parse(x)).ToList() ?? new List <int>();

            if (ModelState.IsValid)
            {
                var item = _context.MatchUps
                           .Include(x => x.VsChampion)
                           .Include(x => x.MainChampionRunes)
                           .ThenInclude(x => x.PrimaryMainRune)
                           .ThenInclude(y => y.RuneCategory)
                           .Include(x => x.MainChampionRunes)
                           .ThenInclude(x => x.PrimaryRune1)
                           .Include(x => x.MainChampionRunes)
                           .ThenInclude(x => x.PrimaryRune2)
                           .Include(x => x.MainChampionRunes)
                           .ThenInclude(x => x.PrimaryRune3)
                           .Include(x => x.MainChampionRunes)
                           .ThenInclude(x => x.SecondaryRune1)
                           .ThenInclude(y => y.RuneCategory)
                           .Include(x => x.MainChampionRunes)
                           .ThenInclude(x => x.SecondaryRune2)
                           .Include(x => x.MainChampionRunes)
                           .ThenInclude(x => x.SecondaryRune3)
                           .Include(x => x.ItemSets)
                           .ThenInclude(x => x.Item)
                           .FirstOrDefault(x => x.Id == model.Id);
                if (item == null)
                {
                    item = new Data.Models.MatchUp()
                    {
                        MainChampionRunes = new Data.Models.ChampionRunes(),
                        ItemSets          = new List <ItemSet>()
                    };
                    _context.MatchUps.Add(item);
                }

                item.WinRate       = model.WinRate;
                item.StrongerEarly = model.StrongerEarly;
                item.StrongerMid   = model.StrongerMid;
                item.StrongerLate  = model.StrongerLate;
                item.MainChampion  = _context.Champions.Where(x => x.Id == cid).FirstOrDefault();
                item.VsChampion    = _context.Champions.Where(x => x.Id == model.VsChampionId).FirstOrDefault();
                item.MainChampionRunes.PrimaryMainRune = _context.MainRunes.Where(x => x.Id == model.PrimaryMainRuneId).FirstOrDefault();
                item.MainChampionRunes.PrimaryRune1    = _context.Runes.Where(x => x.Id == model.PrimaryLevel1RuneId).FirstOrDefault();
                item.MainChampionRunes.PrimaryRune2    = _context.Runes.Where(x => x.Id == model.PrimaryLevel2RuneId).FirstOrDefault();
                item.MainChampionRunes.PrimaryRune3    = _context.Runes.Where(x => x.Id == model.PrimaryLevel3RuneId).FirstOrDefault();
                item.MainChampionRunes.SecondaryRune1  = _context.Runes.Where(x => x.Id == model.SecondaryLevel1RuneId).FirstOrDefault();
                item.MainChampionRunes.SecondaryRune2  = _context.Runes.Where(x => x.Id == model.SecondaryLevel2RuneId).FirstOrDefault();
                item.MainChampionRunes.SecondaryRune3  = _context.Runes.Where(x => x.Id == model.SecondaryLevel3RuneId).FirstOrDefault();

                _context.ItemSets.RemoveRange(item.ItemSets.Where(x => !ids.Contains(x.Item.Id)));
                var newItemSets = ids.Where(x => !item.ItemSets.Any(y => y.Item.Id == x)).Select(x => new ItemSet
                {
                    Item = _context.Items.FirstOrDefault(y => y.Id == x)
                });
                foreach (var itemSet in newItemSets)
                {
                    item.ItemSets.Add(itemSet);
                }
                for (int i = 0; i < ids.Count(); i++)
                {
                    item.ItemSets.First(x => x.Item.Id == ids[i]).Sort = i;
                }

                _context.SaveChanges();
                return(RedirectToAction(nameof(Index), new { cid }));
            }
            model.Items = _context.ItemSets
                          .Where(x => ids.Contains(x.Item.Id))
                          .OrderBy(x => x.Sort)
                          .Select(x => new ItemViewModel
            {
                Id          = x.Item.Id,
                Name        = x.Item.Name,
                Description = x.Item.Description,
                ImageSrc    = x.Item.Logo
            });

            AddAllCollections(model, cid);

            ViewData["cid"] = cid;
            return(View(model));
        }