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

            return(View());
        }
        // 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 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"));
        }
        // 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));
        }