예제 #1
0
        public ActionResult Edit(ShopFruistConnection.SANPHAM sp)
        {
            string pathValue = Server.MapPath("~/");

            var hpt = HttpContext.Request.Files[0];

            if (hpt.FileName == "")
            {
                Models.SanPhamBus.SanPhamBus.UpdateProduct(sp, 0);
            }
            else
            {
                if (HttpContext.Request.Files.Count > 0)
                {
                    if (hpt.ContentLength > 0)
                    {
                        string temp          = hpt.FileName;
                        string RDString      = Guid.NewGuid().ToString();
                        string fullNameImage = "upload/img/" + RDString + temp;
                        hpt.SaveAs(pathValue + fullNameImage);
                        sp.HinhAnh = fullNameImage;
                    }
                }
                Models.SanPhamBus.SanPhamBus.UpdateProduct(sp, 1);
            }

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public ActionResult Create(ShopFruistConnection.SANPHAM sp)
        {
            string pathValue = Server.MapPath("~/");

            var hpt = HttpContext.Request.Files[0];

            if (HttpContext.Request.Files.Count > 0)
            {
                if (hpt.ContentLength > 0)
                {
                    string temp          = hpt.FileName;
                    string RDString      = Guid.NewGuid().ToString();
                    string fullNameImage = "upload/img/" + RDString + temp;
                    hpt.SaveAs(pathValue + fullNameImage);
                    sp.HinhAnh = fullNameImage;
                }
            }

            Models.SanPhamBus.SanPhamBus.insert(sp);
            String link = "";
            int    id   = -1;

            for (int i = 1; i <= 4; i++)
            {
                hpt = HttpContext.Request.Files[i];
                if (hpt.FileName == "")
                {
                }
                else
                {
                    if (HttpContext.Request.Files.Count > 0)
                    {
                        if (hpt.ContentLength > 0)
                        {
                            string temp          = hpt.FileName;
                            string RDString      = Guid.NewGuid().ToString();
                            string fullNameImage = "upload/img/" + RDString + temp;
                            hpt.SaveAs(pathValue + fullNameImage);
                            link = fullNameImage;
                            id   = sp.MaSanPham;
                        }
                    }
                    Models.DanhSachHinh.DanhSachHinh.insertImg(link, id);
                }
            }

            return(RedirectToAction("Create"));
        }