Exemplo n.º 1
0
        public JsonResult CartData()
        {
            var memberid = User.FindFirstValue(ClaimTypes.Sid);
            List <Tbl_Product>     product = new List <Tbl_Product>();
            IEnumerable <Tbl_Cart> cart    = Cart_repository.GetListByParameter(i => i.CartStatusId == 1 && i.MemberId == Convert.ToInt32(memberid));

            foreach (var item in cart)
            {
                int         _count      = cart.Where(x => x.ProductId == item.ProductId).Count();
                Tbl_Product tbl_Product = new Tbl_Product();
                tbl_Product = prod_repository.GetById(item.ProductId);
                Tbl_ProductImage img = new Tbl_ProductImage();
                img = ProdImage_Repository.GetByParameter(i => i.ProductId == item.ProductId);
                tbl_Product.ProductImage = img.ImageName;
                tbl_Product.TotalProduct = _count;
                if (product.Any(s => s.ProductId == item.ProductId))
                {
                    continue;
                }
                product.Add(tbl_Product);
            }
            ViewBag.TotalPrice = product.Sum(i => i.PriceSale * i.TotalProduct);
            //ViewBag.TotalPrice = product.Sum(i => i.PriceSale);
            return(Json(product));
        }
Exemplo n.º 2
0
        public IActionResult Index()
        {
            var model = prod_repository.GetAll();
            List <Tbl_Product> products = new List <Tbl_Product>();

            foreach (var item in model)
            {
                Tbl_Product tbl_Product = new Tbl_Product();
                tbl_Product.Category    = item.Category;
                tbl_Product.Description = item.Description;
                tbl_Product.PriceSale   = item.PriceSale;
                tbl_Product.Price       = item.Price;
                tbl_Product.ProductName = item.ProductName;
                tbl_Product.ProductId   = item.ProductId;
                Tbl_ProductImage img = new Tbl_ProductImage();
                img = prodImage_repository.GetByParameter(i => i.ProductId == item.ProductId);
                tbl_Product.ProductImage = img.ImageName;
                products.Add(tbl_Product);
            }
            if (User.Identity.IsAuthenticated)
            {
                int?memberid = HttpContextAccessor.HttpContext.Session.GetInt32("memberid");
                int count    = cart_repository.GetAllRecordsCountByParameter(i => i.MemberId == memberid);
                this.session.SetInt32("Cartcount", count);
            }

            return(View(products));
        }
Exemplo n.º 3
0
        public IActionResult ProductDetails(int id)
        {
            if (TempData["id"] != null)
            {
                id = (int)TempData["id"];
            }
            Tbl_Product   pd      = prod_repository.GetByParameter(i => i.ProductId == id);
            ProductDetail product = new ProductDetail();

            product.CategoryId  = pd.CategoryId;
            product.CreatedDate = pd.CreatedDate;
            product.Description = pd.Description;
            //product.IsActive = pd.IsActive;
            ////product.IsDelete = pd.IsDelete;
            //product.IsFeatured = pd.IsFeatured;
            product.ModifiedDate    = pd.ModifiedDate;
            product.Price           = pd.Price;
            product.PriceSale       = pd.PriceSale;
            product.ProductId       = pd.ProductId;
            product.Images          = prodImage_repository.GetListByParameter(i => i.ProductId == pd.ProductId);
            product.ProductName     = pd.ProductName;
            product.count           = pd.Quantity;
            product.RelatedProducts = prod_repository.GetListByParameter(i => i.SubCategoryId == pd.SubCategoryId);

            List <Tbl_Product> products = new List <Tbl_Product>();

            foreach (var item in product.RelatedProducts)
            {
                Tbl_Product tbl_Product = new Tbl_Product();
                tbl_Product.Category    = item.Category;
                tbl_Product.Description = item.Description;
                tbl_Product.PriceSale   = item.PriceSale;
                tbl_Product.Price       = item.Price;
                tbl_Product.ProductName = item.ProductName;
                tbl_Product.ProductId   = item.ProductId;
                Tbl_ProductImage img = new Tbl_ProductImage();
                img = prodImage_repository.GetByParameter(i => i.ProductId == item.ProductId);
                tbl_Product.ProductImage = img.ImageName;
                products.Add(tbl_Product);
            }
            product.RelatedProducts = products;
            return(View(product));
        }
Exemplo n.º 4
0
        //public JsonResult getCategories()
        //{
        //    IEnumerable<Tbl_Category> categories = null;
        //    categories = cat_repository.GetAll();
        //    return Json(categories);
        //}

        public ProductList Lazy_data(int pagesize, int pageindex, int catid)
        {
            IEnumerable <Tbl_Product> model = null;

            if (catid == 0)
            {
                model = Context.Tbl_Product.Skip(pageindex * pagesize).Take(pagesize);
                //  SELECT colName1, colName2, colName3, colName4 FROM tblMyTableName  ORDER BY colNameForSorting
                // OFFSET ( @OffSetRowNo-1 ) * @FetchRowNo ROWS  FETCH NEXT @FetchRowNo ROWS ONLY
            }
            else
            {
                model = Context.Tbl_Product.Where(i => i.CategoryId == catid).Skip(pageindex * pagesize).Take(pagesize);
            }

            List <Tbl_Product> products = new List <Tbl_Product>();

            foreach (var item in model)
            {
                Tbl_Product tbl_Product = new Tbl_Product();
                tbl_Product.Category    = item.Category;
                tbl_Product.Description = item.Description;
                tbl_Product.PriceSale   = item.PriceSale;
                tbl_Product.Price       = item.Price;
                tbl_Product.ProductName = item.ProductName;
                tbl_Product.ProductId   = item.ProductId;
                Tbl_ProductImage img = new Tbl_ProductImage();
                img = prodImage_repository.GetByParameter(i => i.ProductId == item.ProductId);
                tbl_Product.ProductImage = img.ImageName;
                products.Add(tbl_Product);
            }


            ProductList productList = new ProductList();

            productList.prodData = products;;
            return(productList);
        }
Exemplo n.º 5
0
        public IActionResult CreateProduct(ProductDetail model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string      uniqueFileName = null;
                    Tbl_Product product        = new Tbl_Product();
                    ///Insert Product Data
                    product.CategoryId    = model.CategoryId;
                    product.SubCategoryId = model.SubCategoryId;
                    product.CreatedDate   = model.CreatedDate;
                    product.Description   = model.Description;
                    product.IsActive      = model.IsActive;
                    product.IsDelete      = model.IsDelete;
                    product.IsFeatured    = model.IsFeatured;
                    product.ModifiedDate  = model.ModifiedDate;
                    product.Price         = model.Price;
                    product.PriceSale     = model.PriceSale;
                    product.ProductId     = model.ProductId;
                    product.ProductName   = model.ProductName;
                    //product.ProductImage = uniqueFileName;
                    prod_repository.Insert(product);
                    int lastProductId = product.ProductId;



                    // If the Photo property on the incoming model object is not null, then the user
                    // has selected an image to upload.
                    if (model.ProductImage != null && model.ProductImage.Count > 0)
                    {
                        foreach (IFormFile image in model.ProductImage)
                        {
                            // The image must be uploaded to the images folder in wwwroot
                            // To get the path of the wwwroot folder we are using the inject
                            // HostingEnvironment service provided by ASP.NET Core
                            string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "ProductImage");
                            // To make sure the file name is unique we are appending a new
                            // GUID value and and an underscore to the file name
                            uniqueFileName = Guid.NewGuid().ToString() + "_" + image.FileName;
                            string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                            // Use CopyTo() method provided by IFormFile interface to
                            // copy the file to wwwroot/images folder
                            image.CopyTo(new FileStream(filePath, FileMode.Create));
                            Tbl_ProductImage productImage = new Tbl_ProductImage();
                            productImage.ProductId = lastProductId;
                            productImage.ImageName = uniqueFileName;

                            // Load image.
                            Image img = Image.FromStream(image.OpenReadStream(), true, true);

                            // Compute thumbnail size.
                            Size thumbnailSize = GetThumbnailSize(img);

                            // Get thumbnail.
                            Image thumbnail = img.GetThumbnailImage(thumbnailSize.Width,
                                                                    thumbnailSize.Height, null, IntPtr.Zero);

                            string uploadsFolder2 = Path.Combine(_hostingEnvironment.WebRootPath, "Thumbnails");
                            string filePath2      = Path.Combine(uploadsFolder2, uniqueFileName);

                            // Save thumbnail.
                            thumbnail.Save(filePath2);
                            _Prodimg_repository.Insert(productImage);
                        }
                    }

                    return(RedirectToAction("AllProducts"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }