/// <summary> /// DisableUsers /// </summary> /// <param name="context">SessionContext is persist</param> /// <param name="funtionId">function BankAdminFunctionID</param> /// <param name="listId">users target</param> /// <param name="message">string ref : message</param> /// <param name="warningCount">int ref : count of warning</param> /// <param name="errorCount">int ref : count of error</param> public static void DisableUsers(BizPortalSessionContext context, int funtionId, IList <int> listId, ref string message, ref int warningCount, ref int errorCount) { MemberUser userTarget = null; string lang = context.CurrentLanguage.Code; string functionName = ""; BizPortalFunction function = null; foreach (int ID in listId) // 1 2 3 n select { using (ITransaction tx = context.PersistenceSession.BeginTransaction()) { try { MemberUser mem = context.PersistenceSession.Get <MemberUser>(ID); userTarget = mem; functionName = Messages.MemberUser.DisableUser.Format(lang, userTarget.LoginName); if (userTarget.IsNotFinalized == true) { warningCount++; message += string.Format("- {0} <br/>", Messages.Genaral.UserTransactionWaitingApproved.Format(lang, functionName)); } MaintenanceWorkflow workflow = GetFunctionWorkflowFormFunctionID(funtionId, context.User); function = workflow.MemberFunction.Function; DisableUserTransaction disableUserTransaction = new DisableUserTransaction(context, workflow, DateTime.Now, context.Member, userTarget); disableUserTransaction.Transit(context, workflow, functionName, TransitionEventCode.SubmitEvent); disableUserTransaction.Persist(context); tx.Commit(); message += String.Format("- {0} {1} {2} <br/>", functionName, Messages.Genaral.Success.Format(lang), Messages.Genaral.PendingApproval.Format(lang)); context.Log(funtionId, 0, 0, Messages.MemberUser.DisableUser.Format(lang, ""), functionName); } catch { tx.Rollback(); errorCount++; context.Log((int)funtionId, 0, 0, Messages.MemberUser.DisableUser.Format(lang, ""), functionName + message); //message += Messages.Genaral.TransactionException.Format(lang, ex.Message) + "<br/>"; //context.Log((int)funtionId, 0, 0, Messages.MemberUser.DisableUser.Format(lang, ""), // functionName + Messages.Genaral.TransactionException.Format(lang, ex.Message)); } } } }
/// <summary> /// DisableUsers /// </summary> /// <param name="context">SessionContext is persist</param> /// <param name="funtionId">function BankAdminFunctionID</param> /// <param name="listId">users target</param> /// <param name="message">string ref : message</param> /// <param name="warningCount">int ref : count of warning</param> /// <param name="errorCount">int ref : count of error</param> public static void DisableUsersNonApproval(BizPortalSessionContext context, int funtionId, List <int> listId, ref string message, ref int warningCount, ref int errorCount) { MemberUser userTarget = null; string lang = context.CurrentLanguage.Code; string functionName = ""; BizPortalFunction function = null; DateTime now = DateTime.Now; foreach (int ID in listId) // 1 2 3 n select { using (ITransaction tx = context.PersistenceSession.BeginTransaction()) { try { MemberUser mem = context.PersistenceSession.Get <MemberUser>(ID); userTarget = mem; functionName = Messages.MemberUser.DisableUser.Format(lang, userTarget.LoginName); MaintenanceWorkflow workflow = GetFunctionWorkflowFormFunctionID(funtionId, context.User); function = workflow.MemberFunction.Function; if (userTarget.IsNotFinalized && ((SelfAuthenticatedUser)userTarget).IsReinstated) // if user reinstate but logon admin disable user this { userTarget.IsNotFinalized = false; ((SelfAuthenticatedUser)userTarget).IsReinstated = false; userTarget.LastLoginTimestamp = now; userTarget.Persist(context); } DisableUserTransaction disableUserTransaction = new DisableUserTransaction(context, workflow, now, context.Member, userTarget); disableUserTransaction.Transit(context, workflow, functionName, TransitionEventCode.SubmitEvent); disableUserTransaction.Persist(context); tx.Commit(); message += String.Format("- {0} {1} <br/>", functionName, Messages.Genaral.Success.Format(lang)); context.Log(funtionId, 0, 0, Messages.MemberUser.DisableUser.Format(lang, ""), functionName); } catch (Exception ex) { tx.Rollback(); errorCount++; message += Messages.Genaral.TransactionException.Format(lang, ex.Message) + "<br/>"; context.Log((int)funtionId, 0, 0, Messages.MemberUser.DisableUser.Format(lang, ""), functionName + Messages.Genaral.TransactionException.Format(lang, ex.Message)); } } } }
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 } } } }