Esempio n. 1
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var accessories = await _common_repo.Get_All_By_Type(Constant.ACCESSORIES);

            var generes = await _gr_repo.Get_ALL_ActiveAsync();

            var result = await _cat_repo.Get_All_Async();

            if (result != null)
            {
                foreach (var x in result)
                {
                    x.AccessoriesTypes = accessories;
                    string platform_ids = x.Platform_Ids;
                    if (!string.IsNullOrEmpty(platform_ids))
                    {
                        platform_ids = platform_ids.Contains(",") ? platform_ids.Trim(',') : platform_ids;
                        if (platform_ids.Length > 0)
                        {
                            x.PlatformList = await _gp_repo.Get_Supported_N_Platforms(100, platform_ids);

                            x.GenereList = generes;
                        }
                    }
                }
            }
            return(View(result));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var generes = await _gr_repo.Get_ALL_ActiveAsync();

            var result = await _cat_repo.Get_All_Async();

            var accessories = await _common_repo.Get_All_By_Type(Constant.ACCESSORIES);

            var featureLinks = await _fea_repo.Get_All();

            if (result != null)
            {
                foreach (var x in result)
                {
                    x.AccessoriesTypes = accessories;
                    string platform_ids = x.Platform_Ids;
                    if (!string.IsNullOrEmpty(platform_ids))
                    {
                        platform_ids = platform_ids.Contains(",") ? platform_ids.Trim(',') : platform_ids;
                        if (platform_ids.Length > 0)
                        {
                            x.GenereList   = generes;
                            x.PlatformList = await _gp_repo.Get_Supported_N_Platforms(100, platform_ids);

                            foreach (var xx in x.PlatformList)
                            {
                                xx.FeatureLinks = featureLinks.Where(o => o.Reference_Id == xx.Id && o.Reference_Name == Constant.ImageCategory.PlatformImage).ToList();
                            }
                        }
                    }
                }
            }
            return(View(result));
        }
        public async Task <IActionResult> ListingPage1(string url, string g, string rd, string r, string c, string t, string order, int page = 1, int min = 0, int max = 0, int pegi = 0)
        {
            url = Regex.Replace(url, "[^a-zA-Z0-9]", "-");
            var platform = await _gp_repo.GetByUrlAsync(url);

            if (platform == null)
            {
                return(NotFound());
            }
            if (!platform.Active)
            {
                return(NotFound());
            }

            var genreList = await _gr_repo.Get_ALL_ActiveAsync();

            ViewBag.GenreList    = genreList;
            ViewBag.GenreUrl     = g;
            ViewBag.PageIndex    = page;
            ViewBag.Release_Date = rd;
            ViewBag.TypeGame     = t;
            ViewBag.Condition    = c;
            ViewBag.Ratings      = r;
            ViewBag.MinPrice     = min;
            ViewBag.orderby      = order;

            Game_Filter obj = new Game_Filter {
                Offset = 0, PageIndex = page, Rows = 20, Platform_Id = platform.Id
            };

            obj.Offset = (page - 1) * 20;
            string where_clouse = string.Empty;
            string where_withoutprice_clouse = string.Empty;

            if (obj.Platform_Id > 0)
            {
                where_clouse += string.Format(" AND t1.PlatformId={0} ", obj.Platform_Id); where_withoutprice_clouse += string.Format(" AND t1.PlatformId={0} ", obj.Platform_Id);
            }

            #region Genere Filters
            if (!string.IsNullOrEmpty(g))
            {
                string g_url = string.Empty;
                Models.Entity.Genere genre = null;
                if (g.Contains(","))
                {
                    var grs = g.Split(',').ToList();
                    grs = grs.Where(x => !string.IsNullOrEmpty(x)).ToList();
                    for (int index = 0; index < grs.Count; index++)
                    {
                        if (string.IsNullOrEmpty(grs[index]))
                        {
                            continue;
                        }
                        g_url = Regex.Replace(grs[index], "[^a-zA-Z0-9]", "-");
                        genre = genreList.FirstOrDefault(x => x.NameUrl.Equals(g_url, System.StringComparison.CurrentCultureIgnoreCase));
                        if (genre != null)
                        {
                            if (index == 0)
                            {
                                where_clouse += string.Format(" AND ( t1.Genres LIKE '%,{0},%' ", genre.Id); where_withoutprice_clouse += string.Format(" AND ( t1.Genres LIKE '%,{0},%' ", genre.Id);
                            }
                            if (index > 0)
                            {
                                where_clouse += string.Format(" OR t1.Genres LIKE '%,{0},%' ", genre.Id); where_withoutprice_clouse += string.Format(" OR t1.Genres LIKE '%,{0},%' ", genre.Id);
                            }
                            if (index == grs.Count - 1)
                            {
                                where_clouse += " ) "; where_withoutprice_clouse += " ) ";
                            }
                        }
                    }
                }
                else
                {
                    g_url = Regex.Replace(g, "[^a-zA-Z0-9]", "-");
                    genre = genreList.FirstOrDefault(x => x.NameUrl.Equals(g_url, System.StringComparison.CurrentCultureIgnoreCase));
                    if (genre != null)
                    {
                        where_clouse += string.Format(" AND t1.Genres LIKE '%,{0},%' ", genre.Id);
                        where_withoutprice_clouse += string.Format(" AND t1.Genres LIKE '%,{0},%' ", genre.Id);
                    }
                }
            }
            #endregion

            #region Release Date Filters
            if (!string.IsNullOrEmpty(rd))
            {
                if (rd.Contains(","))
                {
                    var rds = rd.Split(',').ToList();
                    rds = rds.Where(x => !string.IsNullOrEmpty(x)).ToList();
                    for (int index = 0; index < rds.Count; index++)
                    {
                        if (string.IsNullOrEmpty(rds[index]))
                        {
                            continue;
                        }
                        int days = 0;
                        switch (rds[index])
                        {
                        case "new-releases":
                            days = -180;
                            break;

                        case "last-30-days":
                            days = -30;
                            break;

                        case "last-90-days":
                            days = -90;
                            break;

                        case "best-of-2017":
                            days = -360;
                            break;
                        }
                        if (index == 0)
                        {
                            where_clouse += string.Format(" AND ( t1.First_release_date > dateadd(day, {0}, getdate()) ", days); where_withoutprice_clouse += string.Format(" AND ( t1.First_release_date > dateadd(day, {0}, getdate()) ", days);
                        }
                        if (index > 0)
                        {
                            where_clouse += string.Format(" OR t1.First_release_date > dateadd(day, {0}, getdate()) ", days); where_withoutprice_clouse += string.Format(" OR t1.First_release_date > dateadd(day, {0}, getdate()) ", days);
                        }
                        if (index == rds.Count - 1)
                        {
                            where_clouse += " ) "; where_withoutprice_clouse += " ) ";
                        }
                    }
                }
                else
                {
                    int days = 0;
                    switch (rd)
                    {
                    case "new-releases":
                        days = -180;
                        break;

                    case "last-30-days":
                        days = -30;
                        break;

                    case "last-90-days":
                        days = -90;
                        break;

                    case "best-of-2017":
                        days = -360;
                        break;
                    }
                    where_clouse += string.Format(" AND t1.First_release_date > dateadd(day, {0}, getdate()) ", days);
                    where_withoutprice_clouse += string.Format(" AND t1.First_release_date > dateadd(day, {0}, getdate()) ", days);
                }
            }
            #endregion

            #region Condition Filters
            if (!string.IsNullOrEmpty(c))
            {
                if (c.Contains(","))
                {
                    var cs = c.Split(',').ToList();
                    cs = cs.Where(x => !string.IsNullOrEmpty(x)).ToList();
                    for (int index = 0; index < cs.Count; index++)
                    {
                        int id = 0;
                        if (string.IsNullOrEmpty(cs[index]))
                        {
                            continue;
                        }
                        switch (cs[index])
                        {
                        case "new":
                            id = 1;
                            break;

                        case "pre-owned":
                            id = 2;
                            break;
                        }
                        if (index == 0)
                        {
                            where_clouse += string.Format(" AND ( t1.Condition_Id={0} ", id); where_withoutprice_clouse += string.Format(" AND ( t1.Condition_Id={0} ", id);
                        }
                        if (index > 0)
                        {
                            where_clouse += string.Format(" OR t1.Condition_Id={0} ", id); where_withoutprice_clouse += string.Format(" OR t1.Condition_Id={0} ", id);
                        }
                        if (index == cs.Count - 1)
                        {
                            where_clouse += " ) "; where_withoutprice_clouse += " ) ";
                        }
                    }
                }
                else
                {
                    switch (c)
                    {
                    case "new":
                        where_clouse += string.Format(" AND t1.Condition_Id={0} ", 1);
                        where_withoutprice_clouse += string.Format(" AND t1.Condition_Id={0} ", 1);
                        break;

                    case "pre-owned":
                        where_clouse += string.Format(" AND t1.Condition_Id={0} ", 2);
                        where_withoutprice_clouse += string.Format(" AND t1.Condition_Id={0} ", 2);
                        break;
                    }
                }
            }
            #endregion

            #region Price Filters
            if (min > 0)
            {
                where_clouse += string.Format(" AND t1.Selling_Price >= {0} ", min);
            }
            if (max > 0)
            {
                where_clouse += string.Format(" AND t1.Selling_Price <= {0} ", max);
            }
            #endregion

            #region PEGI Filters
            if (pegi > 0)
            {
                where_clouse += string.Format(" AND t1.PEGI_Rating = {0} ", pegi);
                where_withoutprice_clouse += string.Format(" AND t1.PEGI_Rating = {0} ", pegi);
            }
            #endregion

            #region Rating Filters
            if (!string.IsNullOrEmpty(r))
            {
                if (r.Contains(","))
                {
                    var rs = r.Split(',').ToList();
                    rs = rs.Where(x => !string.IsNullOrEmpty(x)).ToList();
                    for (int index = 0; index < rs.Count; index++)
                    {
                        if (string.IsNullOrEmpty(rs[index]))
                        {
                            continue;
                        }
                        int rate = 0;
                        switch (rs[index])
                        {
                        case "5-star":
                            rate = 5;
                            break;

                        case "4-star":
                            rate = 4;
                            break;

                        case "3-star":
                            rate = 3;
                            break;

                        case "2-star":
                            rate = 2;
                            break;

                        case "1-star":
                            rate = 1;
                            break;
                        }
                        if (index == 0)
                        {
                            where_clouse += string.Format(" AND ( ( t1.Rating >={0}) ", rate); where_withoutprice_clouse += string.Format(" AND ( ( t1.Rating >={0}) ", rate);
                        }
                        if (index > 0)
                        {
                            where_clouse += string.Format(" OR ( t1.Rating >={0}) ", rate); where_withoutprice_clouse += string.Format(" OR ( t1.Rating >={0}) ", rate);
                        }
                        if (index == rs.Count - 1)
                        {
                            where_clouse += " ) "; where_withoutprice_clouse += " ) ";
                        }
                    }
                }
                else
                {
                    int rate = 0;
                    switch (r)
                    {
                    case "5-star":
                        rate = 5;
                        break;

                    case "4-star":
                        rate = 4;
                        break;

                    case "3-star":
                        rate = 3;
                        break;

                    case "2-star":
                        rate = 2;
                        break;

                    case "1-star":
                        rate = 1;
                        break;
                    }
                    where_clouse += string.Format(" AND ( t1.Rating >={0} and t1.Rating <({0}+1)) ", rate);
                    where_withoutprice_clouse += string.Format(" AND ( t1.Rating >={0} and t1.Rating <({0}+1)) ", rate);
                }
            }
            #endregion

            #region OrderBy
            string orderby = string.Empty;
            switch (order)
            {
            case "Price low to high":
                orderby = " t1.Selling_Price asc ";
                break;

            case "Price high to low":
                orderby = " t1.Selling_Price desc ";
                break;

            case "Popularity":
                orderby = " t1.Popularity desc ";
                break;

            case "Best Sellers":
                orderby = " t1.IsBestSelling desc ";
                break;
            }
            #endregion

            #region Query Builder
            string query = string.Empty;
            query += " SELECT COUNT(t1.Id) as Total FROM [dbo].[Game_List_View_For_Display] t1 ";
            query += " WHERE t1.Id > 0 ";
            query += where_clouse;
            query += "; ";


            query += " SELECT t1.* ";
            query += " FROM [dbo].[Game_List_View_For_Display] t1 ";
            query += " WHERE t1.Id > 0 ";
            query += where_clouse;
            //query += " ORDER BY t1.First_release_date DESC, t1.Popularity DESC ";
            if (!string.IsNullOrEmpty(order))
            {
                query += " ORDER by " + orderby;
            }
            else
            {
                query += " ORDER BY t1.First_release_date DESC, t1.Popularity DESC ";
            }

            query += string.Format(" OFFSET {0} ROWS ", obj.Offset);
            query += string.Format(" FETCH NEXT {0} ROWS ONLY ", obj.Rows);
            query += "; ";
            query += " SELECT isnull(Max(Selling_price),0) as [MaxPrice] ";
            query += " FROM [dbo].[Game_List_View_For_Display] t1 ";
            query += " WHERE t1.Id > 0 ";
            query += where_withoutprice_clouse;
            #endregion


            platform.GameList = await _game_repo.GetPaginated_By_Custom_QueryAsync(query);

            foreach (var x in platform.GameList.PagedSet)
            {
                x.Platform = platform;
            }
            //ViewBag.MaxPrice = platform.GameList.PagedSet.OrderByDescending(x => x.Selling_Price).Select(x => x.Selling_Price).FirstOrDefault();
            ViewBag.MaxSelectedPrice = max == 0 ? platform.GameList.MaxPrice : max;
            ViewBag.MaxPrice         = platform.GameList.MaxPrice;
            return(View("ListingPage", platform));
        }