示例#1
0
        /// <summary>
        /// Gets all the Users.
        /// </summary>
        /// <param name="request">Request object.</param>
        /// <param name="response">Response object.</param>
        /// <returns>Populated response object.</returns>
        public UserManagementResponse getUsers(
            UserManagementRequest request,
            UserManagementResponse response)
        {
            IUserManagementDataServices userManagementDataServices = getUserManagementDataServices();

            List <DDO.UserAccount> dataUserAccounts = userManagementDataServices.GetUsers();

            List <DCO.UserAccount> coreUserAccounts = new List <UserAccount>();

            foreach (DDO.UserAccount dataUserAccount in dataUserAccounts)
            {
                coreUserAccounts.Add(UserAccountConverter.ConvertToCoreUserAccount(dataUserAccount));
            }

            response.UserAccountsRetrieved = coreUserAccounts;

            Logger.Log("[Get Users Success] Total User Accounts Retrieved: " + coreUserAccounts.Count,
                       LogType.Informational);

            return(response);
        }
示例#2
0
        /// <summary>
        /// Verifies and update UserAccounts retrieved from Data Provider.
        /// </summary>
        private void verifyAndUpdateUserAccounts()
        {
            // 1.) Get Services
            IUserManagementDataServices userManagementDataServices = getUserManagementDataServices();

            // 2.) Get Users
            List <DDO.UserAccount> dataUserAccounts = userManagementDataServices.GetUsers();

            // 3.) Validate and Verify Data
            List <DCO.UserAccount> coreUserAccounts = new List <UserAccount>();

            foreach (DDO.UserAccount dataUserAccount in dataUserAccounts)
            {
                coreUserAccounts.Add(UserAccountConverter.ConvertToCoreUserAccount(dataUserAccount));
            }

            foreach (DCO.UserAccount coreUserAccount in coreUserAccounts)
            {
                if (coreUserAccount.UserID == null)
                {
                    Logger.Log("[Data Error] A UserID is invalid. Terminating Applciation.",
                               LogType.Error);

                    Environment.Exit(1);
                }

                if (string.IsNullOrEmpty(coreUserAccount.Username))
                {
                    Logger.Log("[Data Error] A Username is invalid. Terminating Applciation.",
                               LogType.Error);

                    Environment.Exit(1);
                }
                else
                {
                    if (coreUserAccounts.FindAll(u => u.Username == coreUserAccount.Username).Count > 1)
                    {
                        Logger.Log("[Data Error] A duplicate UserID is found. Terminating Applciation.",
                                   LogType.Error);

                        Environment.Exit(1);
                    }
                }

                if (string.IsNullOrEmpty(coreUserAccount.Password))
                {
                    Logger.Log("[Data Error] A Password is invalid. Terminating Applciation.",
                               LogType.Error);

                    Environment.Exit(1);
                }

                if (coreUserAccount.UserInfo == null)
                {
                    Logger.Log("[Data Error] A UserInfo is invalid. Terminating Applciation.",
                               LogType.Error);

                    Environment.Exit(1);
                }

                if (!ValidationHelper.CheckIfNameIsValid(coreUserAccount.UserInfo.FirstName))
                {
                    Logger.Log("[Data Error] A First Name is invalid. Terminating Applciation.",
                               LogType.Error);

                    Environment.Exit(1);
                }

                if (!ValidationHelper.CheckIfNameIsValid(coreUserAccount.UserInfo.LastName))
                {
                    Logger.Log("[Data Error] A Last Name is invalid. Terminating Applciation.",
                               LogType.Error);

                    Environment.Exit(1);
                }

                if (coreUserAccount.UserInfo.BirthDate > DateTime.Now)
                {
                    Logger.Log("[Data Error] A BirthDate is invalid. Terminating Applciation.",
                               LogType.Error);

                    Environment.Exit(1);
                }

                coreUserAccount.UserInfo.Age =
                    UserManagementHelper.CalculateAge(coreUserAccount.UserInfo.BirthDate);
            }

            // 4.) Update Data
            dataUserAccounts = new List <DDO.UserAccount>();

            foreach (DCO.UserAccount coreUserAccount in coreUserAccounts)
            {
                userManagementDataServices.EditUser(UserAccountConverter.ConvertToDataUserAccount(coreUserAccount));
            }
        }