Exemplo n.º 1
0
        public ActionResult GetCards(SetsVM vm)
        {
            using (var context = new Context())
            {
                var setIdsToInclude = vm.Sets.Where(s => s.IncludeBlack || s.IncludeBlue || s.IncludeColorless || s.IncludeGreen ||
                                                    s.IncludeMulti || s.IncludeRed || s.IncludeWhite).Select(s => s.Id);
                var setsToInclude = context.Sets.Where(s => setIdsToInclude.Contains(s.Id)).ToList();

                var cards = setsToInclude.SelectMany(s => s.GetCardsWithColorIdentity(_getColorIdentitiesToInclude(vm, s.Id)));
                var model = new CardsVM
                {
                    Cards = cards.Select(c => new CardVM
                    {
                        Id       = c.Id,
                        Name     = c.Name,
                        Set      = c.Set.Name,
                        ManaCost = c.ManaCost,
                        Rarity   = c.Rarity,
                        Amount   = 0
                    }).OrderBy(c => c.Rarity).ToList()
                };

                return(View("Cards", model));
            }
        }
Exemplo n.º 2
0
        // GET: Cards
        public ActionResult Index()
        {
            using (var context = new Context())
            {
                var sets  = context.Sets;
                var model = new SetsVM
                {
                    Sets = sets.Select(s => new SetVM
                    {
                        Id   = s.Id,
                        Name = s.Name
                    }).OrderByDescending(s => s.Id).ToList()
                };

                return(View(model));
            }
        }
Exemplo n.º 3
0
        public IActionResult Index(SetsVM obj)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; //get userId of user who log in

            var list = _db.Sets.Where(x => x.ApplicationUserId == userId).ToList();

            obj.SetsList = list.Select(i => new SelectListItem
            {
                Text  = i.Name,
                Value = i.Id.ToString()
            });

            HttpContext.Session.SetInt32(SD.ssSetId, obj.SetId); //When we back from Edit page to Index, we need SetId


            return(View(obj));
        }
Exemplo n.º 4
0
        private IEnumerable <ColorIdentity> _getColorIdentitiesToInclude(SetsVM sets, int setId)
        {
            var set    = sets.Sets.SingleOrDefault(s => s.Id == setId);
            var colors = new List <ColorIdentity>();

            if (set.IncludeBlack)
            {
                colors.Add(ColorIdentity.Black);
            }

            if (set.IncludeBlue)
            {
                colors.Add(ColorIdentity.Blue);
            }

            if (set.IncludeColorless)
            {
                colors.Add(ColorIdentity.Colorless);
            }

            if (set.IncludeGreen)
            {
                colors.Add(ColorIdentity.Green);
            }

            if (set.IncludeMulti)
            {
                colors.Add(ColorIdentity.Multi);
            }

            if (set.IncludeRed)
            {
                colors.Add(ColorIdentity.Red);
            }

            if (set.IncludeWhite)
            {
                colors.Add(ColorIdentity.White);
            }

            return(colors);
        }
Exemplo n.º 5
0
        public IActionResult Index()
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; //get userId of user who log in
            var obj    = new SetsVM();

            if (HttpContext.Session.GetInt32(SD.ssSetId) != null)
            {
                obj.SetId = (int)HttpContext.Session.GetInt32(SD.ssSetId);
                HttpContext.Session.Remove(SD.ssSetId);
            }

            var list = _db.Sets.Where(x => x.ApplicationUserId == userId).ToList();

            obj.SetsList = list.Select(i => new SelectListItem
            {
                Text  = i.Name,
                Value = i.Id.ToString()
            });

            return(View(obj));
        }
Exemplo n.º 6
0
        public ActionResult SetDetails(int id, string filterColor = "", bool orderByRarity = false)
        {
            var model = new SetsVM {
                Id = id
            };

            using (var context = new Context())
            {
                var set = context.Sets.Where(s => s.Id == id).FirstOrDefault();

                if (set == null)
                {
                    return(new HttpNotFoundResult());
                }

                model.Name  = set.Name;
                model.Cards = set.Cards.Select(c => new CardVM
                {
                    Id          = c.Id,
                    Name        = c.Name,
                    ManaCost    = c.ManaCost,
                    Type        = c.Type,
                    Rarity      = c.Rarity,
                    AmountToAdd = 0,
                    Price       = context.CardPricing.FirstOrDefault(cc => cc.Card.Id == c.Id)?.Price
                }).ToList();
            }

            if (!string.IsNullOrWhiteSpace(filterColor))
            {
                switch (filterColor)
                {
                case "black":
                    model.Cards = model.Cards.Where(c => c.ManaCost != null && c.ManaCost.Contains("B"));
                    break;

                case "white":
                    model.Cards = model.Cards.Where(c => c.ManaCost != null && c.ManaCost.Contains("W"));
                    break;

                case "blue":
                    model.Cards = model.Cards.Where(c => c.ManaCost != null && c.ManaCost.Contains("U"));
                    break;

                case "green":
                    model.Cards = model.Cards.Where(c => c.ManaCost != null && c.ManaCost.Contains("G"));
                    break;

                case "red":
                    model.Cards = model.Cards.Where(c => c.ManaCost != null && c.ManaCost.Contains("R"));
                    break;

                case "neutral":
                    model.Cards = model.Cards.Where(c => c.ManaCost == null || (!c.ManaCost.Contains("B") &&
                                                                                !c.ManaCost.Contains("W") && !c.ManaCost.Contains("U") && !c.ManaCost.Contains("G") &&
                                                                                !c.ManaCost.Contains("R")));
                    break;

                case "multi":
                    model.Cards = model.Cards.Where(c => _cardIsMultiColored(c));
                    break;

                default:
                    break;
                }
            }

            if (orderByRarity)
            {
                model.Cards = model.Cards.OrderBy(c => c.Name).OrderBy(c => c.Rarity);
            }

            return(View("SetDetails", model));
        }