Пример #1
0
 public ActionResult SuaQuyen(Quyen model)
 {
     db.Entry(model).State = System.Data.Entity.EntityState.Modified;
     model.TrangThai       = true;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Пример #2
0
 public ActionResult DuyetDonHang(DonDatHang model)
 {
     db.Entry(model).State   = System.Data.Entity.EntityState.Modified;
     model.TinhTrangGiaoHang = true;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Пример #3
0
        public ActionResult ChinhSua(NhaCungCap ncc)
        {
            ncc.DaXoa           = false;
            db.Entry(ncc).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            ViewBag.ThongBao = "Cập nhật thành công";

            return(View(ncc));
        }
Пример #4
0
        public ActionResult ChinhSua(ThanhVien tv)
        {
            tv.MaLoaiTV        = 3;
            tv.DaXoa           = false;
            db.Entry(tv).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            ViewBag.ThongBao = "Cập nhật thành công";

            return(View(tv));
        }
Пример #5
0
        public ActionResult ChinhSua(SanPham model)
        {
            ViewBag.MaNCC    = new SelectList(db.NhaCungCaps.OrderBy(n => n.TenNCC), "MaNCC", "TenNCC", model.MaNCC);
            ViewBag.MaLoaiSP = new SelectList(db.LoaiSanPhams.OrderBy(n => n.MaLoaiSP), "MaLoaiSP", "TenLoai", model.MaLoaiSP);
            ViewBag.MaNSX    = new SelectList(db.NhaSanXuats.OrderBy(n => n.MaNSX), "MaNSX", "TenNSX", model.MaNSX);

            db.Entry(model).State = System.Data.Entity.EntityState.Modified;
            model.DaXoa           = 0;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #6
0
        public ActionResult Edit([Bind(Include = "id,product_code,product_name,description,standard_cost,list_price,target_level,reorder_level,minimum_reorder_quantity,quantity_per_unit,discontinued,category")] products products, string image_oldFile, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                string uploadFolderPath = Server.MapPath("~/UploadedFiles/ProductImages");

                if (image == null) // Nếu không cập nhật file (không chọn file)
                {
                    // Giữ nguyên giá trị của tên file trong cột `image`
                    products.image = image_oldFile;
                }
                else // Người ta có chọn file ảnh mới
                {
                    // 1. Xóa file ảnh cũ (để tránh rác)
                    // ~/UploadedFiles/ProductImages/ASP.NET_CodeXuLyDangKy.png -> đường dẫn file ảnh cũ
                    string filePathAnhCu = Path.Combine(uploadFolderPath, (products.image == null ? "" : products.image));
                    if (System.IO.File.Exists(filePathAnhCu))
                    {
                        System.IO.File.Delete(filePathAnhCu);
                    }

                    // 2. Upload file ảnh mới
                    // Xử lý file: lưu file vào thư mục UploadedFiles/ProductImages
                    string _FileName = "";
                    // Di chuyển file vào thư mục mong muốn
                    if (image.ContentLength > 0)
                    {
                        _FileName = Path.GetFileName(image.FileName);                   // QRCode_NenTangUrl.png
                        string _FileNameExtension = Path.GetExtension(image.FileName);  // .png
                        if ((_FileNameExtension == ".png" ||
                             _FileNameExtension == ".jpg" ||
                             _FileNameExtension == ".jpeg"
                             ) == false)
                        {
                            return(View(String.Format("File có đuôi {0} không được chấp nhận. Vui lòng kiểm tra lại!", _FileNameExtension)));
                        }

                        if (Directory.Exists(uploadFolderPath) == false) // Nếu thư mục cần lưu trữ file upload không tồn tại (chưa có) => Tạo mới
                        {
                            Directory.CreateDirectory(uploadFolderPath);
                        }

                        string _path = Path.Combine(uploadFolderPath, _FileName);
                        image.SaveAs(_path);
                    }
                    // Lưu tên file vào database
                    products.image = _FileName;
                }

                /* UPDATE products
                 * SET product_code = 'P3333',
                 *      product_name = 'DELL 333'
                 * WHERE id = 603
                 */
                db.Entry(products).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(products));
        }
        public ActionResult ChinhSua(SanPham sp, HttpPostedFileBase HinhAnh)
        {
            //kiểm tra hình ảnh đã tồn tại trong csdl chưa
            if (HinhAnh != null)
            {
                if (HinhAnh.ContentLength > 0)
                {
                    //lấy tên hình ảnh
                    var filename = System.IO.Path.GetFileName(HinhAnh.FileName);
                    //lấy hình ảnh chuyển vào thư mục hình ảnh
                    var path = System.IO.Path.Combine(Server.MapPath("~/Content/HinhAnh"), filename);

                    //Lấy hình ảnh đưa vào mục hình ảnh
                    HinhAnh.SaveAs(path);
                    sp.HinhAnh = filename;
                }
            }
            else
            {
                var ha = Request.Cookies["HinhAnh"].Value;
                if (ha != null)
                {
                    sp.HinhAnh = ha.ToString();
                }
            }
            //Load dropdownlist Nhà cung cấp, Loại SP, nhà sản xuất
            ViewBag.MaNCC    = new SelectList(db.NhaCungCaps.OrderBy(n => n.MaNCC), "MaNCC", "TenNCC", sp.MaNCC);
            ViewBag.MaNSX    = new SelectList(db.NhaSanXuats.OrderBy(n => n.MaNSX), "MaNSX", "TenNSX", sp.MaNSX);
            ViewBag.MaLoaiSP = new SelectList(db.LoaiSanPhams.OrderBy(n => n.MaLoaiSP), "MaLoaiSP", "TenLoai", sp.MaLoaiSP);
            //Nếu dữ liệu đầu vào chắc chắn chuẩn
            db.Entry(sp).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult ChinhSua(ThanhVien model)
 {
     //Nếu dữ liệu chắc chắn ok
     db.Entry(model).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Пример #9
0
 public ActionResult ChinhSuaThanhVien(ThanhVien thanhVien)
 {
     //Nếu dữ liệu đầu vào chắn chắn ok
     db.Entry(thanhVien).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Пример #10
0
 public ActionResult XoaMember(LoaiThanhVien model)
 {
     db.Entry(model).State = System.Data.Entity.EntityState.Modified;
     model.UuDai           = 0;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Пример #11
0
        public ActionResult Xoa(int id)
        {
            if (id <= 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NhaSanXuat nsx = db.NhaSanXuats.SingleOrDefault(n => n.MaNSX == id);

            if (nsx == null)
            {
                return(HttpNotFound());
            }
            nsx.DaXoa           = true;
            db.Entry(nsx).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            TempData["ThongBao"] = "Xóa thành công";
            return(RedirectToAction("Index"));
        }
Пример #12
0
        public ActionResult HuyDonHang(int id)
        {
            if (id <= 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DonDatHang dh = db.DonDatHangs.SingleOrDefault(n => n.MaDDH == id);

            if (dh == null)
            {
                return(HttpNotFound());
            }
            dh.DaHuy           = true;
            db.Entry(dh).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            TempData["ThongBao"] = "Hủy thành công";
            return(RedirectToAction("Index"));
        }
 public ActionResult ChinhSua(LoaiDienThoai ldt, FormCollection f)
 {
     if (ModelState.IsValid)
     {
         //Thực hiện cập nhập trong model
         db.Entry(ldt).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Пример #14
0
 public ActionResult Edit([Bind(Include = "MaNCC,TenNCC,DiaChi,Email,SoDienThoai,Fax")] NhaCungCap nhaCungCap)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nhaCungCap).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(nhaCungCap));
 }
 public ActionResult Edit([Bind(Include = "MaLoaiSP,TenLoai,Icon,BiDanh")] LoaiSanPham loaiSanPham)
 {
     if (ModelState.IsValid)
     {
         db.Entry(loaiSanPham).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(loaiSanPham));
 }
Пример #16
0
        public ActionResult Xoa(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SanPham sp = db.SanPhams.SingleOrDefault(n => n.MaSP == id);

            if (sp == null)
            {
                return(HttpNotFound());
            }
            sp.DaXoa           = true;
            db.Entry(sp).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            ViewBag.ThongBao = "Xóa thành công";

            return(RedirectToAction("Index"));
        }
Пример #17
0
 public ActionResult Edit([Bind(Include = "MaNSX,TenNSX,ThongTin,Logo")] NhaSanXuat nhaSanXuat)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nhaSanXuat).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(nhaSanXuat));
 }
Пример #18
0
 public ActionResult Edit(Quyen quyen)
 {
     if (ModelState.IsValid)
     {
         db.Entry(quyen).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(quyen));
 }
Пример #19
0
 public ActionResult ChinhSua(SanPham model)
 {
     //bỏ ua phân kiêm tra .sưa trưc tiêp
     ViewBag.MaNCC         = new SelectList(db.NhaCC.OrderBy(x => x.MaNCC), "MaNCC", "TenNCC", model.MaNCC);
     ViewBag.MaLoaiSP      = new SelectList(db.LoaiSanPham.OrderBy(x => x.MaLoaiSP), "MaLoaiSP", "TenLoai", model.MaLoaiSP);
     ViewBag.MaNSX         = new SelectList(db.NhaSanXuat.OrderBy(x => x.MaNSX), "MaNSX", "TenNSX", model.MaNSX);
     db.Entry(model).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Пример #20
0
 public ActionResult ChinhSua(SANPHAM model)
 {
     //ViewBag.MaNCC = new SelectList(db.NHACUNGCAPs.OrderBy(n => n.TenNCC), "MaNCC", "TenNCC", model.MaNCC);
     ViewBag.MaLoaiSP = new SelectList(db.LOAISANPHAMs.OrderBy(n => n.MaLoaiSP), "MaLoaiSP", "TenLoai", model.MaLoaiSP);
     // ViewBag.MaNSX = new SelectList(db.NhaSanXuats.OrderBy(n => n.MaNSX), "MaNSX", "TenNSX", model.MaNSX);
     //Nếu dữ liệu đầu vào chắn chắn ok
     db.Entry(model).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Пример #21
0
 public ActionResult Edit([Bind(Include = "MaThanhVien,TaiKhoan,MatKhau,HoTen,DiaChi,Email,SoDienThoai,CauHoi,CauTraLoi,MaLoaiTV")] ThanhVien thanhVien)
 {
     if (ModelState.IsValid)
     {
         db.Entry(thanhVien).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaLoaiTV = new SelectList(db.LoaiThanhVien, "MaLoaiTV", "TenLoai", thanhVien.MaLoaiTV);
     return(View(thanhVien));
 }
Пример #22
0
 public ActionResult Edit([Bind(Include = "Id,MaThanhVien,NgayMua,SoLuong,DonGia,ThanhTien")] HoaDonMuaTin hoaDonMuaTin)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hoaDonMuaTin).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaThanhVien = new SelectList(db.ThanhViens, "MaThanhVien", "TaiKhoan", hoaDonMuaTin.MaThanhVien);
     return(View(hoaDonMuaTin));
 }
Пример #23
0
 public ActionResult Edit([Bind(Include = "MaKH,TenKH,DiaChi,Email,SoDienThoai,MaThanhVien")] KhachHang khachHang)
 {
     if (ModelState.IsValid)
     {
         db.Entry(khachHang).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaThanhVien = new SelectList(db.ThanhVien, "MaThanhVien", "TaiKhoan", khachHang.MaThanhVien);
     return(View(khachHang));
 }
Пример #24
0
 public ActionResult Edit(ThanhVien thanhVien)
 {
     ViewBag.CauHoi = new SelectList(LoadCauHoi());
     if (ModelState.IsValid)
     {
         db.Entry(thanhVien).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaLoaiTV = new SelectList(db.LoaiThanhViens, "MaLoaiTV", "TenLoai", thanhVien.MaLoaiTV);
     return(View(thanhVien));
 }
        public ActionResult ChinhSua(SanPham model)
        {
            //nếu dữ liệu dầu vào chắc chắc đúng
            ViewBag.MaNCC    = new SelectList(db.NhaCungCaps.OrderBy(n => n.TenNCC), "MaNCC", "TenNCC", model.MaNCC);
            ViewBag.MaLoaiSP = new SelectList(db.LoaiSanPhams.OrderBy(n => n.MaLoaiSP), "MaLoaiSP", "TenLoai", model.MaLoaiSP);
            ViewBag.MaNSX    = new SelectList(db.NhaSanXuats.OrderBy(n => n.MaNSX), "MaNSX", "TenNSX", model.MaNSX);


            db.Entry(model).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult ChinhSua(SanPham sp)
        {
            ViewBag.MaNCC    = new SelectList(db.NhaCungCap.OrderBy(s => s.TenNCC), "MaNCC", "TenNCC", sp.MaNCC);
            ViewBag.MaLoaiSP = new SelectList(db.LoaiSanPham.OrderBy(s => s.MaLoaiSP), "MaLoaiSP", "TenLoai", sp.MaLoaiSP);
            ViewBag.MaNSX    = new SelectList(db.NhaSanXuat.OrderBy(s => s.MaNSX), "MaNSX", "TenNSX", sp.MaNSX);
            // do chưa kiểm tra validtion nên tạm thời cho nó đúng
            //if (ModelState.IsValid)
            //{

            db.Entry(sp).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
            //}
            //return View(sp);
        }
 public ActionResult ChinhSua(SanPham model)
 {
     //load dll nhà cung cấp,loại sản phẩm...
     ViewBag.MaNCC    = new SelectList(db.NhaCungCap.OrderBy(n => n.TenNCC), "MaNCC", "TenNCC", model.MaNCC);
     ViewBag.MaLoaiSP = new SelectList(db.LoaiSanPham.OrderBy(n => n.MaLoaiSP), "MaLoaiSP", "TenLoai", model.MaLoaiSP);
     ViewBag.MaNSX    = new SelectList(db.NhaSanXuat.OrderBy(n => n.MaNSX), "MaNSX", "TenNSX", model.MaNSX);
     //kiểm tra validation trong model nếu hợp thì thực hiện công việc{}
     //if (ModelState.IsValid)
     //{
     db.Entry(model).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
     //}
     //return View(model);
 }
        public ActionResult ChinhSua(SanPham sp, HttpPostedFileBase[] HinhAnh)
        {
            ViewBag.MaNCC    = new SelectList(db.NhaCungCaps.OrderBy(x => x.TenNCC), "MaNCC", "TenNCC", sp.MaNCC);
            ViewBag.MaLoaiSP = new SelectList(db.LoaiSanPhams.OrderBy(x => x.MaLoaiSP), "MaLoaiSP", "TenLoai", sp.MaLoaiSP);
            ViewBag.MaNSX    = new SelectList(db.NhaSanXuats.OrderBy(x => x.MaNSX), "MaNSX", "TenNSX", sp.MaNSX);

            db.Entry(sp).State = System.Data.Entity.EntityState.Modified;
            sp = ktraHinhAnhDauVao(sp, HinhAnh);
            if (sp == null)
            {
                return(View(sp));
            }

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #29
0
        public ActionResult ChinhSua(SanPham sp, HttpPostedFileBase[] HinhAnh)
        {
            ViewBag.MaNCC    = new SelectList(db.NhaCungCaps.OrderBy(n => n.TenNCC), "MaNCC", "TenNCC", sp.MaNCC);
            ViewBag.MaLoaiSP = new SelectList(db.LoaiSanPhams.OrderBy(n => n.TenLoai), "MaLoaiSP", "TenLoai", sp.MaLoaiSP);
            ViewBag.MaNSX    = new SelectList(db.NhaSanXuats.OrderBy(n => n.TenNSX), "MaNSX", "TenNSX", sp.MaNSX);
            int loi = 0;

            for (var i = 0; i < HinhAnh.Count(); i++)
            {
                if (HinhAnh[i] != null)
                {
                    //kiểm tra hình ảnh
                    if (HinhAnh[i].ContentLength > 0)
                    {
                        //kiem tra định dạng hình ảnh
                        if (HinhAnh[i].ContentType != "image/jpeg" && HinhAnh[i].ContentType != "image/png" && HinhAnh[i].ContentType != "image/gif" && HinhAnh[i].ContentType != "image/jpg")
                        {
                            ViewBag.upload += "hình ảnh" + i + "không hợp lệ <br/>";
                            loi++;
                        }
                        else
                        {
                            //lấy tên hình ảnh
                            var filename = Path.GetFileName(HinhAnh[0].FileName);
                            //lấy hình ảnh chuyển vào thư mục hình ảnh
                            var path = Path.Combine(Server.MapPath("~/Content/images/ImagesSanPham"), filename);
                            //nếu hình ảnh chứa trong thu mục đó rồi thì xuất thông báo

                            sp.HinhAnh = HinhAnh[0].FileName;
                            //sp.HinhAnh = HinhAnh[1].FileName;
                            //sp.HinhAnh = HinhAnh[2].FileName;
                            //sp.HinhAnh = HinhAnh[3].FileName;
                            //sp.HinhAnh = HinhAnh[4].FileName;
                        }
                    }
                }
            }
            if (ModelState.IsValid)
            {
                db.Entry(sp).State = System.Data.Entity.EntityState.Modified;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult ChinhSua(DonHang dh, FormCollection f)
        {
            ////Lấy dữ liệu từ textbox
            //DienThoai dt1 = db.DienThoais.SingleOrDefault(n => n.MaDT == dt.MaDT);
            //dt1.Mota = dt.Mota;
            //dt1.Mota = f.Get("abc").ToString();
            //db.SaveChanges();

            //Thêm vào cơ sở dữ liệu
            if (ModelState.IsValid)
            {
                //Thực hiện cập nhập trong model
                db.Entry(dh).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }