Beispiel #1
0
        public ActionResult AddProduct(Tbl_Product product)
        {
            _unitOfWork.GetRepositoryInstance <Tbl_Product>().Add(product);
            _unitOfWork.SaveChanges();

            return(View());
        }
 public ActionResult UpdateProduct(ProductDetail pd, HttpPostedFileBase _ProductImage)
 {
     if (ModelState.IsValid)
     {
         Tbl_Product prod = _unitOfWork.GetRepositoryInstance <Tbl_Product>().GetFirstOrDefault(pd.ProductId);
         prod              = prod != null ? prod : new Tbl_Product();
         prod.CategoryId   = pd.CategoryId;
         prod.Description  = pd.Description;
         prod.IsActive     = pd.IsActive;
         prod.IsFeatured   = pd.IsFeatured;
         prod.Price        = pd.Price;
         prod.ProductImage = _ProductImage != null ? _ProductImage.FileName : prod.ProductImage;
         prod.ProductName  = pd.ProductName;
         prod.ModifiedDate = DateTime.Now;
         if (prod.ProductId == 0)
         {
             prod.CreatedDate = DateTime.Now;
             prod.IsDelete    = false;
             _unitOfWork.GetRepositoryInstance <Tbl_Product>().Add(prod);
         }
         else
         {
             _unitOfWork.GetRepositoryInstance <Tbl_Product>().Update(prod);
             _unitOfWork.SaveChanges();
         }
         if (_ProductImage != null)
         {
             uc.UploadImage(_ProductImage, prod.ProductId + "_", "/Content/ProductImage/", Server, _unitOfWork, 0, prod.ProductId, 0);
         }
         return(RedirectToAction("Products"));
     }
     pd.Categories = new SelectList(_unitOfWork.GetRepositoryInstance <Tbl_Category>().GetAllRecordsIQueryable(), "CategoryId", "CategoryName");
     return(View("UpdateProduct", pd));
 }
Beispiel #3
0
        public IHttpActionResult Post(Tbl_Product product)
        {
            //adminLoginRepository.Insert(Admin);
            productRepository.Insert(product);

            return(Created("api/products/" + product.ProductId, product));
        }
        public SearchVM GetSearchProduct(string search, int page)
        {
            using (var db = new ProjectWebEntities())
            {
                var model   = new SearchVM();
                var pageNum = 10;
                var key     = "";
                if (!string.IsNullOrEmpty(search))
                {
                    key = Util.RemoveSignInVietnameseString(search);
                }
                var listSearchDb = db.sp_Search_Product(key).Where(p => p.IsDisable == false && p.IsStatus == 0).ToList();
                var listSearch   = new List <Tbl_Product>();
                foreach (var item in listSearchDb)
                {
                    var result = new Tbl_Product();
                    result.Name          = item.Name;
                    result.ImagePath     = item.ImagePath;
                    result.RealPrice     = item.RealPrice;
                    result.Id            = item.Id;
                    result.ProductTypeId = item.ProductTypeId;

                    //result.ProductTypeName = result.Tbl_ProductType.Name;
                    listSearch.Add(result);
                }
                model.ListSearch = listSearch.ToPagedList(page, pageNum);
                return(model);
            }
        }
        public ActionResult ProductEdit(Tbl_Product Product, HttpPostedFileBase file)
        {
            if (Session["AdminId"] != null)
            {
                string pic = null;
                if (file != null)
                {
                    pic = System.IO.Path.GetFileName(file.FileName);
                    string path = System.IO.Path.Combine(Server.MapPath("~/ProductImgs/"), pic);
                    file.SaveAs(path);
                    Product.ProductImage = pic;
                }
                else
                {
                    Product.ProductImage = Product.ProductImage;
                }

                Product.ModifiedDate = DateTime.Now;
                _unitOfWork.GetRepositoryInstance <Tbl_Product>().Update(Product);
                ViewBag.CategoryId = new SelectList(_DBEntity.Tbl_Category, "CategoryId", "CategoryName", Product.ProductId);
                return(RedirectToAction("Product"));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
        public ActionResult UpdateProduct(Tbl_Product Product, HttpPostedFileBase file)
        {
            if (Session["AdminId"] != null)
            {
                string pic = null;
                if (file != null)
                {
                    pic = System.IO.Path.GetFileName(file.FileName);
                    string path = System.IO.Path.Combine(Server.MapPath("~/ProductImgs/"), pic);
                    file.SaveAs(path);
                }
                Product.ProductImage = pic;
                Product.IsDelete     = false;
                Product.CreatedDate  = DateTime.Now;
                _DBEntity.Tbl_Product.Add(Product);
                _DBEntity.SaveChanges();


                ViewBag.CategoryId = new SelectList(_DBEntity.Tbl_Category, "CategoryId", "CategoryName", Product.ProductId);
                return(RedirectToAction("Product"));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
Beispiel #7
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));
        }
        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));
        }
Beispiel #9
0
        public IActionResult GetProduct(int id)
        {
            Tbl_Product pd = prod_repository.GetByParameter(i => i.ProductId == id);

            pd.ProductImage = prodImage_repository.GetByParameter(i => i.ProductId == pd.ProductId).ImageName;
            return(PartialView("_quickView", pd));
        }
        /// <summary>
        /// Product Detail
        /// </summary>
        /// <param name="pId"></param>
        /// <returns></returns>
        public ActionResult ProductDetail(int pId)
        {
            Tbl_Product pd = _unitOfWork.GetRepositoryInstance <Tbl_Product>().GetFirstOrDefault(pId);

            ViewBag.SimilarProducts = _unitOfWork.GetRepositoryInstance <Tbl_Product>().GetListByParameter(i => i.CategoryId == pd.CategoryId).ToList();
            return(View(pd));
        }
Beispiel #11
0
        public ActionResult ProductDelete(int productId)
        {
            Tbl_Product delete = unit.GetRepositoryInstance <Tbl_Product>().GetFirstorDefault(productId);

            delete.IsDelete = true;
            unit.GetRepositoryInstance <Tbl_Product>().Update(delete);
            return(RedirectToAction("Product"));
        }
        // [ValidateAntiForgeryToken]
        // [Authorize(Roles = "Admin")]
        public ActionResult _DeleteConfirmed(int id)
        {
            Tbl_Product _product = db.Tbl_Product.Find(id);

            db.Tbl_Product.Remove(_product);
            db.SaveChanges();
            return(RedirectToAction("Product_List"));
        }
        public ActionResult Create(Tbl_Product model)
        {
            using (var db = new ProjectWebEntities())
            {
                try
                {
                    model.DateCreate   = DateTime.Now;
                    model.Url          = Util.GenerateUrl(model.Name);
                    model.ImageDetails = Request.Form["multiImage"];

                    if (Request.Form["RealPrice"] != "" && Request.Form["RealPrice"] != null)
                    {
                        model.RealPrice = decimal.Parse(Request.Form["RealPrice"].Replace(".", "").Replace("đ", ""));
                    }
                    model.IsDisable = Request.Form["IsDisable"] != "on";
                    //if (Request.Form["ParentId"] != null && Request.Form["ParentId"] != "")
                    //{
                    //    string[] parList = Request.Form["ParentId"].Split(',');
                    //    for (int i = parList.Count() - 1; i >= 0; i--)
                    //    {
                    //        if (parList[i] != "")
                    //        {
                    //            if (int.Parse(parList[i]) > 0)
                    //            {
                    //                model.ProductTypeId = int.Parse(parList[i]);
                    //                break;
                    //            }
                    //        }
                    //    }
                    //}
                    //create new
                    if (model.Id == 0)
                    {
                        model.ViewNumber = 0;
                        db.Tbl_Product.Add(model);
                        db.pr_LogSystem_save("Thêm dữ liệu(" + model.Name + ")", "Thêm", "Product", User.Identity.Name);

                        db.SaveChanges();
                    }
                    else// edit
                    {
                        db.Entry(model).State = EntityState.Modified;
                        db.SaveChanges();
                        db.pr_LogSystem_save("Cập nhật dữ liệu(" + model.Name + ")", "Cập nhật", "Product", User.Identity.Name);
                    }
                    //save product icon

                    //Xóa cache
                    CacheHelper.ClearAllOutputCache();
                }
                catch (Exception ex)
                {
                    _logger.Error("An Error Happened! ", ex);
                }
                return(RedirectToAction("Index", "Product"));
            }
        }
Beispiel #14
0
 public ActionResult ProductAdd(Tbl_Product table)
 {
     using (GenericUnitOfWork _unitOfWork = new GenericUnitOfWork())
     {
         table.CreatedDate = DateTime.Now;
         _unitOfWork.GetRepositoryInstance <Tbl_Product>().Add(table);
         return(RedirectToAction("Product"));
     }
 }
Beispiel #15
0
        public ActionResult ProductEdit(Tbl_Product table)
        {
            table.ModifiedDate = DateTime.Now;

            using (GenericUnitOfWork _unitOfWork = new GenericUnitOfWork())
            {
                _unitOfWork.GetRepositoryInstance <Tbl_Product>().Update(table);
                return(RedirectToAction("Product"));
            }
        }
        public ActionResult ViewImageofProducts(Tbl_Product _product, int id)
        {
            // Tbl_Product _product = new Tbl_Product();

            using (dbOnlineShoppingEntities db = new dbOnlineShoppingEntities())
            {
                _product = db.Tbl_Product.Where(x => x.ProductId == id).FirstOrDefault();
            }

            return(View(_product));
        }
 public ActionResult Create(int id)
 {
     using (var db = new ProjectWebEntities())
     {
         var model = new Tbl_Product();
         if (id != 0)
         {
             model = db.Tbl_Product.Find(id);
         }
         return(View(model));
     }
 }
Beispiel #18
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Tbl_Product tbl_Product = await db.Products.FindAsync(id);

            tbl_Product.IsDelete       = true;
            tbl_Product.IsActive       = false;
            tbl_Product.SalesmanUserId = User.Identity.GetUserId();
            db.Products.AddOrUpdate(tbl_Product);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #19
0
        // GET: Tbl_Product/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Tbl_Product tbl_Product = await db.Products.FindAsync(id);

            if (tbl_Product == null)
            {
                return(HttpNotFound());
            }
            return(View(tbl_Product));
        }
Beispiel #20
0
        private dbOnlineShoppingEntities db = new dbOnlineShoppingEntities();  // Connection String
        // GET: HomePgProductDetails

        public ActionResult ProductDetails(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Tbl_Product _product = db.Tbl_Product.Find(id);

            if (_product == null)
            {
                return(HttpNotFound());
            }
            return(View(_product));
        }
        public ActionResult ProductAdd(Tbl_Product tbl, HttpPostedFileBase file)
        {
            string pic = null;

            if (file != null)
            {
                pic = System.IO.Path.GetFileName(file.FileName);
                string path = System.IO.Path.Combine(Server.MapPath("~/Product_Images/"), pic);
                file.SaveAs(path);
            }
            tbl.ProductImage = pic;
            _unitOfWork.GetRepositoryInstance <Tbl_Product>().Add(tbl);
            return(RedirectToAction("Product"));
        }
Beispiel #22
0
        // GET: Tbl_Product/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Tbl_Product tbl_Product = await db.Products.FindAsync(id);

            if (tbl_Product == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", tbl_Product.CategoryId);
            return(View(tbl_Product));
        }
Beispiel #23
0
        public ActionResult ProductEdit(Tbl_Product tbl, HttpPostedFileBase file)
        {
            string pic = null;

            if (file != null)
            {
                pic = System.IO.Path.GetFileName(file.FileName);
                string path = System.IO.Path.Combine(Server.MapPath("~/ProductImg/"), pic);
                file.SaveAs(path);
            }
            tbl.ProductImage = file != null? pic: tbl.ProductImage;
            tbl.ModifiedDate = DateTime.Now;
            _unitOfWork.GetRepositoryInstance <Tbl_Product>().Update(tbl);
            return(RedirectToAction("Product"));
        }
Beispiel #24
0
        public ActionResult EditProduct(Tbl_Product tbl, HttpPostedFileBase file)
        {
            string picture = null;

            if (file != null)
            {
                picture = Path.GetFileName(file.FileName);
                string path = Path.Combine(Server.MapPath("/Images/ProductImages/"), picture);
                file.SaveAs(path);
            }
            tbl.ProductImagePath = file != null ? picture : tbl.ProductImagePath;
            tbl.MdifiedDate      = DateTime.Now;
            _unitOfWork.GetRepositoryInstance <Tbl_Product>().Update(tbl);
            return(View());
        }
Beispiel #25
0
        public ActionResult AddProduct(Tbl_Product tbl, HttpPostedFileBase file)
        {
            string picture = null;

            if (file != null)
            {
                picture = Path.GetFileName(file.FileName);
                string path = Path.Combine(Server.MapPath("~/Images/ProductImages/"), picture);
                file.SaveAs(path);
            }
            tbl.ProductImagePath = picture;
            tbl.CreatedDate      = DateTime.Now;
            _unitOfWork.GetRepositoryInstance <Tbl_Product>().Add(tbl);
            return(Redirect("Products"));
        }
        public ActionResult ProductAdd(Tbl_Product product, HttpPostedFileBase file)
        {
            string pic = null;

            if (file != null)
            {
                pic = System.IO.Path.GetFileName(file.FileName);
                string path = System.IO.Path.Combine(Server.MapPath("~/Images/pic"), pic);

                file.SaveAs(path);
            }
            product.ProductImage = pic;
            product.CreatedDate  = DateTime.Now;
            _unitOfWork.GetRepositoryInstance <Tbl_Product>().Add(product);
            return(RedirectToAction("Product"));
        }
Beispiel #27
0
        public async Task <ActionResult> Edit([Bind(Include = "ProductId,ProductName,CategoryId,IsActive,IsDelete,CreatedDate,ModifiedDate,Description,Price")] Tbl_Product tbl_Product)
        {
            if (ModelState.IsValid)
            {
                tbl_Product.IsActive        = true;
                tbl_Product.IsDelete        = false;
                tbl_Product.ModifiedDate    = DateTime.Now;
                tbl_Product.SalesmanUserId  = User.Identity.GetUserId();
                db.Entry(tbl_Product).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", tbl_Product.CategoryId);
            return(View(tbl_Product));
        }
        public ActionResult ProductAdd(Tbl_Product tbl, HttpPostedFileBase file)
        {
            string picName = null;
            string picPath;

            if (file != null)
            {
                picName = System.IO.Path.GetFileName(file.FileName);
                picPath = System.IO.Path.Combine(Server.MapPath("~/ProductImages/"), picName);
                //file is uploaded
                file.SaveAs(picPath);
            }
            tbl.ProductImage = picName;
            tbl.CreatedDate  = DateTime.Now;
            _unitOfWork.GetRepositoryInstance <Tbl_Product>().Add(tbl);
            return(RedirectToAction("Product"));
        }
Beispiel #29
0
        public ActionResult ProductAdd(Tbl_Product new_p, HttpPostedFileBase file)
        {
            string pic = null;

            if (file != null)
            {
                pic = System.IO.Path.GetFileName(file.FileName);
                string path = System.IO.Path.Combine(Server.MapPath("~/Products/"), pic);
                file.SaveAs(path);
            }
            new_p.ProductImage = pic;
            new_p.CreatedDate  = DateTime.Now;
            _unitOfWork.GetRepositoryInstance <Tbl_Product>().Add(new_p);
            //_unitOfWork.db.func_insert_procduct(new_p.ProductName, new_p.CategoryId, new_p.Price);
            //ViewBag.CategoryId = new SelectList(_unitOfWork.GetRepositoryInstance<Tbl_Category>().GetAllRecords(),"CategoryId", "CategoryName",new_p.CategoryId);
            return(RedirectToAction("Products"));
        }
Beispiel #30
0
        public ActionResult ProductAdd(Tbl_Product tbl, HttpPostedFileBase file)
        {
            string pic = null;

            if (file != null)
            {
                var fileName  = Path.GetFileNameWithoutExtension(file.FileName);
                var extention = Path.GetExtension(file.FileName);
                pic = fileName.Replace(" ", "_") + "_" + DateTime.Now.ToString("yyyyMMddhhmmss") + extention;
                string path = Path.Combine(Server.MapPath("~/ProductImg/"), pic);
                file.SaveAs(path);
            }
            tbl.ProductImage = pic;
            tbl.CreatedDate  = DateTime.Now;
            _unitOfWork.GetRepositoryInstance <Tbl_Product>().Add(tbl);
            return(RedirectToAction("Product"));
        }