コード例 #1
0
        private async Task PopulateStoreIndexViewModelFromGet(StoreIndexViewModel model)
        {
            model.StoreListings = model.StoreListings.OrderBy(l => l.ListingName).ToList();

            //if (User.Identity.IsAuthenticated)
            //{
                model.LoggedInUser = await storeService.GetCurrentUser();
            //}

            List<Platform> platforms = storeService.GetPlatforms().ToList();

            model.StorePlatforms = storeService.GetPlatforms().ToList();

            /*foreach (Platform platform in platforms)
            {
                if (model.StoreListings.Any(l => l.ContainsPlatform(platform)))
                {
                    model.StorePlatforms.Add(platform);
                }
            }*/

            model.StorePlatforms.OrderBy(p => p.PlatformName).ToList();
            model.FullNavList = CreateStoreControllerStoreNavList(model);

            List<SelectedTagMapping> tagMappings = new List<SelectedTagMapping>();

            foreach (Tag tag in storeService.GetTags())
            {
                if (model.StoreListings.Any(l => l.ContainsTag(tag)))
                {
                    tagMappings.Add(new SelectedTagMapping(tag, false));
                }
            }

            model.SelectedTagMappings = tagMappings.OrderBy(t => t.StoreTag.TagName).ToList();

            List<SelectedProductCategoryMapping> categoryMappings = new List<SelectedProductCategoryMapping>();

            foreach (ProductCategory category in storeService.GetProductCategories())
            {
                if (model.StoreListings.Any(l => l.ContainsProductCategory(category)))
                {
                    categoryMappings.Add(new SelectedProductCategoryMapping(category, false));
                }
            }

            model.SelectedProductCategoryMappings = categoryMappings.OrderBy(c => c.ProductCategory.CategoryString).ToList();
        }
コード例 #2
0
        // Populate StoreIndexViewModel for various actions
        private async Task PopulateStoreIndexViewModelFromPostback(StoreIndexViewModel model)
        {
            //if (User.Identity.IsAuthenticated)
            //{
                model.LoggedInUser = await storeService.GetCurrentUser();
            //}

            if (!String.IsNullOrEmpty(model.SearchText))//model.SearchTextBool == true && 
            {
                if (!String.IsNullOrEmpty(model.SearchText))
                {
                    model.StoreListings = model.StoreListings.Where(l => l.ListingName.ToLower().Contains(model.SearchText.Trim().ToLower())).ToList();
                }
            }

            foreach (SelectedProductCategoryMapping mapping in model.SelectedProductCategoryMappings)
            {
                if (model.CategoryToChange == mapping.ProductCategory.ProductCategoryID)
                {
                    mapping.IsSelected = !mapping.IsSelected;
                }

                mapping.ProductCategory = storeService.GetProductCategoryByID(mapping.ProductCategory.ProductCategoryID);

                if (mapping.IsSelected)
                {
                    model.StoreListings = model.StoreListings.Where(l => l.ContainsProductCategory(mapping.ProductCategory)).ToList();
                }
            }

            model.CategoryToChange = 0;

            foreach (SelectedTagMapping mapping in model.SelectedTagMappings)
            {
                if (model.TagToChange == mapping.StoreTag.TagID)
                {
                    mapping.IsSelected = !mapping.IsSelected;
                }

                mapping.StoreTag = storeService.GetTagByID(mapping.StoreTag.TagID);

                if (mapping.IsSelected)
                {
                    model.StoreListings = model.StoreListings.Where(l => l.ContainsTag(mapping.StoreTag)).ToList();
                }
            }

            model.TagToChange = 0;

            if (model.SelectedPlatformID != 0)
            {
                Platform platform = storeService.GetPlatformByID(model.SelectedPlatformID);
                model.PreviousSelectedPlatformID = model.SelectedPlatformID;
                model.SelectedPlatformID = 0;
                model.PreviousSelectedDealsPlatformID = 0;
                model.StoreListings = model.StoreListings.Where(l => l.ContainsPlatform(platform)).ToList();
            }
            else if (model.PreviousSelectedPlatformID != 0)
            {
                Platform platform = storeService.GetPlatformByID(model.PreviousSelectedPlatformID);
                model.StoreListings = model.StoreListings.Where(l => l.ContainsPlatform(platform)).ToList();
            }

            if (model.SelectedDealsPlatformID != 0)
            {
                Platform platform = storeService.GetPlatformByID(model.SelectedDealsPlatformID);
                model.PreviousSelectedDealsPlatformID = model.SelectedDealsPlatformID;
                model.SelectedDealsPlatformID = 0;
                model.PreviousSelectedPlatformID = 0;
                model.StoreListings = model.StoreListings.Where(l => l.HasSale() && l.ContainsPlatform(platform)).ToList();
            }
            else if (model.PreviousSelectedDealsPlatformID != 0)
            {
                Platform platform = storeService.GetPlatformByID(model.PreviousSelectedDealsPlatformID);
                model.StoreListings = model.StoreListings.Where(l => l.HasSale() && l.ContainsPlatform(platform)).ToList();
            }

            if (model.BeginsWithFilter != noSelectionSentinel)
            {
                // this case means that the character was already selected and highlighted and now the user wishes to unselect it
                if (model.BeginsWithFilter == model.PreviousBeginsWithFilter)
                {
                    model.PreviousBeginsWithFilter = noSelectionSentinel;
                }
                else
                {
                    model.PreviousBeginsWithFilter = model.BeginsWithFilter;
                    if (model.BeginsWithFilter == '0')
                    {
                        model.StoreListings = model.StoreListings.Where(l => Regex.IsMatch(l.ListingName, @"^\d.*")).ToList();
                    }
                    else
                    {
                        model.StoreListings = model.StoreListings.Where(l => l.ListingName.ToLower().StartsWith(model.BeginsWithFilter.ToString())).ToList();
                    }
                }
                model.BeginsWithFilter = noSelectionSentinel;
            }
            else if (model.PreviousBeginsWithFilter != noSelectionSentinel)
            {
                if (model.PreviousBeginsWithFilter == '0')
                {
                    model.StoreListings = model.StoreListings.Where(l => Regex.IsMatch(l.ListingName, @"^\d.*")).ToList();
                }
                else
                {
                    model.StoreListings = model.StoreListings.Where(l => l.ListingName.ToLower().StartsWith(model.PreviousBeginsWithFilter.ToString())).ToList();
                }
            }

            if (model.FilterLibrary)
            {
                model.PreviousFilterLibrary = !model.PreviousFilterLibrary;

                if (model.PreviousFilterLibrary && HttpContext.User.Identity.IsAuthenticated)
                {
                    AppUser user = await storeService.GetCurrentUser();

                    if (user.OwnedGames != null)
                    {
                        model.StoreListings = model.StoreListings.Where(l => !user.OwnsListing(l)).ToList();
                    }
                }
            }

            if (model.FilterBlacklist)
            {
                model.PreviousFilterBlacklist = !model.PreviousFilterBlacklist;

                if (model.PreviousFilterBlacklist && HttpContext.User.Identity.IsAuthenticated)
                {
                    AppUser user = await storeService.GetCurrentUser();

                    if (user.BlacklistedListings != null)
                    {
                        model.StoreListings = model.StoreListings.Where(l => !user.BlacklistedListings.Contains(l)).ToList();
                    }
                }
            }

            if (model.AffordableFilter)
            {
                model.PreviousAffordableFilter = !model.PreviousAffordableFilter;
            }

            if (model.PreviousAffordableFilter && !model.CartAffordableFilter)
            {
                model.PreviousCartAffordableFilter = false;

                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    AppUser user = await storeService.GetCurrentUser();

                    int targetMaxPrice = user.Balance - user.ReservedBalance();

                    model.StoreListings = model.StoreListings.Where(l => l.SaleOrDefaultPrice() <= targetMaxPrice).ToList();
                }
            }

            if (model.CartAffordableFilter)
            {
                model.PreviousCartAffordableFilter = !model.PreviousCartAffordableFilter;
            }

            if (model.PreviousCartAffordableFilter)
            {
                model.PreviousAffordableFilter = false;

                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    AppUser user = await storeService.GetCurrentUser();

                    int targetMaxPrice = user.Balance - user.ReservedBalance() - user.GetCartTotal();

                    model.StoreListings = model.StoreListings.Where(l => l.SaleOrDefaultPrice() <= targetMaxPrice).ToList();
                }
            }

            if (model.GameSort > 0)
            {
                if (model.GameSort == 1)
                {
                    model.StoreListings = model.StoreListings.OrderBy(l => l.ListingName).ToList();
                }
                else
                {
                    model.StoreListings = model.StoreListings.OrderByDescending(l => l.ListingName).ToList();
                }
                model.PreviousGameSort = model.GameSort;
                model.PreviousPriceSort = 0;
                model.PreviousQuantitySort = 0;
            }
            else if (model.QuantitySort > 0)
            {
                if (model.QuantitySort == 1)
                {
                    model.StoreListings = model.StoreListings.OrderBy(l => l.Quantity).ToList();
                }
                else
                {
                    model.StoreListings = model.StoreListings.OrderByDescending(l => l.Quantity).ToList();
                }
                model.PreviousQuantitySort = model.QuantitySort;
                model.PreviousPriceSort = 0;
                model.PreviousGameSort = 0;
            }
            else if (model.PriceSort > 0)
            {
                if (model.PriceSort == 1)
                {
                    model.StoreListings = model.StoreListings.OrderBy(l => l.SaleOrDefaultPrice()).ToList();
                }
                else
                {
                    model.StoreListings = model.StoreListings.OrderByDescending(l => l.SaleOrDefaultPrice()).ToList();
                }
                model.PreviousPriceSort = model.PriceSort;
                model.PreviousGameSort = 0;
                model.PreviousQuantitySort = 0;
            }
            else if (model.PreviousGameSort > 0)
            {
                if (model.PreviousGameSort == 1)
                {
                    model.StoreListings = model.StoreListings.OrderBy(l => l.ListingName).ToList();
                }
                else
                {
                    model.StoreListings = model.StoreListings.OrderByDescending(l => l.ListingName).ToList();
                }
            }
            else if (model.PreviousQuantitySort > 0)
            {
                if (model.PreviousQuantitySort == 1)
                {
                    model.StoreListings = model.StoreListings.OrderBy(l => l.Quantity).ToList();
                }
                else
                {
                    model.StoreListings = model.StoreListings.OrderByDescending(l => l.Quantity).ToList();
                }
            }
            else if (model.PreviousPriceSort > 0)
            {
                if (model.PreviousPriceSort == 1)
                {
                    model.StoreListings = model.StoreListings.OrderBy(l => l.ListingPrice).ToList();
                }
                else
                {
                    model.StoreListings = model.StoreListings.OrderByDescending(l => l.ListingPrice).ToList();
                }
            }

            model.StorePlatforms = storeService.GetPlatforms().ToList();
            
            model.StorePlatforms.OrderBy(p => p.PlatformName).ToList();
            model.FullNavList = CreateStoreControllerStoreNavList(model);
        }
コード例 #3
0
        public async Task<ActionResult> Deals(string id = "all")
        {
            // conform to route convention by accepting "id" parameter, but assign it to a new variable to make it clear what purpose it serves
            string subsection = id;

            StoreIndexViewModel model = new StoreIndexViewModel();

            if (String.Compare(subsection.ToLower(), "all") == 0)
            {
                model.StoreListings = storeService.GetListingsWithDeals().ToList();
                ViewBag.Title = "All Deals";
            }
            else if (String.Compare(subsection.ToLower(), "daily") == 0)
            {
                model.StoreListings = storeService.GetListingsWithDeals().Where(l => l.HasDailyDeal()).ToList();
                ViewBag.Title = "Daily Deals";
            }
            else if (String.Compare(subsection.ToLower(), "weekly") == 0)
            {
                model.StoreListings = storeService.GetListingsWithDeals().Where(l => l.HasWeeklyDeal()).ToList();
                ViewBag.Title = "Weekly Deals";
            }
            else if (String.Compare(subsection.ToLower(), "other") == 0)
            {
                model.StoreListings = storeService.GetListingsWithDeals().Where(d => d.HasDailyDeal() == false && d.HasWeeklyDeal() == false).ToList();
                ViewBag.Title = "Other Deals";
            }
            else
            {
                return RedirectToAction("Deals", new { id = "all" });
            }

            await PopulateStoreIndexViewModelFromGet(model);

            model.FormName = "Deals";
            model.FormID = id;

            return View("Index", model);
        }
コード例 #4
0
        public async Task<ActionResult> Deals(StoreIndexViewModel model, string id)
        {
            // conform to route convention by accepting "id" parameter, but assign it to a new variable to make it clear what purpose it serves
            string subsection = id;

            if (String.Compare(subsection.ToLower(), "all") == 0)
            {
                model.StoreListings = storeService.GetListingsWithDeals().ToList();
                ViewBag.Title = "All Deals";
            }
            else if (String.Compare(subsection.ToLower(), "daily") == 0)
            {
                model.StoreListings = storeService.GetListingsWithDeals().Where(l => l.HasDailyDeal()).ToList();
                ViewBag.Title = "Daily Deals";
            }
            else if (String.Compare(subsection.ToLower(), "weekly") == 0)
            {
                model.StoreListings = storeService.GetListingsWithDeals().Where(l => l.HasWeeklyDeal()).ToList();
                ViewBag.Title = "Weekly Deals";
            }
            else if (String.Compare(subsection.ToLower(), "other") == 0)
            {
                model.StoreListings = storeService.GetListingsWithDeals().Where(d => d.HasDailyDeal() == false && d.HasWeeklyDeal() == false).ToList();
                ViewBag.Title = "Other Deals";
            }
            else
            {
                return RedirectToAction("Deals", new { id = "all", model = model });
            }

            bool filterOwnLibrary = model.FilterLibrary;

            await PopulateStoreIndexViewModelFromPostback(model);

            if (filterOwnLibrary == false && String.IsNullOrEmpty(model.FriendSteamID) == false)
            {
                model.StoreListings = storeService.FilterListingsByUserSteamID(model.StoreListings, model.FriendSteamID, System.Configuration.ConfigurationManager.AppSettings["steamAPIKey"]);
            }

            model.FormName = "Deals";
            model.FormID = id;

            ModelState.Clear();

            return View("Index", model);
        }
コード例 #5
0
        public async Task<ActionResult> Newest(string id = "")
        {
            StoreIndexViewModel model = new StoreIndexViewModel();

            DateTime maxDate = storeService.GetStockedStoreListings().Select(l => l.DateEdited).Max().Date;

            model.StoreListings = storeService.GetStockedStoreListings().Where(l => l.DateEdited.Date.CompareTo(maxDate) == 0).OrderBy(l => l.ListingName).ToList();

            await PopulateStoreIndexViewModelFromGet(model);

            model.FormName = "Newest";
            model.FormID = "";

            return View("Index", model);
        }
コード例 #6
0
        public async Task<ActionResult> Newest(StoreIndexViewModel model, string id = "")
        {
            DateTime maxDate = storeService.GetStockedStoreListings().Select(l => l.DateEdited).Max().Date;

            model.StoreListings = storeService.GetStockedStoreListings().Where(l => l.DateEdited.Date.CompareTo(maxDate) == 0).OrderBy(l => l.ListingName).ToList();

            bool filterOwnLibrary = model.FilterLibrary;

            await PopulateStoreIndexViewModelFromPostback(model);

            if (filterOwnLibrary == false && String.IsNullOrEmpty(model.FriendSteamID) == false)
            {
                model.StoreListings = storeService.FilterListingsByUserSteamID(model.StoreListings, model.FriendSteamID, System.Configuration.ConfigurationManager.AppSettings["steamAPIKey"]);
            }

            model.FormName = "Newest";
            model.FormID = "";

            ModelState.Clear();

            return View("Index", model);
        }
コード例 #7
0
        public async Task<ActionResult> Id(StoreIndexViewModel model, string id = "")
        {
            if (String.IsNullOrEmpty(id))
            {
                id = model.FriendSteamID;
            }

            if (String.IsNullOrEmpty(id))
            {
                return RedirectToAction("Index", new { model = model });
            }

            model.StoreListings = storeService.GetStockedStoreListings().ToList();

            bool filterOwnLibrary = model.FilterLibrary;

            await PopulateStoreIndexViewModelFromPostback(model);

            // don't want users filtering their own libraries along with their friend's library (this just doesn't make sense)
            // so if the passed in id is a relic make sure to 
            if (filterOwnLibrary == false)
            {
                model.StoreListings = storeService.FilterListingsByUserSteamID(model.StoreListings, id, System.Configuration.ConfigurationManager.AppSettings["steamAPIKey"]);
                model.FriendSteamID = id;
            }

            model.FormName = "Id";
            model.FormID = id;

            // Clear the ModelState so changes in the model are reflected when using HtmlHelpers (their default behavior is to not use changes made to the model when re-rendering a view, not what we want here)
            ModelState.Clear();

            return View("Index", model);
        }
コード例 #8
0
        public async Task<ActionResult> Id(string id = "")
        {
            if (String.IsNullOrEmpty(id))
            {
                return RedirectToAction("Index");
            }

            StoreIndexViewModel model = new StoreIndexViewModel();

            model.StoreListings = storeService.GetStockedStoreListings().ToList();

            await PopulateStoreIndexViewModelFromGet(model);

            model.StoreListings = storeService.FilterListingsByUserSteamID(model.StoreListings, id, System.Configuration.ConfigurationManager.AppSettings["steamAPIKey"]);
            model.FriendSteamID = id;

            model.FormName = "Id";
            model.FormID = id;

            return View("Index", model);
        }
コード例 #9
0
        public async Task<ActionResult> Index(StoreIndexViewModel model, string id = "")
        {
            model.StoreListings = storeService.GetStockedStoreListings().ToList();

            bool filterOwnLibrary = model.FilterLibrary;

            await PopulateStoreIndexViewModelFromPostback(model);

            if (filterOwnLibrary == false && String.IsNullOrEmpty(model.FriendSteamID) == false)
            {
                model.StoreListings = storeService.FilterListingsByUserSteamID(model.StoreListings, model.FriendSteamID, System.Configuration.ConfigurationManager.AppSettings["steamAPIKey"]);
            }

            await PopulateStoreIndexViewModelFromPostback(model);
            
            model.FormName = "Index";
            model.FormID = "";

            // Clear the ModelState so changes in the model are reflected when using HtmlHelpers (their default behavior is to not use changes made to the model when re-rendering a view, not what we want here)
            ModelState.Clear();

            return View(model);
        }
コード例 #10
0
        public async Task<ActionResult> Index(string id = "")
        {
            StoreIndexViewModel model = new StoreIndexViewModel();

            model.StoreListings = storeService.GetStockedStoreListings().ToList();

            await PopulateStoreIndexViewModelFromGet(model);
            model.FormName = "Index";
            model.FormID = "";

            return View(model);
        }
コード例 #11
0
        public List<NavGrouping> CreateStoreControllerStoreNavList(StoreIndexViewModel model)
        {
            List<NavGrouping> navList = new List<NavGrouping>();

            if (User.Identity.IsAuthenticated)
            {
                NavGrouping basicNav = new NavGrouping();
                basicNav.GroupingHeader = "Account";
                basicNav.NavItems = new List<NavItem>();
                NavItem basicNavItem = new NavItem();
                basicNavItem.DestinationName = "My Account";
                basicNavItem.Destination = "/Account/";
                basicNav.NavItems.Add(basicNavItem);
                basicNavItem = new NavItem();
                basicNavItem.DestinationName = "My Cart";
                basicNavItem.Destination = "/Cart/";
                basicNav.NavItems.Add(basicNavItem);

                navList.Add(basicNav);
            }

            NavGrouping actions = new NavGrouping();
            actions.GroupingHeader = "Actions";
            actions.NavItems = new List<NavItem>();
            NavItem clearSearch = new NavItem();
            clearSearch.DestinationName = "Clear Search";
            clearSearch.Destination = "/Store/";
            actions.NavItems.Add(clearSearch);

            navList.Add(actions);

            NavGrouping platforms = new NavGrouping();
            platforms.GroupingHeader = "Platforms";
            platforms.NavItems = new List<NavItem>();

            for (int i = 0; i < model.StorePlatforms.Count; i++)
            {
                NavItem navItem = new NavItem();
                navItem.IsFormSubmit = true;
                navItem.DestinationName = model.StorePlatforms[i].PlatformName; 
                navItem.FormName = "SelectedPlatformID";
                navItem.FormValue = model.StorePlatforms[i].PlatformID.ToString();
                navItem.FormID = storeFormID;

                platforms.NavItems.Add(navItem);
            }

            navList.Add(platforms);

            NavGrouping deals = new NavGrouping();
            deals.GroupingHeader = "Deals";
            deals.NavItems = new List<NavItem>();

            NavItem weeklyDeals = new NavItem();
            weeklyDeals.IsFormSubmit = true;
            weeklyDeals.FormID = storeFormID;
            weeklyDeals.FormAction = "/Store/Deals/weekly";
            weeklyDeals.DestinationName = "Weekly Deals";

            NavItem dailyDeals = new NavItem();
            dailyDeals.DestinationName = "Daily Deals";
            dailyDeals.IsFormSubmit = true;
            dailyDeals.FormID = storeFormID;
            dailyDeals.FormAction = "/Store/Deals/daily";

            NavItem newestListings = new NavItem();
            newestListings.DestinationName = "New Additions";
            newestListings.IsFormSubmit = true;
            newestListings.FormID = storeFormID;
            newestListings.FormAction = "/Store/Newest/";

            deals.NavItems.Add(weeklyDeals);
            deals.NavItems.Add(dailyDeals);
            deals.NavItems.Add(newestListings);

            navList.Add(deals);

            return navList;
        }