public static void AddMemberUser(BizPortalSessionContext context, Member member, IList <MemberUser> memberUsers, int funtionId, int pageID, string action, ref string message, ref int warningCount, ref int errorCount) { string lang = context.CurrentLanguage.Code; string functionName = ""; IList <MemberUser> newUsers = memberUsers; foreach (MemberUser memberUser in newUsers) { using (ITransaction tx = context.PersistenceSession.BeginTransaction()) { try { #region Validation Zone // 1. ตรวจสอบว่ามีสิทธิ์ใช้งานฟังก์ชัน ///////////////////////////////////////////////////// MaintenanceWorkflow addMemberUserWorkflow = GetFunctionMaintenanceWorkflow(context.User, funtionId); if (null == addMemberUserWorkflow || addMemberUserWorkflow.MemberFunction == null) { warningCount++; message += Messages.Genaral.IsNotAddMemberUser.Format(lang); } #endregion Validation Zone #region Create Transaction Zone if (warningCount == 0) { BizPortalFunction function = addMemberUserWorkflow.MemberFunction.Function; functionName = Messages.MemberUser.AddMemberUser.Format(lang, memberUser.LoginName); memberUser.Member = member; AddMemberUserTransaction mainTransaction = new AddMemberUserTransaction(context, addMemberUserWorkflow, DateTime.Now, member, memberUser); mainTransaction.Transit(context, addMemberUserWorkflow, RemarkTransaction.AddMemberUser(memberUser), TransitionEventCode.SubmitEvent); mainTransaction.Persist(context); tx.Commit(); message += String.Format("- {0} {1} {2}", functionName, Messages.Genaral.Success.Format(lang), Messages.Genaral.PendingApproval.Format(lang)); context.Log(funtionId, pageID, 0, action, functionName); } #endregion Create Transaction Zone } catch (Exception ex) { #region Exception Zone tx.Rollback(); warningCount++; context.PersistenceSession.Clear(); context.Log(funtionId, pageID, 0, action , IBankException.LogMessageProgramError(ex, ExceptionMessages.AddMemberUserTransactionError_MemberUserService.Code + '-' + functionName + message)); message = ExceptionMessages.AddMemberUserTransactionError_MemberUserService.Message; #endregion Exception Zone } } } }
public static void TerminateTransaction(BizPortalSessionContext context, int functionId, int pageId, MaintenanceWorkflow fwfTarget, MemberUserGroup mugTarget, ref string message, ref int warningCount, bool approval) { string functionName = ""; string lange = context.CurrentLanguage.Code; using (ITransaction tx = context.PersistenceSession.BeginTransaction()) { try { #region Validate Zone MaintenanceWorkflow fw = GetFunctionMaintenanceWorkflow(context.User, functionId); if (OpenTransactionsUsingWorkflow(fwfTarget.GetNumberOfOpenTransactions(context), ref message, ref warningCount, lange)) { message = message + "<br/>"; } if (fwfTarget.IsNotFinalized) { warningCount++; message = String.Format("- {0}<br/>", Messages.Genaral.TransactionPendingApproval.Format(lange, Messages.FunctionWorkFlow.TerminateFunctionWorkFlow.Format(lange, fwfTarget.MemberFunction.Function.Title, mugTarget.Title))); } if (IsNotPermistion(fw, ref message, ref warningCount, lange)) { message = message + "<br/>"; } #endregion Validate Zone #region Create Transaction Zone if (warningCount == 0) { functionName = Messages.FunctionWorkFlow.TerminateFunctionWorkFlow.Format(lange, fwfTarget.MemberFunction.Function.Title, mugTarget.Title); TerminateMaintenanceWorkflowTransaction transactionMember = new TerminateMaintenanceWorkflowTransaction(context, fw, DateTime.Now, context.Member, fwfTarget); transactionMember.Transit(context, fw, functionName, TransitionEventCode.SubmitEvent); transactionMember.Persist(context); tx.Commit(); message = String.Format("- {0} <br/>", Messages.Genaral.TransactionSubmitedForPendingApproval.Format(lange, functionName)); context.Log(functionId, pageId, 0, ActionLog.BankAdminFunction.TerminateFunctionWorkflow, functionName); } #endregion Create Transaction Zone } catch (Exception ex) { #region Exception Zone tx.Rollback(); warningCount++; context.Log(functionId, pageId, 0, ActionLog.BankAdminFunction.TerminateFunctionWorkflow , IBankException.LogMessageProgramError(ex, ExceptionMessages.TerminateTransactionMaintenanceWorkflow_BankGroupsManagement.Code + '-' + functionName + message)); message = ExceptionMessages.TerminateTransactionMaintenanceWorkflow_BankGroupsManagement.Message; #endregion Exception Zone } } }
public static void TerminateTransaction(BizPortalSessionContext context, int functionId, int pageId, UserGroupUser uguTarget, ref string message, ref int warningCount) { string functionName = ""; string lange = context.CurrentLanguage.Code; using (ITransaction tx = context.PersistenceSession.BeginTransaction()) { try { if (uguTarget.IsNotFinalized) { warningCount++; message = Messages.Genaral.TransactionApproved.Format(lange); } if (warningCount == 0) { MaintenanceWorkflow fw = GetFunctionMaintenanceWorkflow(context.User, functionId); functionName = Messages.UserGroupUser.TerminateUserGroupUser.Format(lange, uguTarget.User.LoginName, uguTarget.Group.Title); if (fw.MemberFunction == null) { warningCount++; message = Messages.Genaral.IsNotMemberFunction.Format(context.CurrentLanguage.Code); } BizPortalFunction function = fw.MemberFunction.Function; TerminateMemberGroupUserTransaction transactionMember = new TerminateMemberGroupUserTransaction(context, fw, DateTime.Now, context.Member, uguTarget); transactionMember.Transit(context, fw, functionName, TransitionEventCode.SubmitEvent); transactionMember.Persist(context); tx.Commit(); message = String.Format("{0} <br/>", Messages.Genaral.TransactionSubmitedForPendingApproval.Format(lange, functionName)); context.Log(functionId, pageId, 0, ActionLog.BankAdminFunction.TerminateMemberGroupUser, functionName); } } catch (Exception ex) { tx.Rollback(); warningCount++; context.Log((int)functionId, pageId, 0, ActionLog.BankAdminFunction.TerminateMemberGroupUser , IBankException.LogMessageProgramError(ex, ExceptionMessages.TerminateTransactionUserGroupUserError_Role.Code + '-' + functionName + message)); message = ExceptionMessages.TerminateTransactionUserGroupUserError_Role.Message; } } }
public static void Enable(BizPortalSessionContext context, int functionId, int pageID, IList <long> listId, string action, ref string message, ref int warningCount, Member memberTarget) { string lange = context.CurrentLanguage.Code; string functionName = ""; foreach (long userId in listId) // 1 2 3 n select { using (ITransaction tx = context.PersistenceSession.BeginTransaction()) { try { #region Validation Zone MemberUser userTarget = context.PersistenceSession.Get <MemberUser>(userId); functionName = Messages.MemberUser.EnableUser.Format(lange, userTarget.LoginName); // 1. ตรวจสอบ IsNotFinalized //////////////////////////////////////////////////// if (userTarget.IsNotFinalized) { warningCount++; message += string.Format("- {0} {1}", Messages.Genaral.UserTransactionWaitingApproved.Format(lange, functionName), newLineHTML); } // 2. ตรวจสอบว่ามีตัวตนบน Active Directory ////////////////////////////////////////// if (userTarget is ActiveDirectoryUser) { IList <UserPrincipal> userPrincipal = ActiveDirectoryUser.GetADUsers(context , System.Configuration.ConfigurationManager.AppSettings["ADUser"].ToString() , System.Configuration.ConfigurationManager.AppSettings["ADPass"].ToString()); foreach (UserPrincipal adUser in userPrincipal) { if (userTarget.LoginName.Equals(adUser.SamAccountName, StringComparison.InvariantCultureIgnoreCase)) { userTarget.TempID = 1; } } if (userTarget.TempID != 1) { warningCount++; message += "- ไม่สามารถ ยกเลิกระงับการใช้งาน : " + userTarget.LoginName + " ได้ เนื่องจากไม่พบผู้ใช้งานใน Active Directory Server"; } } // 3. ตรวจสอบว่ามีสิทธิ์ใช้งานฟังก์ชัน ///////////////////////////////////////////////////// MaintenanceWorkflow workflow = GetFunctionMaintenanceWorkflow(context.User, functionId); if (workflow.MemberFunction == null) { warningCount++; message = Messages.Genaral.IsNotMemberFunction.Format(context.CurrentLanguage.Code); } #endregion Validation Zone #region Create Transaction Zone if (warningCount == 0) { BizPortalFunction function = workflow.MemberFunction.Function; EnableUserTransaction enableUserTransaction = new EnableUserTransaction(context, workflow, DateTime.Now, memberTarget, userTarget); enableUserTransaction.Transit(context, workflow, functionName, TransitionEventCode.SubmitEvent); enableUserTransaction.Persist(context); tx.Commit(); message += String.Format("- {0} {1} {2} {3}", functionName, Messages.Genaral.Success.Format(lange), Messages.Genaral.PendingApproval.Format(lange), newLineHTML); context.Log(functionId, pageID, 0, action, functionName); } #endregion Create Transaction Zone } catch (Exception ex) { #region Exception Zone tx.Rollback(); warningCount++; context.Log(functionId, pageID, 0, action , IBankException.LogMessageProgramError(ex, ExceptionMessages.EnableUserTransactionError_UserService.Code + '-' + functionName + message)); message = ExceptionMessages.EnableUserTransactionError_UserService.Message; #endregion Exception Zone } } } }
public static void Disable(BizPortalSessionContext context, int functionId, int pageID, IList <long> listId, string action, ref string message, ref int warningCount, Member memberTarget) { string lange = context.CurrentLanguage.Code; string functionName = ""; foreach (long ID in listId) // 1 2 3 n select { using (ITransaction tx = context.PersistenceSession.BeginTransaction()) { try { #region Validation Zone MemberUser userTarget = context.PersistenceSession.Get <MemberUser>(ID); functionName = Messages.MemberUser.DisableUser.Format(lange, userTarget.LoginName); // 1. ตรวจสอบ IsNotFinalized //////////////////////////////////////////////////// if (userTarget.IsNotFinalized) { warningCount++; message += string.Format("- {0} {1}", Messages.Genaral.UserTransactionWaitingApproved.Format(lange, functionName), newLineHTML); } // 2. ตรวจสอบว่ามีสิทธิ์ใช้งานฟังก์ชัน ///////////////////////////////////////////////////// MaintenanceWorkflow workflow = GetFunctionMaintenanceWorkflow(context.User, functionId); if (workflow.MemberFunction == null) { warningCount++; message += Messages.Genaral.IsNotMemberFunction.Format(context.CurrentLanguage.Code); } #endregion Validation Zone #region Create Transaction Zone if (warningCount == 0) { BizPortalFunction function = workflow.MemberFunction.Function; DisableUserTransaction disableUserTransaction = new DisableUserTransaction(context, workflow, DateTime.Now, memberTarget, userTarget); disableUserTransaction.Transit(context, workflow, functionName, TransitionEventCode.SubmitEvent); disableUserTransaction.Persist(context); tx.Commit(); message += String.Format("- {0} {1} {2} {3}", functionName, Messages.Genaral.Success.Format(lange), Messages.Genaral.PendingApproval.Format(lange), newLineHTML); context.Log(functionId, pageID, 0, action, functionName); } #endregion Create Transaction Zone } catch (Exception ex) { #region Exception Zone tx.Rollback(); warningCount++; context.Log(functionId, pageID, 0, action , IBankException.LogMessageProgramError(ex, ExceptionMessages.DisableUserTransactionError_UserService.Code + '-' + functionName + message)); message = ExceptionMessages.DisableUserTransactionError_UserService.Message; #endregion Exception Zone } } } }
public static void ApproveFinanceTransaction(BizPortalSessionContext context, string[] eventNameAndId, string remark, ref string message, ref int warningCount, DateTime newValueDate = default(DateTime)) { string lange = context.CurrentLanguage.Code; string mark = ""; ServiceWorkflowOutstandingTransaction wat = null; using (ITransaction tx = context.PersistenceSession.BeginTransaction()) { var eventNameEng = TransitionEventCode.CreateEvent; try { int eventID = int.Parse(eventNameAndId[2]); //Find event var t = TransitionEventCode.CreateEvent; switch (int.Parse(eventNameAndId[2])) { case (int)TransitionEventCode.StopEvent: t = TransitionEventCode.StopEvent; eventNameEng = TransitionEventCode.StopEvent; break; case (int)TransitionEventCode.ApproveFinalEvent: t = TransitionEventCode.ApproveFinalEvent; eventNameEng = TransitionEventCode.ApproveFinalEvent; break; case (int)TransitionEventCode.ApproveFirstEvent: t = TransitionEventCode.ApproveFirstEvent; eventNameEng = TransitionEventCode.ApproveFirstEvent; break; case (int)TransitionEventCode.ApproveIntermediateEvent: t = TransitionEventCode.ApproveIntermediateEvent; eventNameEng = TransitionEventCode.ApproveIntermediateEvent; break; case (int)TransitionEventCode.RejectEvent: t = TransitionEventCode.RejectEvent; eventNameEng = TransitionEventCode.RejectEvent; break; case (int)TransitionEventCode.ReturnEvent: t = TransitionEventCode.ReturnEvent; eventNameEng = TransitionEventCode.ReturnEvent; break; } wat = new ServiceWorkflowOutstandingTransaction(context, eventNameAndId[1]); if (newValueDate != default(DateTime)) { wat.Transaction.EffectiveDate = newValueDate; } mark = wat.CurrentStateRemark; // is not use wat.CurrentStateRemark case if (warningCount == 0) { ValidateWorkflow(wat, lange, ref warningCount, ref message); } else { return; } //Validate are Approve Event only if (eventID == (int)TransitionEventCode.ApproveFirstEvent || eventID == (int)TransitionEventCode.ApproveFinalEvent || eventID == (int)TransitionEventCode.ApproveIntermediateEvent) { if (warningCount == 0) { ValidateValueDate(context, wat.Transaction, ref warningCount, ref message); } else { return; } if (warningCount == 0) { ValidateAmountLimit(context, wat.Transaction, ref warningCount, ref message); } else { return; } if (warningCount == 0) { ValidateDataEntry(context, wat.Transaction, ref warningCount, ref message); } else { return; } } if (warningCount == 0) { wat.Transaction.Transit(context, wat.Workflow, mark, t); wat.Transaction.Remark = remark; wat.Transaction.Persist(context); //Hard if (wat.Transaction.DebitWindow.From <= DateTime.Now && DateTime.Now <= wat.Transaction.DebitWindow.To && wat.Transaction.CurrentStateCode == StateCode.Approved) { ((FundsTransferTransactionOneToMany)wat.Transaction).Transit(context, wat.Workflow, "Timeout debit transaction [" + wat.TransactionNo + "]", TransitionEventCode.DebitTimeoutEvent); context.Persist(wat.Transaction.CurrentState); } tx.Commit(); message = string.Format("{0} {1}", eventNameAndId[0], Messages.Genaral.ApprovalSuccess.Format(context.CurrentLanguage.Code)); context.Log(wat.Transaction.FunctionID, 0, 0, GetFunctionName(lange, eventNameEng), mark); } } catch (Exception exception) { warningCount++; tx.Rollback(); context.PersistenceSession.Clear(); message = string.Empty; message += ExceptionMessages.ApproveFinanceException; if (wat != null) { context.Log(wat.Transaction.FunctionID, ClientWebPageID.ApproveView, 0, ActionLog.Exception, IBankException.LogMessageProgramError(exception, ExceptionMessages.ApproveFinanceException.Code + "-" + string.Format("ฟังก์ชัน : {0} : {1}", GetFunctionName(lange, eventNameEng), mark))); } } } }
public static void ApproveFinanceOverValueDateTransaction(BizPortalSessionContext context, string[] eventNameAndId, string remark, ref string message, ref int warningCount) { ServiceWorkflowOutstandingTransaction wat = null; try { wat = new ServiceWorkflowOutstandingTransaction(context, eventNameAndId[1]); DateTime originalValueDate = wat.Transaction.EffectiveDate; string originalTransferFee = wat.Transaction.TotalFee(); //Find new EffectiveDate DateTime effective; TimeInterval debitWindow; TimeInterval exportWindow; var standard = wat.Transaction.Member. GetEffectiveMemberOrStandardFundsTransferServiceProfile(context, wat.Transaction.Service.ServiceCode, wat.Transaction.PostedTS); standard.FindNearestPossibleTransactionDates(context, out effective, out debitWindow, out exportWindow); wat.Transaction.EffectiveDate = effective; wat.Transaction.DebitWindow = debitWindow; wat.Transaction.ExportWindow = exportWindow; string logMessage = string.Format( "วันที่รายการมีผลเดิม {0} เปลี่ยนเป็น วันที่ {1} ค่าธรรมเนียม {2}", originalValueDate.DateFormat(), effective.DateFormat(), originalTransferFee); if (warningCount == 0) { ValidateValueDate(context, wat.Transaction, ref warningCount, ref message); } else { return; } if (warningCount == 0) { ValidateAmountLimit(context, wat.Transaction, ref warningCount, ref message); } else { return; } if (warningCount == 0) { ValidateDataEntry(context, wat.Transaction, ref warningCount, ref message); } else { return; } context.Log(wat.Transaction.FunctionID, 0, 0, "Change Value date of transaction", logMessage); //Call Method Approv finance ApproveFinanceTransaction(context, eventNameAndId, remark, ref message, ref warningCount); } catch (Exception exception) { warningCount++; context.PersistenceSession.Clear(); message = string.Empty; message += ExceptionMessages.ApproveFinanceException; if (wat != null) { context.Log(wat.Transaction.FunctionID, ClientWebPageID.ApproveView, 0, ActionLog.Exception, IBankException.LogMessageProgramError(exception, ExceptionMessages.ChangeValueDateException.Code + "-" + string.Format("ฟังก์ชัน : {0} : {1}", "Change Value date of transaction", wat.CurrentStateRemark))); } } }
//Edit v1.1 add parameter mamberTarget of transaction public static void Expire(BizPortalSessionContext context, int funtionId, int pageID, IList <long> listId, string action, ref IList <MessageRespone> message, ref int warningCount, Member memberTarget) { string lange = context.CurrentLanguage.Code; string functionName = ""; foreach (long userId in listId) // 1 2 3 n select { using (ITransaction tx = context.PersistenceSession.BeginTransaction()) { try { #region Validation Zone MemberUser mem = context.PersistenceSession.Get <MemberUser>(userId); functionName = Messages.MemberUser.ExpireUser.Format(lange, mem.LoginName); // 1. ตรวจสอบ IsNotFinalized //////////////////////////////////////////////////// if (mem.IsNotFinalized) { warningCount++; message.Add(new MessageRespone { IsSuccess = false, Message = Messages.Genaral.ExistingTransactionOfUserWaitingApproved.Format(lange, mem.LoginName), }); } // 2. ตรวจสอบว่ามีสิทธิ์ใช้งานฟังก์ชัน ///////////////////////////////////////////////////// MaintenanceWorkflow workflow = GetFunctionMaintenanceWorkflow(context.User, funtionId); if (workflow.MemberFunction == null) { warningCount++; message.Add(new MessageRespone { IsSuccess = false, Message = Messages.Genaral.IsNotMemberFunction.Format(context.CurrentLanguage.Code), }); } #endregion Validation Zone #region Create Transaction Zone if (warningCount == 0) { BizPortalFunction function = workflow.MemberFunction.Function; TerminateMemberUserTransaction transactionMember = new TerminateMemberUserTransaction(context, workflow, DateTime.Now, memberTarget, mem); transactionMember.Transit(context, workflow, functionName, TransitionEventCode.SubmitEvent); transactionMember.Persist(context); tx.Commit(); message.Add(new MessageRespone { IsSuccess = true, Message = String.Format("{0} {1} {2}", functionName, Messages.Genaral.Success.Format(lange), Messages.Genaral.PendingApproval.Format(lange)), }); context.Log(funtionId, pageID, 0, action, functionName); } #endregion Create Transaction Zone } catch (Exception ex) { #region Exception Zone tx.Rollback(); string tempMessage = ""; foreach (var item in message) { tempMessage = tempMessage + item.Message + "<br />"; } warningCount++; context.Log(funtionId, pageID, 0, action , IBankException.LogMessageProgramError(ex, ExceptionMessages.TerminateMemberUserTransactionError_MemberUserService.Code + '-' + functionName + tempMessage)); message.Add(new MessageRespone { IsSuccess = false, Message = ExceptionMessages.TerminateMemberUserTransactionError_MemberUserService.Message, }); #endregion Exception Zone } } } }
public static void AddTransaction(BizPortalSessionContext context, int functionId, int pageId, MaintenanceWorkflow fwfTarget, MemberUserGroup mugTarget, ref string message, ref int warningCount, bool approval) { string functionName = ""; string lange = context.CurrentLanguage.Code; IList <MaintenanceWorkflow> ListOfMaintenanceWorkflowNotFinalized = GetIsNotFinalizedMaintenanceWorkf(context, fwfTarget.MemberFunction); using (ITransaction tx = context.PersistenceSession.BeginTransaction()) { try { #region Validate Zone MaintenanceWorkflow fw = GetFunctionMaintenanceWorkflow(context.User, functionId); if (fwfTarget.CreatorGroup != null) { foreach (MaintenanceWorkflow item in ListOfMaintenanceWorkflowNotFinalized) { if (item.CreatorGroup != null) { if (item.CreatorGroup.ID == fwfTarget.CreatorGroup.ID) { warningCount++; message = String.Format("- {0}<br/>", Messages.Genaral.TransactionPendingApproval.Format(lange, Messages.FunctionWorkFlow.AddFunctionWorkFlow.Format(lange, fwfTarget.MemberFunction.Function.Title, mugTarget.Title))); } } } } else { foreach (MaintenanceWorkflow item in ListOfMaintenanceWorkflowNotFinalized) { if (item.ApprovalTiers.Count != 0) { if (item.ApprovalTiers[0].ApproverGroup.ID == fwfTarget.ApprovalTiers[0].ApproverGroup.ID) { warningCount++; message = String.Format("- {0}<br/>", Messages.Genaral.TransactionPendingApproval.Format(lange, Messages.FunctionWorkFlow.AddFunctionWorkFlow.Format(lange, fwfTarget.MemberFunction.Function.Title, mugTarget.Title))); } } } } if (IsNotPermistion(fw, ref message, ref warningCount, lange)) { message = message + "<br/>"; } #endregion Validate Zone #region Create Transaction Zone if (warningCount == 0) { functionName = Messages.FunctionWorkFlow.AddFunctionWorkFlow.Format(lange, fwfTarget.MemberFunction.Function.Title, mugTarget.Title); AddMaintenanceWorkflowTransaction transactionMember = new AddMaintenanceWorkflowTransaction ( context, fw, DateTime.Now, context.Member, fwfTarget ); transactionMember.Transit(context, fw, functionName, TransitionEventCode.SubmitEvent); transactionMember.Persist(context); tx.Commit(); message = String.Format("- {0} <br/>", Messages.Genaral.TransactionSubmitedForPendingApproval.Format(lange, functionName)); context.Log(functionId, pageId, 0, ActionLog.BankAdminFunction.AddFunctionWorkflow, functionName); } #endregion Create Transaction Zone } catch (Exception ex) { #region Exception Zone tx.Rollback(); warningCount++; context.Log(functionId, pageId, 0, ActionLog.BankAdminFunction.AddFunctionWorkflow , IBankException.LogMessageProgramError(ex, ExceptionMessages.AddTransactionMaintenanceWorkflow_BankGroupsManagement.Code + "-" + functionName + message)); message = ExceptionMessages.AddTransactionMaintenanceWorkflow_BankGroupsManagement.Message; #endregion Exception Zone } } }