using EasyBL.WebApi.Message; using Entity.Sugar; using SqlSugar; using SqlSugar.Base; using System; namespace EasyBL.WEBAPP.WSM { public class OfficeTemplate_UpdService : ServiceBase { #region Office模版管理(單筆查詢) /// /// Office模版管理(單筆查詢) /// /// /// public ResponseMessage QueryOne(RequestMessage i_crm) { ResponseMessage rm = null; string sMsg = null; var db = SugarBase.GetIntance(); try { do { var sTemplID = _fetchString(i_crm, @"TemplID"); var oEntity = db.Queryable ((t1, t2, t3) => new object[] { JoinType.Left, t1.OrgID == t2.OrgID && t1.CreateUser == t2.MemberID, JoinType.Left, t1.OrgID == t3.OrgID && t1.ModifyUser == t3.MemberID } ) .Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.TemplID == sTemplID) .Select((t1, t2, t3) => new OTB_SYS_OfficeTemplate { TemplID = SqlFunc.GetSelfAndAutoFill(t1.TemplID), CreateUserName = t2.MemberName, ModifyUserName = t3.MemberName }) .Single(); rm = new SuccessResponseMessage(null, i_crm); rm.DATA.Add(BLWording.REL, oEntity); } while (false); } catch (Exception ex) { sMsg = Util.GetLastExceptionMsg(ex); LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(OfficeTemplate_UpdService), "", "QueryOne(Office模版管理(單筆查詢))", "", "", ""); } finally { if (null != sMsg) { rm = new ErrorResponseMessage(sMsg, i_crm); } } return rm; } #endregion Office模版管理(單筆查詢) #region Office模版管理(新增) /// /// Office模版管理(新增) /// /// todo: describe i_crm parameter on UpdImportCustomers /// public ResponseMessage Insert(RequestMessage i_crm) { ResponseMessage rm = null; string sMsg = null; try { rm = SugarBase.ExecTran(db => { do { var oEntity = _fetchEntity(i_crm); _setEntityBase(oEntity, i_crm); var iRel = db.Insertable(oEntity).ExecuteCommand(); rm = new SuccessResponseMessage(null, i_crm); rm.DATA.Add(BLWording.REL, iRel); } while (false); return rm; }); } catch (Exception ex) { sMsg = Util.GetLastExceptionMsg(ex); LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(OfficeTemplate_UpdService), @"Office模版管理", @"Add(Office模版管理(新增))", @"", @"", @""); } finally { if (null != sMsg) { rm = new ErrorResponseMessage(sMsg, i_crm); } } return rm; } #endregion Office模版管理(新增) #region Office模版管理(修改) /// /// Office模版管理(修改) /// /// todo: describe i_crm parameter on UpdImportCustomers /// public ResponseMessage Update(RequestMessage i_crm) { ResponseMessage rm = null; string sMsg = null; try { rm = SugarBase.ExecTran(db => { do { var oNewEntity = _fetchEntity(i_crm); _setEntityBase(oNewEntity, i_crm); var iRel = db.Updateable(oNewEntity) .IgnoreColumns(x => new { x.CreateUser, x.CreateDate }).ExecuteCommand(); rm = new SuccessResponseMessage(null, i_crm); rm.DATA.Add(BLWording.REL, iRel); } while (false); return rm; }); } catch (Exception ex) { sMsg = Util.GetLastExceptionMsg(ex); LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(OfficeTemplate_UpdService), @"Office模版管理", @"Update(Office模版管理(修改))", @"", @"", @""); } finally { if (null != sMsg) { rm = new ErrorResponseMessage(sMsg, i_crm); } } return rm; } #endregion Office模版管理(修改) #region Office模版管理(刪除) /// /// Office模版管理(刪除) /// /// todo: describe i_crm parameter on UpdImportCustomers /// public ResponseMessage Delete(RequestMessage i_crm) { ResponseMessage rm = null; string sMsg = null; try { rm = SugarBase.ExecTran(db => { do { var sTemplID = _fetchString(i_crm, @"TemplID"); var oOfficeTemplate = db.Queryable().Single(x => x.TemplID == sTemplID); var iRel = db.Deleteable().Where(x => x.OrgID == i_crm.ORIGID && x.TemplID == sTemplID).ExecuteCommand(); i_crm.DATA.Add("FileID", oOfficeTemplate.FileID); i_crm.DATA.Add("IDType", "parent"); new CommonService().DelFile(i_crm); rm = new SuccessResponseMessage(null, i_crm); rm.DATA.Add(BLWording.REL, iRel); } while (false); return rm; }); } catch (Exception ex) { sMsg = Util.GetLastExceptionMsg(ex); LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(OfficeTemplate_UpdService), @"Office模版管理", @"Delete(Office模版管理(刪除))", @"", @"", @""); } finally { if (null != sMsg) { rm = new ErrorResponseMessage(sMsg, i_crm); } } return rm; } #endregion Office模版管理(刪除) #region Office模版管理(查詢筆數) /// /// Office模版管理(查詢筆數) /// /// /// public ResponseMessage QueryCout(RequestMessage i_crm) { ResponseMessage rm = null; string sMsg = null; var db = SugarBase.GetIntance(); try { do { var sTemplID = _fetchString(i_crm, @"TemplID"); var iCout = db.Queryable() .Where(x => x.OrgID == i_crm.ORIGID) .WhereIF(!string.IsNullOrEmpty(sTemplID), x => x.TemplID == sTemplID) .Count(); rm = new SuccessResponseMessage(null, i_crm); rm.DATA.Add(BLWording.REL, iCout); } while (false); } catch (Exception ex) { sMsg = Util.GetLastExceptionMsg(ex); LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(OfficeTemplate_UpdService), "", "QueryCout(Office模版管理(查詢筆數))", "", "", ""); } finally { if (null != sMsg) { rm = new ErrorResponseMessage(sMsg, i_crm); } } return rm; } #endregion Office模版管理(查詢筆數) } }