public ActionResult EditHoaDonNhap(HoaDonNhapJson hdn)
 {
     try
     {
         HoaDonNhap temp = db.HoaDonNhap.Where(n => n.MaHDN == hdn.MaHDN).SingleOrDefault();
         temp.MaNV            = hdn.MaNV; temp.NgayNhap = Convert.ToDateTime(hdn.NgayNhap); temp.MaNCC = hdn.MaNCC;
         db.Entry(temp).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(new { success = true, message = "Sửa hóa đơn nhập 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 CreateHoaDonNhap(HoaDonNhapJson temp)
 {
     try
     {
         HoaDonNhap newHDN = new HoaDonNhap
         {
             MaHDN    = temp.MaHDN,
             MaNV     = temp.MaNV,
             NgayNhap = Convert.ToDateTime(temp.NgayNhap),
             MaNCC    = temp.MaNCC
         };
         db.HoaDonNhap.Add(newHDN);
         db.SaveChanges();
         return(Json(new { code = 200, mes = "Thêm Hóa Đơn Nhập thành công" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
         return(Json(new { code = 500, mes = e.Message }, JsonRequestBehavior.AllowGet));
     }
 }
 public ActionResult DeleteHoaDonNhap(HoaDonNhapJson temp)
 {
     try
     {
         var cthdn = db.ChiTietHDN.Where(n => n.MaHDN == temp.MaHDN);
         if (cthdn != null)
         {
             foreach (var item in cthdn)
             {
                 db.Entry(item).State = EntityState.Deleted;
             }
         }
         var hdn = db.HoaDonNhap.Where(n => n.MaHDN == temp.MaHDN).SingleOrDefault();
         db.Entry(hdn).State = EntityState.Deleted;
         db.SaveChanges();
         return(Json(new { success = true, message = "Xóa hóa đơn nhập 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: " + e.Message }, JsonRequestBehavior.AllowGet));
     }
 }