public ServiceResult <TR01C> Update(TR01C entity) { var errMsg = ""; using (var trans = _Entity.Database.BeginTransaction(IsolationLevel.Snapshot)) { try { if (entity.TR01C_ID == 0) { _Entity.Entry(entity).State = EntityState.Added; } else { _Entity.Entry(entity).State = EntityState.Modified; } var result = _Entity.SaveChanges(); trans.Commit(); CacheHelper.Invalidate("TR01C"); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { errMsg = ErrorHandler.GetDbEntityValidationExceptionMessage(ex); } catch (Exception ex) { errMsg = ErrorHandler.GetSQLMessage(ex); } } return(new ServiceResult <TR01C>() { Data = entity, Message = errMsg }); }
public static TR01CModel FromEntity(TR01C entity) { var data = new TR01CModel(); if (entity != null) { var objectHelper = new ActWeis.Utility.ObjectHelper(); objectHelper.CopyValue(entity, data); if (data.INV_MY.HasValue) { data.INV_MY = decimal.Parse(data.INV_MY.Value.ToString("G29")); } data.ARR_QT = decimal.Parse(data.ARR_QT.ToString("G29")); data.CUR_RT = decimal.Parse(data.CUR_RT.ToString("G29")); //資料處理 //var item = CacheCommonDataModule.GetBA02A().Where(x => x.BA02A_ID == entity.BA02A_ID).FirstOrDefault(); //if (item != null) //{ // data.ITM_NO = item.ITM_NO; // data.ITM_NM = item.ITM_NM; //} } return(data); }
/// <summary>viewmodel to entity </summary> /// <param name="entity"></param> private static TR01C ToEntity(TR01CModel data) { //entity = data; var entity = new TR01C(); if (data != null) { //資料處理 var objectHelper = new ActWeis.Utility.ObjectHelper(); objectHelper.CopyValue(data, entity); } return(entity); }
public static TR01C BeforSave(TR01CModel data) { var TR01C = new TR01C(); if (data.TR01C_ID == 0)//Adding New { data.CREATE_USER = UserInfo.Id; data.CREATE_DATE = DateTime.Now; } else//Update { var _Service = new TR01Service(); TR01C = _Service.GetC(x => x.TR01C_ID == data.TR01C_ID).First(); data.CREATE_USER = TR01C.CREATE_USER; data.CREATE_DATE = TR01C.CREATE_DATE; } data.UPDATE_USER = UserInfo.Id; data.UPDATE_DATE = DateTime.Now; return(ToEntity(data)); }
/// <summary>刪除</summary> /// <param name="key">Master 的 Key</param> /// <returns>被trigger擋下=> 取回資料, 被其他人刪單=> new TR01C</returns> public ServiceResult <TR01C> DeleteC(int key) { string errMsg = ""; var master = _Entity.TR01C.FirstOrDefault(x => x.TR01C_ID == key); using (var trans = _Entity.Database.BeginTransaction(IsolationLevel.Snapshot)) { try { if (master != null && master.TR01C_ID > 0) { _Entity.TR01C.Remove(master); _Entity.SaveChanges(); CacheHelper.Invalidate("TR01C"); } else { errMsg = "資料已被刪除";//被其他人刪單 ErrorHandler.GetCodeName("W011"); master = new TR01C(); } trans.Commit(); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { errMsg = ErrorHandler.GetDbEntityValidationExceptionMessage(ex); } catch (Exception ex) { errMsg = ErrorHandler.GetSQLMessage(ex); } } return(new ServiceResult <TR01C>() { Data = master, Message = errMsg }); }