public long AddBill(bill bill) { db.bills.Add(bill); db.SaveChanges(); var idbill = bill.id; return(idbill); }
//Xây dựng chức năng đặt hàng public ActionResult DatHang(KhachHang kh) { if (Session["GioHang"] == null) { return(RedirectToAction("Index", "Home")); } KhachHang khang = new KhachHang(); if (Session["TaiKhoan"] == null) { khang = kh; db.KhachHangs.Add(khang); db.SaveChanges(); } else { ThanhVien tv = Session["TaiKhoan"] as ThanhVien; khang = kh; db.KhachHangs.Add(khang); db.SaveChanges(); } DonDatHang ddh = new DonDatHang(); ddh.MaKH = int.Parse(khang.MaKH.ToString()); ddh.NgayDat = DateTime.Now; ddh.TinhTrang = 0; ddh.TinhTrangGH = null; ddh.NVGiaoHang = null; ddh.UuDai = 0; db.DonDatHangs.Add(ddh); db.SaveChanges(); List <ItemGioHang> lstGH = LayGioHang(); foreach (var item in lstGH) { SanPham sp = new SanPham(); ChiTietDonDatHang ctdh = new ChiTietDonDatHang(); ctdh.MaDDH = ddh.MaDDH; ctdh.MaSP = item.MaSP; ctdh.TenSP = item.TenSP; ctdh.SoLuong = item.SoLuong; ctdh.DonGia = item.DonGia; db.ChiTietDonDatHangs.Add(ctdh); // Trừ số lượng //SanPham spCheck = db.SanPhams.SingleOrDefault(n => n.MaSP == item.MaSP); //if (spCheck.SoLuongTon > item.SoLuong) //{ // spCheck.SoLuongTon = spCheck.SoLuongTon - item.SoLuong; //} } db.SaveChanges(); Session["GioHang"] = null; return(RedirectToAction("XemGioHang")); }
public ActionResult Create([Bind(Include = "MaNSX,TenNSX,ThongTin")] NhaSanXuat nhaSanXuat) { if (ModelState.IsValid) { db.NhaSanXuats.Add(nhaSanXuat); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(nhaSanXuat)); }
public ActionResult Create([Bind(Include = "MaNCC,TenNCC,DiaChi,Email,SoDienThoai,Fax")] NhaCungCap nhaCungCap) { if (ModelState.IsValid) { db.NhaCungCaps.Add(nhaCungCap); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(nhaCungCap)); }
public ActionResult Create([Bind(Include = "MaLoaiSP,TenLoai")] LoaiSanPham loaiSanPham) { if (ModelState.IsValid) { db.LoaiSanPhams.Add(loaiSanPham); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(loaiSanPham)); }
public ActionResult Create([Bind(Include = "MaKH,TenKH,DiaChi,Email,SoDienThoai,MaThanhVien")] KhachHang khachHang) { if (ModelState.IsValid) { db.KhachHangs.Add(khachHang); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaThanhVien = new SelectList(db.ThanhViens, "MaThanhVien", "TaiKhoan", khachHang.MaThanhVien); return(View(khachHang)); }
public ActionResult Create([Bind(Include = "MaThanhVien,TaiKhoan,MatKhau,Hoten,GioiTinh,DiaChi,SoDienThoai,Email,MaLoaiTV")] ThanhVien thanhVien) { if (ModelState.IsValid) { db.ThanhViens.Add(thanhVien); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaLoaiTV = new SelectList(db.LoaiThanhViens, "MaLoaiTV", "TenLoai", thanhVien.MaLoaiTV); return(View(thanhVien)); }
public ActionResult Create([Bind(Include = "MaDDH,NgayDat,TinhTrang,MaKH,UuDai,NVGiaoHang,TinhTrangGH,TongTien")] DonDatHang donDatHang) { if (ModelState.IsValid) { db.DonDatHangs.Add(donDatHang); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaKH = new SelectList(db.KhachHangs, "MaKH", "TenKH", donDatHang.MaKH); return(View(donDatHang)); }
public bool AddTypeProduct(type_products TypeProduct) { try { db.type_products.Add(TypeProduct); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public ActionResult NhapHang(PhieuNhap model, IEnumerable <ChiTietPhieuNhapp> ListModel) { ViewBag.MaNCC = db.NhaCungCaps; ViewBag.ListSanPham = db.SanPhams; db.PhieuNhaps.Add(model); db.SaveChanges(); foreach (var item in ListModel) { item.MaPN = model.MaPN; } db.ChiTietPhieuNhapps.AddRange(ListModel); db.SaveChanges(); return(View()); }
public ActionResult Create([Bind(Include = "MaSP,TenSP,DonGia,NgayCapNhat,CauHinh,MoTa,HinhAnh,SoLuongTon,TinhTrang,MaNCC,MaNSX,MaLoaiSP,HinhAnh1,HinhAnh2,HinhAnh3")] SanPham sanPham) { if (ModelState.IsValid) { db.SanPhams.Add(sanPham); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaLoaiSP = new SelectList(db.LoaiSanPhams, "MaLoaiSP", "TenLoai", sanPham.MaLoaiSP); ViewBag.MaNCC = new SelectList(db.NhaCungCaps, "MaNCC", "TenNCC", sanPham.MaNCC); ViewBag.MaNSX = new SelectList(db.NhaSanXuats, "MaNSX", "TenNSX", sanPham.MaNSX); return(View(sanPham)); }
public ActionResult DeleteConfirmed(int id) { DonDatHang donDatHang = db.DonDatHangs.Find(id); db.DonDatHangs.Remove(donDatHang); db.SaveChanges(); return(RedirectToAction("Index")); }
//huy don hang public bool ChangeStatus(int id) { var user = db.DonDatHangs.Find(id); if (user.TinhTrang == 0) { user.TinhTrang = 2; db.SaveChanges(); } //else //{ // user.TinhTrang = !user.TinhTrang; // db.SaveChanges(); //} return(true); }
public bool AddProduct(product product) { var result = true; try { var productadd = db.products.Add(product); var id = productadd.id; db.SaveChanges(); } catch (Exception ex) { result = false; throw; } return(result); }
public long AddCustomer(customer customer) { db.customers.Add(customer); db.SaveChanges(); long id_Customer = customer.id; return(id_Customer); }
public ActionResult ChinhSua(ThanhVien tvien) { ThanhVien tvv = Session["TaiKhoan"] as ThanhVien; var tv = db.ThanhViens.Find(tvien.MaThanhVien); if (tv != null) { tv.Hoten = tvien.Hoten; tv.TaiKhoan = tvv.TaiKhoan; tv.MatKhau = tvien.MatKhau; tv.DiaChi = tvien.DiaChi; tv.SoDienThoai = tvien.SoDienThoai; db.SaveChanges(); ViewBag.TV = tv; RedirectToAction("Index", "User"); } else { ModelState.AddModelError("", "Sửa thành công"); } return(View("Index")); }
public ActionResult DangKy(ThanhVien tv, FormCollection f) { //Kiểm tra captcha hợp lệ if (this.IsCaptchaValid("Captcha is not valid")) { if (ModelState.IsValid) { ViewBag.ThongBao = "Đăng ký thành công"; //Thêm khách hàng vào csdl db.ThanhViens.Add(tv); db.SaveChanges(); } else { ViewBag.ThongBao = "Đăng ký thất bại"; } return(View()); } ViewBag.ThongBao = "Sai captcha"; return(View()); }
public void AddUser(user user) { db.users.Add(user); db.SaveChanges(); }