Example #1
0
        public Tuple <List <ProductVm>, List <Category>, CatelogVm> IndexTuple(long?id)
        {
            try
            {
                using (_db)
                {
                    #region --> Get Product and Category Details

                    var products = new List <ProductVm>();
                    if (id == 5)
                    {
                        products = CommonFunctions.GetProductsVms(null, 44);
                    }
                    else if (id == 43)
                    {
                        products = CommonFunctions.GetNewArrivalsProductsVms(null, 43);
                    }
                    else if (id == 8)
                    {
                        var db             = new DBEntities();
                        var productDetails = db.Products.Where(s => s.Category.RootCategoryId == 2).OrderByDescending(m => m.CreatedDate).ToList();
                        if (productDetails.Any())
                        {
                            var offers = db.Offers.Where(m => m.OfferId != 0).ToList();
                            products = productDetails.Select(s => new ProductVm
                            {
                                OfferTitle      = (s.OfferId != 0) ? offers.FirstOrDefault(m => m.OfferId == s.OfferId)?.Title : string.Empty,
                                CategoryId      = s.CategoryId,
                                CategoryName    = s.Category.Name,
                                CoverImage      = s.ProductImages.FirstOrDefault(k => k.ProductId == s.ProductId && k.CoverImage)?.ImageName,
                                FullDescription = s.FullDescription,
                                MRP             = s.MRP,
                                Price           = s.Price,
                                ProductDetails  = s.ProductDetails.Where(k => k.ProductId == s.ProductId).Select(k => new ProductDetailsVm {
                                    ColorId = k.ColorId, SizeId = k.SizeId
                                }).ToList(),
                                ProductFeatureDetails = s.ProductFeatures.Where(k => k.ProductId == s.ProductId).Select(k => new ProductFeatureDetailsVm {
                                    FeatureType = k.FeatureType, FeatureValue = k.FeatureValue
                                }).ToList(),
                                ProductId            = s.ProductId,
                                ProductName          = s.ProductName,
                                SKU                  = s.SKU,
                                ShortDescription     = s.ShortDescription,
                                TAX                  = s.TAX,
                                Tag                  = s.Tag,
                                ProductImagesDetails = s.ProductImages.Where(k => k.ProductId == s.ProductId).Select(k => new ProductImageArrayVm {
                                    ProductId = k.ProductId, ImageName = k.ImageName, ProductImageId = k.ProductImageId, iscover = k.CoverImage
                                }).ToList(),
                                CreatedDate = s.CreatedDate
                            }).OrderByDescending(p => p.CreatedDate).ToList();
                        }
                    }
                    else
                    {
                        products = CommonFunctions.GetProductsVms(null, id);
                    }

                    var category = _db.Categories.Where(s => s.IsActive).ToList();

                    var catelogVm = new CatelogVm
                    {
                        CategoryName  = category.FirstOrDefault(s => s.CategoryId == id)?.Name,
                        FilterDataVms = new List <FilterDataVm>()
                    };

                    if (!string.IsNullOrWhiteSpace(catelogVm.CategoryName) || catelogVm.CategoryName == "one size")
                    {
                        catelogVm.CategoryName = "All Categories";
                    }

                    if (string.IsNullOrWhiteSpace(catelogVm.CategoryName))
                    {
                        catelogVm.CategoryName = "All Categories";
                    }

                    if (id != null && id > 0)
                    {
                        catelogVm.CategoryId = id.Value;
                        category             = category.Where(s => s.RootCategoryId == id.Value).ToList();
                    }
                    else
                    {
                        catelogVm.CategoryId = 0;
                        category             = category.Where(s => s.RootCategoryId == 0 && s.CategoryId > 0).ToList();
                    }
                    #endregion

                    #region --> Get Filter Data

                    if (id != null && id > 0)
                    {
                        catelogVm.Sizes = _db.Sizes.Where(s => s.SizeId > 0 && s.CategoryId == id).Select(s => new SizeVm
                        {
                            CategoryId   = s.CategoryId,
                            SizeId       = s.SizeId,
                            Name         = s.Name,
                            CategoryName = s.Category.Name,
                            IsChecked    = false
                        }).ToList();
                        catelogVm.ProductId = id.Value;
                    }
                    else
                    {
                        catelogVm.Sizes = _db.Sizes.Where(s => s.SizeId == 0).Select(s => new SizeVm
                        {
                            CategoryId   = s.CategoryId,
                            SizeId       = s.SizeId,
                            Name         = s.Name,
                            CategoryName = s.Category.Name,
                            IsChecked    = false
                        }).ToList();
                        catelogVm.ProductId = 0;
                    }

                    #endregion

                    return(new Tuple <List <ProductVm>, List <Category>, CatelogVm>(products, category, catelogVm));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Example #2
0
        public ActionResult Detail(long id)
        {
            try
            {
                using (_db)
                {
                    var products       = CommonFunctions.GetProductsVms(null, null);
                    var product        = products.FirstOrDefault(s => s.ProductId == id);
                    var relatedProduct = new List <ProductVm>();

                    var catelogVm = new CatelogVm
                    {
                        Colors = new List <ColorVm>(),
                        Sizes  = new List <SizeVm>()
                    };

                    if (product?.ProductDetails != null)
                    {
                        var sizes  = _db.Sizes.ToList();
                        var colors = _db.Colors.ToList();

                        foreach (var item in product.ProductDetails)
                        {
                            var addSize = sizes.Where(s => s.SizeId == item.SizeId).Select(s => new SizeVm
                            {
                                CategoryId   = s.CategoryId,
                                SizeId       = s.SizeId,
                                Name         = s.Name,
                                CategoryName = s.Category.Name,
                                IsChecked    = false
                            }).FirstOrDefault();

                            var addColor = colors.Where(s => s.ColorId == item.ColorId).Select(s => new ColorVm
                            {
                                Name      = s.Name,
                                ColorId   = s.ColorId,
                                Hex       = s.Hex,
                                IsChecked = false
                            }).FirstOrDefault();

                            if (addSize != null && catelogVm.Sizes.FirstOrDefault(s => s.SizeId == item.SizeId) == null)
                            {
                                catelogVm.Sizes.Add(addSize);
                            }

                            if (addColor != null && catelogVm.Colors.FirstOrDefault(s => s.ColorId == item.ColorId) == null)
                            {
                                catelogVm.Colors.Add(addColor);
                            }
                        }
                    }

                    if (product != null)
                    {
                        relatedProduct = products.Where(s => s.CategoryId == product.CategoryId).Take(4).ToList();
                    }

                    var tuple = new Tuple <ProductVm, CatelogVm, List <ProductVm> >(product, catelogVm, relatedProduct);
                    return(View(tuple));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Example #3
0
        public Tuple <List <ProductVm>, List <Category>, CatelogVm> IndexTuple(long?id)
        {
            try
            {
                using (_db)
                {
                    #region --> Get Product and Category Details

                    var products = CommonFunctions.GetOfferProductsVms(id);

                    var category  = _db.Categories.Where(s => s.IsActive).ToList();
                    var catelogVm = new CatelogVm
                    {
                        CategoryName  = category.FirstOrDefault(s => s.CategoryId == id)?.Name,
                        FilterDataVms = new List <FilterDataVm>()
                    };

                    if (!string.IsNullOrWhiteSpace(catelogVm.CategoryName) || catelogVm.CategoryName == "one size")
                    {
                        catelogVm.CategoryName = "All Categories";
                    }

                    if (string.IsNullOrWhiteSpace(catelogVm.CategoryName))
                    {
                        catelogVm.CategoryName = "All Categories";
                    }

                    if (id != null && id > 0)
                    {
                        catelogVm.CategoryId = id.Value;
                        category             = category.Where(s => s.RootCategoryId == id.Value).ToList();
                    }
                    else
                    {
                        catelogVm.CategoryId = 0;
                        category             = category.Where(s => s.RootCategoryId == 0 && s.CategoryId > 0).ToList();
                    }
                    #endregion

                    #region --> Get Filter Data

                    if (id != null && id > 0)
                    {
                        catelogVm.Sizes = _db.Sizes.Where(s => s.SizeId > 0 && s.CategoryId == id).Select(s => new SizeVm
                        {
                            CategoryId   = s.CategoryId,
                            SizeId       = s.SizeId,
                            Name         = s.Name,
                            CategoryName = s.Category.Name,
                            IsChecked    = false
                        }).ToList();
                        catelogVm.ProductId = id.Value;
                    }
                    else
                    {
                        catelogVm.Sizes = _db.Sizes.Where(s => s.SizeId == 0).Select(s => new SizeVm
                        {
                            CategoryId   = s.CategoryId,
                            SizeId       = s.SizeId,
                            Name         = s.Name,
                            CategoryName = s.Category.Name,
                            IsChecked    = false
                        }).ToList();
                        catelogVm.ProductId = 0;
                    }

                    #endregion

                    return(new Tuple <List <ProductVm>, List <Category>, CatelogVm>(products, category, catelogVm));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }