Example #1
0
        public async Task <IActionResult> ProductDetails(int product)
        {
            ProductListViewModel pList = new ProductListViewModel();
            Product pro = await _unitOfWork.Repository <Product>().GetSingleIncludeAsync(x => x.Id == product, b => b.Brand, c => c.Category, u => u.Unit, rc => rc.ProductCommentses, pi => pi.ProductImages);

            if (pro != null)
            {
                pList.Id                  = pro.Id;
                pList.Name                = pro.Name;
                pList.Code                = pro.Code;
                pList.Tag                 = pro.Tag;
                pList.CategoryId          = pro.CategoryId;
                pList.BrandId             = pro.BrandId;
                pList.UnitId              = pro.UnitId;
                pList.Description         = pro.Description;
                pList.Price               = pro.Price;
                pList.BrandName           = pro.Brand.Name;
                pList.CategoryName        = pro.Category.Name;
                pList.UnitName            = pro.Unit.Name;
                pList.Discount            = pro.Discount;
                pList.FinalPrice          = (pro.Price - ((pro.Price * pro.Discount) / 100));
                pList.ProductComments     = pro.ProductCommentses.Count(x => x.ProductId == pro.Id);
                pList.TotalImage          = pro.ProductImages.Count(x => x.ProductId == pro.Id);
                pList.ProductCommentsList = GetAllCommentsByProduct(pro.Id);

                pList.ImageList = new List <ProductImageListViewModel>();

                var productImageList = pro.ProductImages.Where(x => x.ProductId == pro.Id).ToList();

                var productImage = productImageList.FirstOrDefault();
                if (productImage != null)
                {
                    pList.ImageTitle = productImage.Title;
                    pList.ImagePath  = productImage.ImagePath;
                    productImageList.ForEach(x =>
                    {
                        ProductImageListViewModel image = new ProductImageListViewModel
                        {
                            Id        = x.Id,
                            ImagePath = x.ImagePath,
                            Title     = x.Title,
                        };
                        pList.ImageList.Add(image);
                    });
                }
            }
            return(View(pList));
        }
Example #2
0
        public List <ProductImageListViewModel> GetAllProductImageList()
        {
            List <ProductImageListViewModel> productImageList = new List <ProductImageListViewModel>();

            _unitOfWork.Repository <ProductImage>().GetAllInclude(p => p.Product).OrderByDescending(x => x.AddedDate).ToList().ForEach(p =>
            {
                ProductImageListViewModel productImage = new ProductImageListViewModel
                {
                    Id          = p.Id,
                    ProductId   = p.Id,
                    Title       = p.Title,
                    ImagePath   = p.ImagePath,
                    ProductName = p.Product.Name
                };
                productImageList.Add(productImage);
            });
            return(productImageList);
        }
Example #3
0
        public PartialViewResult GetProdutcsImages(int id)
        {
            List <ProductImageListViewModel> productImageList = new List <ProductImageListViewModel>();

            ViewBag.productName = _unitOfWork.Repository <Product>().GetById(id).Name;
            _unitOfWork.Repository <ProductImage>().GetAll().Where(x => x.ProductId == id).ToList().ForEach(x =>
            {
                ProductImageListViewModel pImage = new ProductImageListViewModel
                {
                    Id          = x.Id,
                    ProductId   = x.ProductId,
                    ImagePath   = x.ImagePath,
                    Title       = x.Title,
                    ProductName = _unitOfWork.Repository <Product>().GetById(id).Name
                };
                productImageList.Add(pImage);
            });
            return(PartialView("_ShowImageByProduct", productImageList));
        }