Exemplo n.º 1
0
        //Non Approval

        /// <summary>
        /// EnableUsers non approval
        /// </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 EnableUsersNonApproval(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 userId in listId) // 1 2 3 n select
            {
                using (ITransaction tx = context.PersistenceSession.BeginTransaction())
                {
                    try
                    {
                        MemberUser mem = context.PersistenceSession.Get <MemberUser>(userId);
                        userTarget   = mem;
                        functionName = Messages.MemberUser.EnableUser.Format(lang, userTarget.LoginName);
                        MaintenanceWorkflow workflow = GetFunctionWorkflowFormFunctionID(funtionId, context.User);
                        function = workflow.MemberFunction.Function;
                        EnableUserTransaction enableUserTransaction = new EnableUserTransaction(
                            context,
                            workflow,
                            now,
                            context.Member,
                            userTarget
                            );

                        enableUserTransaction.Transit(context, workflow, functionName, TransitionEventCode.SubmitEvent);
                        enableUserTransaction.Persist(context);

                        userTarget.LastLoginTimestamp = now;
                        userTarget.Persist(context);

                        tx.Commit();
                        message += String.Format("- {0} {1} <br/>", functionName, Messages.Genaral.Success.Format(lang));
                        context.Log(funtionId, 0, 0, Messages.MemberUser.EnableUser.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.EnableUser.Format(lang, ""),
                                    functionName + Messages.Genaral.TransactionException.Format(lang, ex.Message));
                    }
                }
            }
        }
Exemplo n.º 2
0
        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
                    }
                }
            }
        }