public ActionResult EditHoaDonXuat(HoaDonXuatJson hdx) { try { HoaDonXuat temp = db.HoaDonXuat.Where(n => n.MaHDX == hdx.MaHDX).SingleOrDefault(); temp.MaNV = hdx.MaNV; temp.MaKH = hdx.MaKH; temp.NgayXuat = Convert.ToDateTime(hdx.NgayXuat); temp.BacSi = hdx.BacSi; temp.DVCT = hdx.DVCT; db.Entry(temp).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Sửa thành công" }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { success = false, message = "Sửa không thành công, lỗi: " + e.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult CreateHoaDonXuat(HoaDonXuatJson hdx) { try { HoaDonXuat newHDX = new HoaDonXuat { MaHDX = hdx.MaHDX, MaNV = hdx.MaNV, MaKH = hdx.MaKH, NgayXuat = Convert.ToDateTime(hdx.NgayXuat), BacSi = hdx.BacSi, DVCT = hdx.DVCT, }; db.HoaDonXuat.Add(newHDX); db.SaveChanges(); return(Json(new { code = 200, mes = "Thêm hóa đơn xuất thành công" }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { code = 500, mes = e.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult DeleteHoaDonXuat(HoaDonXuatJson temp) { try { var cthdx = db.ChiTietHDX.Where(n => n.MaHDX == temp.MaHDX); if (cthdx != null) { foreach (var a in cthdx) { db.Entry(a).State = EntityState.Deleted; } } var nv = db.HoaDonXuat.Where(n => n.MaHDX == temp.MaHDX).SingleOrDefault(); db.Entry(nv).State = EntityState.Deleted; db.SaveChanges(); return(Json(new { success = true, message = "Xóa hóa đơn xuất thành công" }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { success = false, message = "Xóa không thành công, lỗi: " + temp.MaHDX }, JsonRequestBehavior.AllowGet)); } }