public bool Sua(HT_PHAM_VI obj) { bool kq = true; Entities entities = ContextFactory.GetInstance(); EntityKey key = null; object original = null; try { key = entities.CreateEntityKey(ENTITY_SET_NAME, obj); if (entities.TryGetObjectByKey(key, out original)) { entities.ApplyCurrentValues(key.EntitySetName, obj); } entities.SaveChanges(); kq = true; } catch (System.Exception ex) { kq = false; LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); throw ex; } finally { entities = null; } return(kq); }
public HT_PHAM_VI GetById(int id) { HT_PHAM_VI kq = null; Entities entities = ContextFactory.GetInstance(); try { kq = entities.HT_PHAM_VI.FirstOrDefault(e => e.ID == id); return(kq); } catch (System.Exception ex) { kq = null; LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); throw ex; } finally { entities = null; } }
public bool Them(HT_PHAM_VI obj) { bool kq = true; Entities entities = ContextFactory.GetInstance(); try { entities.HT_PHAM_VI.AddObject(obj); entities.SaveChanges(); } catch (System.Exception ex) { kq = false; LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); throw ex; } finally { entities = null; } return(kq); }
public ApplicationConstant.ResponseStatus Luu( ref PHAM_VI objPhamVi, ref ApplicationConstant.QuanTriHeThongResponseMessage responseMessage, ref BS_ResponseDetail bsRetDetail ) { bool kq = true; try { DS_HT_PHAM_VI dsPhamVi = new DS_HT_PHAM_VI(); using (TransactionScope trans = new TransactionScope()) { // Xóa các dữ liệu phân quyền bị xóa List <HT_PHAM_VI> lstPhamVi = new List <HT_PHAM_VI>(); if (objPhamVi.MA_PVI_LOAI.Equals(BusinessConstant.LOAI_PHAM_VI.DON_VI.layGiaTri())) { lstPhamVi = dsPhamVi.GetPhamViDonVi_ByDoiTuong(objPhamVi.MA_DTUONG_LOAI, objPhamVi.MA_DTUONG); } if (objPhamVi.MA_PVI_LOAI.Equals(BusinessConstant.LOAI_PHAM_VI.DIA_LY.layGiaTri())) { lstPhamVi = dsPhamVi.GetPhamViDiaLy_ByDoiTuong(objPhamVi.MA_DTUONG_LOAI, objPhamVi.MA_DTUONG); } foreach (HT_PHAM_VI item in lstPhamVi) { kq = dsPhamVi.Xoa(item); if (!kq) { break; } } // Thêm các dữ liệu phân quyền mới if (kq) { foreach (int item in objPhamVi.ID_PVI) { HT_PHAM_VI htPhamVi = new HT_PHAM_VI(); //htPhamVi.ID_DTUONG_LOAI = objPhamVi.ID_DTUONG; htPhamVi.MA_DTUONG_LOAI = objPhamVi.MA_DTUONG_LOAI; htPhamVi.ID_DTUONG = objPhamVi.ID_DTUONG; htPhamVi.MA_DTUONG = objPhamVi.MA_DTUONG; htPhamVi.PHAN_LOAI = objPhamVi.PHAN_LOAI.ElementAt(objPhamVi.ID_PVI.IndexOf(item)); htPhamVi.MA_PVI_LOAI = objPhamVi.MA_PVI_LOAI; htPhamVi.ID_PVI = item; htPhamVi.MA_PVI = objPhamVi.MA_PVI.ElementAt(objPhamVi.ID_PVI.IndexOf(item)); htPhamVi.TTHAI_BGHI = BusinessConstant.TrangThaiBanGhi.SU_DUNG.layGiaTri(); htPhamVi.TTHAI_NVU = BusinessConstant.TrangThaiNghiepVu.DA_DUYET.layGiaTri(); htPhamVi.MA_DVI_QLY = objPhamVi.MA_DVI_QLY; htPhamVi.MA_DVI_TAO = objPhamVi.MA_DVI_TAO; htPhamVi.NGAY_NHAP = objPhamVi.NGAY_NHAP; htPhamVi.NGUOI_NHAP = objPhamVi.NGUOI_NHAP; htPhamVi.NGAY_CNHAT = objPhamVi.NGAY_CNHAT; htPhamVi.NGUOI_CNHAT = objPhamVi.NGUOI_CNHAT; kq = dsPhamVi.Them(htPhamVi); if (!kq) { break; } } } if (kq) { trans.Complete(); responseMessage = ApplicationConstant.QuanTriHeThongResponseMessage.M_ResponseMessage_QuanTriHeThong_ThanhCong; bsRetDetail.Result = ApplicationConstant.OperationStatus.Successful.layNgonNgu(); bsRetDetail.Detail = responseMessage.layGiaTri(); return(ApplicationConstant.ResponseStatus.THANH_CONG); } else { responseMessage = ApplicationConstant.QuanTriHeThongResponseMessage.M_ResponseMessage_QuanTriHeThong_KhongThanhCong; bsRetDetail.Result = ApplicationConstant.OperationStatus.Failed.layNgonNgu(); bsRetDetail.Detail = responseMessage.layGiaTri(); return(ApplicationConstant.ResponseStatus.KHONG_THANH_CONG); } } } catch (Exception ex) { responseMessage = ApplicationConstant.QuanTriHeThongResponseMessage.M_ResponseMessage_QuanTriHeThong_KhongThanhCong; bsRetDetail.Result = ApplicationConstant.OperationStatus.Failed.layNgonNgu(); bsRetDetail.Detail = responseMessage.layGiaTri(); LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); throw ex; } }