// GET api/<controller> public IEnumerable <QuanLyDonHang> Get() { string filter = HttpContext.Current.Request.Params.Get("filter"); if (string.IsNullOrEmpty(filter)) { List <QuanLyDonHang> lst = (from table in db.QuanLyDonHangs select table).ToList(); //string json = JsonConvert.SerializeObject(lst); return(lst); //return new string[] { json }; } else { QuanLyDonHang obj = JsonConvert.DeserializeObject <QuanLyDonHang>(filter); List <QuanLyDonHang> lst = (from table in db.QuanLyDonHangs where (obj.KhoHangCuoi == null || obj.KhoHangCuoi == table.KhoHangCuoi) && (obj.KhoHangNhan == null || obj.KhoHangNhan == table.KhoHangNhan) && (obj.LinkSP == null || obj.LinkSP == table.LinkSP) && (obj.MaVanChuyen == null || obj.MaVanChuyen == table.MaVanChuyen) && (obj.NgayDatHang == null || obj.NgayDatHang == table.NgayDatHang) && (obj.NguoiNhanCuoi == null || obj.NguoiNhanCuoi == table.NguoiNhanCuoi) && (obj.OrderNumber == null || obj.OrderNumber == table.OrderNumber) && (obj.TaiKhoanDatHang == null || obj.TaiKhoanDatHang == table.TaiKhoanDatHang) && (obj.TaiKhoanKhach == null || obj.TaiKhoanKhach == table.TaiKhoanKhach) && (obj.TrangThaiDonHang == null || obj.TrangThaiDonHang == table.TrangThaiDonHang) select table).ToList(); return(lst); // string json = JsonConvert.SerializeObject(lst); // return new string[] { json }; } }
// DELETE api/<controller>/5 public void Delete(int id) { QuanLyDonHang obj = db.QuanLyDonHangs.Where(o => o.Id == id).SingleOrDefault(); db.QuanLyDonHangs.DeleteOnSubmit(obj); db.SubmitChanges(); }
public ActionResult DonHangDaDuyet(string searchString, int?page) { if (Session["MaTKAdmin"] == null) { return(RedirectToAction("Login", "Admin")); } else { try { var model = new QuanLyDonHang() { DanhSachHoaDon = KhoiTaoDSDonHangDaDuyet(searchString, page) }; return(View(model)); } catch (Exception) { var model = new QuanLyDonHang() { DanhSachHoaDon = KhoiTaoDSDonHangDaDuyet(searchString, page) }; return(View(model)); } } }
public ActionResult ChiTietDonHang(int id, int?page) { if (Session["MaTKAdmin"] == null) { return(RedirectToAction("Login", "Admin")); } else { try { ViewBag.id = id; ShopEntities shop = new ShopEntities(); var model = new QuanLyDonHang() { DanhSachChiTiet = KhoiTaoChitietHoaDon(id, page), HoaDon = shop.HoaDons.SingleOrDefault(h => h.MaHoaDon == id) }; return(View(model)); } catch (Exception) { return(View("ChiTietDonHang")); } } }
public ActionResult XoaDonHang(int id, int loai) { if (Session["MaTKAdmin"] == null) { return(RedirectToAction("Login", "Admin")); } else { try { ShopEntities shop = new ShopEntities(); var model = new QuanLyDonHang() { DanhSachHoaDon = KhoiTao("", 1) }; var hoaDon = shop.HoaDons.Single(s => s.MaHoaDon == id); var dsChiTiet = shop.ChiTietHoaDons.Where(c => c.MaHoaDon == id).ToList(); if (loai == 0) { foreach (var item in dsChiTiet) { shop.ChiTietHoaDons.Remove(item); } shop.HoaDons.Remove(hoaDon); shop.SaveChanges(); return(View("DonHangChuaDuyet", model)); } else { foreach (var item in dsChiTiet) { var sp = shop.SanPhams.SingleOrDefault(s => s.MaSanPham == item.MaSanPham); sp.SoLuong -= item.SoLuong; shop.ChiTietHoaDons.Remove(item); shop.SaveChanges(); } shop.HoaDons.Remove(hoaDon); shop.SaveChanges(); return(View("DonHangDaDuyet", model)); } } catch (Exception) { return(View("DonHangChuaDuyet")); } } }
public ActionResult DuyetDonHang(int id) { if (Session["MaTKAdmin"] == null) { return(RedirectToAction("Login", "Admin")); } else { try { ShopEntities shop = new ShopEntities(); var model = new QuanLyDonHang() { DanhSachHoaDon = KhoiTao("", 1) }; var hoaDon = shop.HoaDons.Single(s => s.MaHoaDon == id); hoaDon.TrangThai = true; hoaDon.NgayDuyet = DateTime.Now; shop.SaveChanges(); var list = shop.ChiTietHoaDons.Where(c => c.MaHoaDon == id).ToList(); foreach (var item in list) { var sp = shop.SanPhams.SingleOrDefault(s => s.MaSanPham == item.MaSanPham); sp.SoLuong += item.SoLuong; shop.SaveChanges(); } return(View("DonHangChuaDuyet", model)); } catch (Exception) { return(View("DonHangChuaDuyet")); } } }
// PUT api/<controller>/5 public void Put(int id, [FromBody] QuanLyDonHang value) { QuanLyDonHang obj = db.QuanLyDonHangs.Where(o => o.Id == id).SingleOrDefault(); QuanLyDonHang newobj = value;// JsonConvert.DeserializeObject<QuanLyDonHang>(value); if (newobj.KhoHangCuoi != null) { obj.KhoHangCuoi = newobj.KhoHangCuoi; } if (newobj.KhoHangNhan != null) { obj.KhoHangNhan = newobj.KhoHangNhan; } if (newobj.LinkSP != null) { obj.LinkSP = newobj.LinkSP; } if (newobj.MaVanChuyen != null) { obj.MaVanChuyen = newobj.MaVanChuyen; } if (newobj.NgayDatHang != null) { obj.NgayDatHang = newobj.NgayDatHang; } if (newobj.NguoiNhanCuoi != null) { obj.NguoiNhanCuoi = newobj.NguoiNhanCuoi; } if (newobj.OrderNumber != null) { obj.OrderNumber = newobj.OrderNumber; } if (newobj.TaiKhoanDatHang != null) { obj.TaiKhoanDatHang = newobj.TaiKhoanDatHang; } if (newobj.TaiKhoanKhach != null) { obj.TaiKhoanKhach = newobj.TaiKhoanKhach; } if (newobj.TenHang != null) { obj.TenHang = newobj.TenHang; } if (newobj.TrangThaiDonHang != null) { obj.TrangThaiDonHang = newobj.TrangThaiDonHang; } if (newobj.TheTich != null) { obj.TheTich = newobj.TheTich; } if (newobj.CanNang != null) { obj.CanNang = newobj.CanNang; } if (newobj.ChuyenPhat != null) { obj.ChuyenPhat = newobj.ChuyenPhat; } if (newobj.CuocVanChuyen != null) { obj.CuocVanChuyen = newobj.CuocVanChuyen; } if (newobj.DatCoc != null) { obj.DatCoc = newobj.DatCoc; } if (newobj.GiaSP != null) { obj.GiaSP = newobj.GiaSP; } if (newobj.GiaSPCanThu != null) { obj.GiaSPCanThu = newobj.GiaSPCanThu; } if (newobj.HangVanChuyen != null) { obj.HangVanChuyen = newobj.HangVanChuyen; } db.SubmitChanges(); }
// POST api/<controller> public void Post([FromBody] QuanLyDonHang value) { //QuanLyDonHang newobj = (QuanLyDonHang)JsonConvert.DeserializeObject(value); db.QuanLyDonHangs.InsertOnSubmit(value); db.SubmitChanges(); }