Ejemplo n.º 1
0
        internal void SetSelectListItems(ProductProductOverviewVM PPOVM)
        {
            var sizeArray  = Size.ToArray();
            var colorArray = Color.ToArray();
            var brandArray = Brand.ToArray();

            SelectListItem[] priceSpans = new SelectListItem[] { new SelectListItem {
                                                                     Text = "Maxpris", Value = "0"
                                                                 },
                                                                 new SelectListItem {
                                                                     Text = "1000", Value = "1"
                                                                 },
                                                                 new SelectListItem {
                                                                     Text = "1500", Value = "2"
                                                                 }, new SelectListItem {
                                                                     Text = "2000", Value = "3"
                                                                 },
                                                                 new SelectListItem {
                                                                     Text = "2500", Value = "4"
                                                                 } };

            List <SelectListItem> sizeList  = new List <SelectListItem>();
            List <SelectListItem> colorList = new List <SelectListItem>();
            List <SelectListItem> brandList = new List <SelectListItem>();

            sizeList.Add(new SelectListItem {
                Text = "Storlek", Value = "0"
            });
            colorList.Add(new SelectListItem {
                Text = "Färg", Value = "0"
            });
            brandList.Add(new SelectListItem {
                Text = "Märke", Value = "0"
            });

            for (int i = 0; i < sizeArray.Length; i++)
            {
                var tempSize = new SelectListItem {
                    Text = sizeArray[i].SizeName, Value = (i + 2).ToString()
                };
                sizeList.Add(tempSize);
            }

            for (int i = 0; i < colorArray.Length; i++)
            {
                var tempColor = new SelectListItem {
                    Text = colorArray[i].ColorName, Value = (i + 1).ToString()
                };
                colorList.Add(tempColor);
            }

            for (int i = 0; i < brandArray.Length; i++)
            {
                var tempBrand = new SelectListItem {
                    Text = brandArray[i].BrandName, Value = (i + 1).ToString()
                };
                brandList.Add(tempBrand);
            }
            PPOVM.BrandArray = brandList.ToArray();
            PPOVM.SizeArray  = sizeList.ToArray();
            PPOVM.ColorArray = colorList.ToArray();
            PPOVM.PriceArray = priceSpans;
        }
Ejemplo n.º 2
0
        internal ProductProductOverviewVM GetOverview(char id, string link)
        {
            List <ProductThumbnail> thumbnailList          = new List <ProductThumbnail>();
            List <Product>          listOfProductsToReturn = new List <Entities.Product>();
            List <Product>          allProductsToFilter    = new List <Entities.Product>();

            allProductsToFilter = Product.ToList();


            List <Brand> allBrands = Brand.ToList();
            List <Model> allModels = Model.ToList();
            List <Color> allColors = Color.ToList();
            List <Size>  allSizes  = Size.ToList();

            //check if id is not null
            if (int.TryParse(id.ToString(), out int result))
            {
                if (link == "Visa alla")
                {
                    if (id == '3')
                    {
                        allProductsToFilter = allProductsToFilter.Where(p => p.ProdQty > 0).ToList();
                    }
                    else
                    {
                        allProductsToFilter = allProductsToFilter.Where(p => p.ProdArtNr.StartsWith(id)).ToList();
                    }
                }
                else if (id == '1' && link != null)
                {
                    string[] arr = new string[3];
                    arr[0] = "10013";
                    arr[1] = "10082";
                    arr[2] = "10083";

                    if (link == "Businesskor")
                    {
                        arr[0] = "10043";
                        arr[1] = "10073";
                        arr[2] = "10022";
                    }

                    else if (link == "Outdoorskor")
                    {
                        arr[0] = "10052";
                        arr[1] = "10066";
                        arr[2] = "10032";
                    }

                    else if (link == "Finskor")
                    {
                        arr[0] = "10106";
                        arr[1] = "10092";
                        arr[2] = "10093";
                    }
                    List <Product> tempList = new List <Product>();

                    for (int i = 0; i < arr.Length; i++)
                    {
                        tempList.Add(allProductsToFilter.First(p => p.ProdArtNr.Contains(arr[i])));
                    }
                    allProductsToFilter = tempList;
                }
                else if (id == '2')
                {
                    int prodbrand = 6;

                    if (link == "Bälten")
                    {
                        prodbrand = 7;
                    }
                    else if (link == "Näsdukar")
                    {
                        prodbrand = 8;
                    }
                    allProductsToFilter = allProductsToFilter.Where(p => p.ProdArtNr.StartsWith(id)).Where(p => p.ProdBrandId == prodbrand).ToList();
                }
                else if (id == '3')
                {
                    int brandID = allBrands.First(b => b.BrandName == link).BrandId;
                    allProductsToFilter = allProductsToFilter.Where(p => p.ProdBrandId == brandID).ToList();
                }
            }
            else if (link != null)
            {
                int brandID = allBrands.First(b => b.BrandName == link).BrandId;
                allProductsToFilter = allProductsToFilter.Where(p => p.ProdBrandId == brandID).ToList();
            }

            foreach (var item in allProductsToFilter)
            {
                if (listOfProductsToReturn.Count == 0)
                {
                    listOfProductsToReturn.Add(item);
                }
                else
                {
                    bool productFound = false;

                    foreach (var product in listOfProductsToReturn)
                    {
                        if (product.ProdArtNr.Substring(0, 5) == item.ProdArtNr.Substring(0, 5))
                        {
                            productFound = true;
                            break;
                        }
                    }
                    if (!productFound)
                    {
                        listOfProductsToReturn.Add(item);
                    }
                }
            }

            foreach (var item in listOfProductsToReturn)
            {
                string currBrandName = allBrands.FirstOrDefault(b => b.BrandId == item.ProdBrandId).BrandName;
                string currModelName = allModels.FirstOrDefault(m => m.ModelId == item.ProdModelId).ModelName;
                string currSizeName  = allSizes.FirstOrDefault(s => s.SizeId == item.ProdSizeId).SizeName;
                string currColorName = allColors.FirstOrDefault(c => c.ColorId == item.ProdColorId).ColorName;
                thumbnailList.Add(new ProductThumbnail
                {
                    ImgPath        = $"{item.ProdArtNr.Remove(item.ProdArtNr.Length - 2)}_1.jpg",
                    ArticleNrShort = item.ProdArtNr.Substring(0, 5),
                    Brand          = currBrandName,
                    Model          = currModelName,
                    Price          = Convert.ToInt32(item.ProdPrice),
                    Size           = currSizeName,
                    Color          = currColorName
                });
            }
            ProductProductOverviewVM PPOVM = new ProductProductOverviewVM {
                ProdThumbnails = thumbnailList.ToArray()
            };

            SetSelectListItems(PPOVM);

            return(PPOVM);
        }