Пример #1
0
        public ActionResult Suadongho(HttpPostedFileBase fileupload, FormCollection f)
        {
            WATCH dongho = db.WATCHes.First(d => d.IdWatch == int.Parse(f["IdWatch"]));

            ViewBag.IdBrand = new SelectList(db.Brands.ToList().OrderBy(n => n.BrandName), "IdBrand", "BrandName");
            if (fileupload == null)
            {
                ViewBag.Thongbao = "vui lòng chọn ảnh bìa";
                return(View());
            }
            else
            {
                if (ModelState.IsValid)
                {
                    dongho.WatchName = f["WatchName"];
                    dongho.Cost      = decimal.Parse(f["Cost"]);
                    dongho.DateUp    = DateTime.Now;
                    dongho.number    = int.Parse(f["number"]);
                    var fileName = Path.GetFileName(fileupload.FileName);
                    var path     = Path.Combine(Server.MapPath("~/images/products"), fileName);
                    if (System.IO.File.Exists(path))
                    {
                        ViewBag.Thongbao = "Hình đã được tồn tại";
                    }
                    else
                    {
                        fileupload.SaveAs(path);
                    }
                    dongho.Img = fileName;
                    UpdateModel(dongho);
                    db.SubmitChanges();
                }
                return(RedirectToAction("dongho"));
            }
        }
Пример #2
0
        public Giohang(int IdWatch)
        {
            iIdDongho = IdWatch;
            WATCH dh = db.WATCHes.Single(n => n.IdWatch == iIdDongho);

            sTendongho = dh.WatchName;
            sAnhbia    = dh.Img;
            dDongia    = double.Parse(dh.Cost.ToString());
            iSoluong   = 1;
        }
Пример #3
0
 public ActionResult Suadongho(int id)
 {
     if (Session["Taikhoanadmin"] != null)
     {
         WATCH dh = db.WATCHes.SingleOrDefault(n => n.IdWatch == id);
         if (dh == null)
         {
             Response.StatusCode = 404;
             return(null);
         }
         ViewBag.IdBrand = new SelectList(db.Brands.ToList().OrderBy(n => n.BrandName), "IdBrand", "BrandName", dh.IdBrand);
         return(View(dh));
     }
     return(RedirectToAction("Login", "Admin"));
 }
Пример #4
0
 public ActionResult Xoadongho(int id)
 {
     if (Session["Taikhoanadmin"] != null)
     {
         WATCH dh = db.WATCHes.SingleOrDefault(n => n.IdWatch == id);
         ViewBag.IdDongho = dh.IdWatch;
         if (dh == null)
         {
             Response.StatusCode = 404;
             return(null);
         }
         return(View(dh));
     }
     return(RedirectToAction("Login", "Admin"));
 }
Пример #5
0
        public ActionResult Xacnhanxoa(int id)
        {
            WATCH dh = db.WATCHes.SingleOrDefault(n => n.IdWatch == id);

            ViewBag.IdDongho = dh.IdWatch;


            if (dh == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            db.WATCHes.DeleteOnSubmit(dh);
            db.SubmitChanges();
            return(RedirectToAction("dongho"));
        }
Пример #6
0
 public ActionResult Themdongho(WATCH dongho, HttpPostedFileBase fileupload)
 {
     //Dua du lieu vao dropdownload
     ViewBag.IdBrand = new SelectList(db.Brands.ToList().OrderBy(n => n.BrandName), "IdBrand", "BrandName");
     //ktra duong dan file
     if (fileupload == null)
     {
         ViewBag.Thongbao = "vui lòng chọn ảnh bìa";
         return(View());
     }
     //them vao csdl
     else
     {
         if (ModelState.IsValid)
         {
             //luu ten file , dung thu vien System.IO;
             var fileName = Path.GetFileName(fileupload.FileName);
             //luu duong dan file
             var path = Path.Combine(Server.MapPath("~/images/products"), fileName);
             //kiem tra hien ton tai chua?
             if (System.IO.File.Exists(path))
             {
                 ViewBag.Thongbao = "Hình đã được tồn tại";
             }
             else
             {
                 //luu hinh anh vao duong dan
                 fileupload.SaveAs(path);
             }
             dongho.Img = fileName;
             db.WATCHes.InsertOnSubmit(dongho);
             db.SubmitChanges();
         }
         return(RedirectToAction("dongho"));
     }
 }