Exemplo n.º 1
0
        public IActionResult Update(ProductMv product)
        {
            ViewBag.Categories = CategoryBus.GetAll().Result.Where(x => x.CategoryParent == TypeCategories.Child).ToList();
            var productData = ProductBus.GetById(product.Id).Result;

            if (!ModelState.IsValid)
            {
                return(View(productData));
            }
            product.ModifiedBy = Guid.Parse("a845b16a-4ca6-48e2-4ca6-08d817450c1a");
            if (product.FileImage != null)
            {
                var ms = new MemoryStream();
                product.FileImage.CopyTo(ms);
                var    fileBytes = ms.ToArray();
                string s         = Convert.ToBase64String(fileBytes);
                product.FileData  = s;
                product.FileImage = null;
            }
            if (ProductBus.Update(product.Id, product).Result)
            {
                TempData[ConstKey.Success] = "Success!";
                return(RedirectToAction("Index"));
            }
            TempData[ConstKey.Error] = "Fail! Try again.";
            return(View(productData));
        }
Exemplo n.º 2
0
        public IActionResult Update(Guid id)
        {
            ViewBag.Categories = CategoryBus.GetAll().Result.Where(x => x.CategoryParent == TypeCategories.Child).ToList();
            var product = ProductBus.GetById(id).Result;

            return(View(product));
        }
        // GET: QuanLyProduct/Create
        public ActionResult Create()
        {
            ViewBag.CategogyID     = new SelectList(ProductBus.GetListCategogy(), "ID", "CategogyName");
            ViewBag.ManufacturerID = new SelectList(ProductBus.GetListManufacturer(), "ID", "ManufacturerName");

            return(View());
        }
Exemplo n.º 4
0
        public JsonResult LoadData(string name, string status, int page, int pageSize)
        {
            var model = ProductBus.List();

            if (!string.IsNullOrEmpty(name))
            {
                model = model.Where(x => x.Name.ToUpper().Contains(name.ToUpper()));
            }

            if (!string.IsNullOrEmpty(status))
            {
                var statusBool = bool.Parse(status);
                model = model.Where(x => x.Status == statusBool);
            }

            int totalRow = model.Count();

            model = model.Skip((page - 1) * pageSize).Take(pageSize);
            return(Json(new
            {
                data = model,
                total = totalRow,
                status = true
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult CreateSpecification()
        {
            Specification temp = new Specification();

            temp.ProductID = ProductBus.getIDProductNew();
            return(View(temp));
        }
Exemplo n.º 6
0
        public ActionResult Index(int id)
        {
            ProductBus.Xoa(id);
            var ds = ProductBus.DanhSach();

            return(View(ds));
        }
Exemplo n.º 7
0
 //
 // GET: /Admin/AminProduct/
 //[ValidateInput(true)]
 public ActionResult Index(int?page)
 {
     if (page == null)
     {
         page = 1;
     }
     return(View(ProductBus.AdDanhSach(page)));
 }
 /// <summary>
 /// 产品列表
 /// </summary>
 /// <returns></returns>
 public ActionResult ProductcList()
 {
     if (!base.CheckIsLogin())
     {
         return(RedirectToAction("Index", "Login"));
     }
     ViewData["AllPersonClass"] = new ProductBus().GetProductclassesBySupclassid(0);
     return(View());
 }
Exemplo n.º 9
0
        public JsonResult ChangeStatus(int id)
        {
            var result = ProductBus.ChangeStatus(id);

            return(Json(new
            {
                status = result
            }));
        }
Exemplo n.º 10
0
 public ActionResult Search(int?page, string key)
 {
     if (page == null)
     {
         page = 1;
     }
     Session["keysearch"] = key;
     return(View(ProductBus.TimKiem(page, key)));
 }
Exemplo n.º 11
0
 public ActionResult Loai(int?page, string maloai)
 {
     if (page == null)
     {
         page = 1;
     }
     Session["key2"] = maloai;
     return(View(ProductBus.SpTheoLoai(page, maloai)));
 }
Exemplo n.º 12
0
 public ActionResult CLoai(int?page, int?macl)
 {
     if (page == null)
     {
         page = 1;
     }
     Session["key2"] = macl;
     return(View(ProductBus.SpTheoCL(page, macl)));
 }
Exemplo n.º 13
0
        public JsonResult Top10FeaturedByCate(int id)
        {
            var model = ProductBus.Top10FeaturedByCate(id);

            return(Json(new
            {
                data = model,
                status = true
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 14
0
        public JsonResult Details(int id)
        {
            var product = ProductBus.ViewProduct(id);

            return(Json(new
            {
                data = product,
                status = true
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult EditSpecification(int id)
        {
            var spec = ProductBus.GetSpecification(id);

            if (spec == null)
            {
                HttpNotFound();
            }
            return(View(spec));
        }
Exemplo n.º 16
0
        // GET: Admin/SanPham/Edit/5
        public ActionResult Edit(int id)
        {
            var ds        = ProductBus.ChiTiet(id);
            var selectnsx = ds.MaNSX;
            var selectlsp = ds.MaLSP;

            ViewBag.MaNSX = new SelectList(BrandBus.DanhSach(), "MaNSX", "TenNSX", selectnsx);
            ViewBag.MaLSP = new SelectList(TypeBus.DanhSach(), "MaLSP", "TenLSP", selectlsp);
            return(View(ds));
        }
        // GET: QuanLyProduct/Delete/5
        public ActionResult Delete(int id)
        {
            var sp = ProductBus.DetailProduct(id);

            if (sp == null)
            {
                HttpNotFound();
            }
            ViewBag.CategogyID     = new SelectList(ProductBus.GetListCategogy(), "ID", "CategogyName", sp.CategogyID);
            ViewBag.ManufacturerID = new SelectList(ProductBus.GetListManufacturer(), "ID", "ManufacturerName", sp);
            return(View(sp));
        }
        public ActionResult Edit(int id, Product sp, HttpPostedFileBase Image)
        {
            // TODO: Add update logic here
            if (Image != null)
            {
                var fileName = Path.GetFileName(Image.FileName);
                var path     = Path.Combine(Server.MapPath("~/Content/Image"), fileName);
                if (System.IO.File.Exists(path))
                {
                    sp.Image = fileName;
                }
                else
                {
                    Image.SaveAs(path);
                    sp.Image = fileName;
                }
            }
            else
            {
                ProductBus.UpdateNoImage(id, sp);
            }

            var htf      = HttpContext.Request.Files;
            var lstImage = ProductBus.getListImage(id).ToList();

            for (int i = 1; i < htf.Count; i++)
            {
                if (htf[i].ContentLength > 0)
                {
                    string fileName = "";
                    if (Request.Browser.Browser == "IE")
                    {
                        fileName = Path.GetFileName(htf[i].FileName);
                    }
                    else
                    {
                        fileName = htf[i].FileName;
                    }
                    var path = Path.Combine(Server.MapPath("~/Content/Image"), fileName);
                    if (System.IO.File.Exists(path))
                    {
                        ProductBus.UpdateImage(fileName, lstImage[i - 1].Image_ID);
                    }
                    else
                    {
                        htf[i].SaveAs(path);
                        ProductBus.UpdateImage(fileName, lstImage[i - 1].Image_ID);
                    }
                }
            }
            ProductBus.Update(id, sp);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 19
0
 public IActionResult Disable(Guid id)
 {
     if (ProductBus.DisableAsync(id).Result)
     {
         TempData[ConstKey.Success] = "Success.";
     }
     else
     {
         TempData[ConstKey.Error] = "Fail! Try again.";
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         // TODO: Add delete logic here
         ProductBus.Delete(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 21
0
 public ActionResult Delete(string id, Product sp)
 {
     try
     {
         // TODO: Add delete logic here
         ProductBus.Xoa(id, sp);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 22
0
        public IActionResult Index()
        {
            var products   = ProductBus.GetAll().Result.ToList();
            var categories = CategoryBus.GetAll().Result.ToList();

            foreach (var product in products)
            {
                product.Category = categories.SingleOrDefault(x => x.Id == product.CategoryId);
            }
            ViewBag.Products = products;

            return(View());
        }
        public ActionResult Create(Product sp, HttpPostedFileBase[] Images)
        {
            //Kiểm tra hình ảnh

            if (Images[0] != null)
            {
                var fileName = Path.GetFileName(Images[0].FileName);
                var path     = Path.Combine(Server.MapPath("~/Content/Image"), fileName);
                if (System.IO.File.Exists(path))
                {
                    ViewBag.ThongBao = "Hinh đã tồn tại";
                    return(View());
                }
                else
                {
                    Images[0].SaveAs(path);
                    sp.Image = fileName;
                }
            }
            ProductBus.Insert(sp);
            var id = ProductBus.getIDProductNew();

            foreach (var Image in Images)
            {
                if (Image != null)
                {
                    var fileName = Path.GetFileName(Image.FileName);
                    var path     = Path.Combine(Server.MapPath("~/Content/Image"), fileName);
                    if (System.IO.File.Exists(path) && fileName != sp.Image)
                    {
                        ViewBag.ThongBao       = "Hinh đã tồn tại";
                        ViewBag.CategogyID     = new SelectList(ProductBus.GetListCategogy(), "ID", "CategogyName");
                        ViewBag.ManufacturerID = new SelectList(ProductBus.GetListManufacturer(), "ID", "ManufacturerName");
                        return(View());
                    }
                    else
                    {
                        MoreImage mi = new MoreImage();
                        Image.SaveAs(path);
                        mi.ImageName  = fileName;
                        mi.Product_ID = id;
                        ProductBus.InsertImage(mi);
                    }
                }
            }
            return(RedirectToAction("CreateSpecification"));
        }
Exemplo n.º 24
0
        // GET: Product/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(Redirect("/"));
            }

            var product = ProductBus.Find(id);

            if (product == null)
            {
                return(Redirect("/"));
            }

            ViewBag.Images = ImageBus.List(id);

            return(View(ProductBus.Details(id)));
        }
Exemplo n.º 25
0
        public ActionResult Create(ProductViewModels sp)
        {
            try
            {
                var validImageTypes = new string[]
                {
                    "image/gif",
                    "image/jpeg",
                    "image/pjpeg",
                    "image/png"
                };

                if (sp.ImageUpload == null || sp.ImageUpload.ContentLength == 0)
                {
                    ModelState.AddModelError("ImageUpload", "Chưa chọn hình");
                }
                else if (!validImageTypes.Contains(sp.ImageUpload.ContentType))
                {
                    ModelState.AddModelError("ImageUpload", "Làm ơn chọn file có định dạng hình GIF, JPG, PNG.");
                }

                if (ModelState.IsValid)
                {
                    if (sp.ImageUpload != null && sp.ImageUpload.ContentLength > 0)
                    {
                        var uploadDir = "~/image/product";
                        var imagePath = Path.Combine(Server.MapPath(uploadDir), sp.ImageUpload.FileName);
                        var imageUrl  = Path.Combine(uploadDir, sp.ImageUpload.FileName);
                        sp.ImageUpload.SaveAs(imagePath);
                        sp.Hinh = sp.ImageUpload.FileName;
                    }
                }
                sp.NgayDangSP = DateTime.Now;
                sp.LuotXem    = 0;
                ProductBus.Them(sp);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ProductViewModels spham = new ProductViewModels();
                spham.dsLoai1 = LoaiBus.DanhSach();
                return(View(spham));
            }
        }
Exemplo n.º 26
0
        public ActionResult Edit(ProductViewModels sp)
        {
            try
            {
                var validImageTypes = new string[]
                {
                    "image/gif",
                    "image/jpeg",
                    "image/pjpeg",
                    "image/png"
                };

                if (sp.ImageUpload2 == null || sp.ImageUpload2.ContentLength == 0)
                {
                    ModelState.AddModelError("ImageUpload", "Chưa chọn hình");
                }
                else if (!validImageTypes.Contains(sp.ImageUpload2.ContentType))
                {
                    ModelState.AddModelError("ImageUpload", "Làm ơn chọn file có định dạng hình GIF, JPG, PNG.");
                }

                if (ModelState.IsValid)
                {
                    if (sp.ImageUpload2 != null && sp.ImageUpload2.ContentLength > 0)
                    {
                        var uploadDir = "~/Image/product";
                        var imagePath = Path.Combine(Server.MapPath(uploadDir), sp.ImageUpload2.FileName);
                        var imageUrl  = Path.Combine(uploadDir, sp.ImageUpload2.FileName);
                        sp.ImageUpload2.SaveAs(imagePath);
                        if (sp.ImageUpload2.FileName != null)
                        {
                            sp.Hinh = sp.ImageUpload2.FileName;
                        }
                    }
                }
                sp.NgayDangSP = DateTime.Now;
                ProductBus.Sua(sp);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(ProductBus.ChiTiet(sp.MaSP)));
            }
        }
        // GET: QuanLyProduct/Edit/5
        public ActionResult Edit(int id)
        {
            //if (id == null)
            //{
            //    Response.StatusCode = 404;
            //    return null;
            //}
            var sp = ProductBus.GetProduct(id);

            if (sp == null)
            {
                HttpNotFound();
            }
            ViewBag.CategogyID     = new SelectList(ProductBus.GetListCategogy(), "ID", "CategogyName", sp.CategogyID);
            ViewBag.ManufacturerID = new SelectList(ProductBus.GetListManufacturer(), "ID", "ManufacturerName", sp.ManufacturerID);
            ViewBag.ThongBao       = "";
            ViewBag.ListImage      = ProductBus.getListImage(id).ToList();
            return(View(sp));
        }
        /// <summary>
        /// 新产品
        /// </summary>
        /// <returns></returns>
        public ActionResult AddProduct(string productid)
        {
            if (!base.CheckIsLogin())
            {
                return(RedirectToAction("Index", "Login"));
            }

            ViewData["AllClass"] = new ProductBus().GetProductclassesBySupclassid(-1);
            if (!string.IsNullOrEmpty(productid))
            {
                ViewData["ProductModel"] = new ProductBus().GetProductById(productid);
            }
            else
            {
                ViewData["ProductModel"] = null;
            }

            return(View());
        }
        /// <summary>
        /// 产品类别编辑页面
        /// </summary>
        /// <returns></returns>
        public ActionResult EditProductclass(string classid)
        {
            if (!base.CheckIsLogin())
            {
                return(RedirectToAction("Index", "Login"));
            }

            int id = 0;

            int.TryParse(classid, out id);

            ViewData["AllPersonClass"] = new ProductBus().GetProductclassesBySupclassid(0);
            Mproductclass model = new ProductBus().GetMproductclassById(id);

            if (model == null)
            {
                model = new Mproductclass();
            }
            return(View(model));
        }
Exemplo n.º 30
0
        //add a product to cart
        public ActionResult AddItem(int productId, int quantity)
        {
            var cart = Session[CartSession];

            if (cart != null)
            {
                var list = (List <CartItem>)cart;
                if (list.Exists(x => x.Product.Id == productId))
                {
                    foreach (var item in list)
                    {
                        if (item.Product.Id == productId)
                        {
                            item.Quantity += quantity;
                        }
                    }
                }
                else
                {
                    //create new cartItem object
                    var item = new CartItem();
                    item.Product  = ProductBus.Details(productId);
                    item.Quantity = quantity;
                    list.Add(item);
                }
                //set to session
                Session[CartSession] = list;
            }
            else
            {
                //create new cartItem object
                var item = new CartItem();
                item.Product  = ProductBus.Details(productId);
                item.Quantity = quantity;
                var list = new List <CartItem>();
                list.Add(item);
                //set to session
                Session[CartSession] = list;
            }
            return(RedirectToAction("Index"));
        }