public ActionResult Delete(int id) { CN_ThanhLy cN_ThanhLy = db.CN_ThanhLy.Find(id); db.CN_ThanhLy.Remove(cN_ThanhLy); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CN_ThanhLy cN_ThanhLy = db.CN_ThanhLy.Find(id); if (cN_ThanhLy == null) { return(HttpNotFound()); } ViewBag.IDHD = DanhSachHopDong(cN_ThanhLy.IDHD.Value); return(View(cN_ThanhLy)); }
public ActionResult Edit([Bind(Include = "IDTL, IDHD, IsHoanThanh, NgayThanhLy, GiaTriThanhLy, GiaTriQuyetToan, NgayTongNghiemThu, NguoiTao, NgayTao, NguoiCapNhat, NgayCapNhat")] CN_ThanhLy cN_ThanhLy, FormCollection fCollection) { try { db.Configuration.LazyLoadingEnabled = false; CN_HopDong hopDong = db.CN_HopDong.Find(cN_ThanhLy.IDHD); if (cN_ThanhLy.NgayThanhLy < hopDong.NgayHetHan) { ModelState.AddModelError("NgayThanhLy", $"Ngày thanh lý hợp đổng nhỏ hơn Ngày hết hạn {hopDong.NgayHetHan}"); } if (ModelState.IsValid) { List <SelectListItem> list = _common.getThongTinBang(); cN_ThanhLy.NguoiCapNhat = list.Where(o => o.Value == "NguoiCapNhat").SingleOrDefault().Text; cN_ThanhLy.NgayCapNhat = DateTime.Parse(list.Where(o => o.Value == "NgayCapNhat").SingleOrDefault().Text); db.Entry(cN_ThanhLy).State = EntityState.Modified; db.SaveChanges(); //TempData["err"] = "<div class='alert alert-success' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Cập nhật thành công</div> "; #region luu lich su // luu lich su HT_LichSuHoatDong ls = new HT_LichSuHoatDong( ChucNang , "UPDATE" , DateTime.Now, Session["username"]?.ToString() , $"Cập nhật - Thanh lý - số hợp đồng { hopDong?.SoHopDong }"); db.HT_LichSuHoatDong.Add(ls); db.SaveChanges(); #endregion return(RedirectToAction("Index")); } TempData["err"] = "<div class='alert alert-danger' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Có lỗi xảy ra</div> "; ViewBag.IDHD = DanhSachHopDong(cN_ThanhLy.IDHD.Value); return(View(cN_ThanhLy)); } catch (Exception ex) { string cauBaoLoi = "Không ghi được dữ liệu.<br/>Lý do: " + ex.Message; return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, cauBaoLoi)); } }