Beispiel #1
0
        /// <summary>
        /// Update Profile
        /// </summary>
        /// <param name="userInformation"></param>
        /// <param name="transaction"></param>
        public void UpdateProfile(UserInformation userInformation, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();

            User user = new User();

            try
            {
                user.FirstName = userInformation.FirstName;
                user.LastName  = userInformation.LastName;

                UserBusinessRules userBusinessRules = new UserBusinessRules();
                ValidationResult  results           = userBusinessRules.Validate(user);

                bool validationSucceeded           = results.IsValid;
                IList <ValidationFailure> failures = results.Errors;

                if (validationSucceeded == false)
                {
                    transaction = ValidationErrors.PopulateValidationErrors(failures);
                    return;
                }

                _userDataService.CreateSession();
                _userDataService.BeginTransaction();

                User existingUser = _userDataService.GetUser(userInformation.UserID);
                existingUser.AddressLine1 = userInformation.AddressLine1;
                existingUser.AddressLine2 = userInformation.AddressLine2;
                existingUser.City         = userInformation.City;
                existingUser.State        = userInformation.State;
                existingUser.ZipCode      = userInformation.ZipCode;

                _userDataService.UpdateUser(user);
                _userDataService.CommitTransaction(true);

                transaction.ReturnStatus = true;
                transaction.ReturnMessage.Add("Your profile was successfully updated.");
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.ReturnStatus = false;
            }
            finally
            {
                _userDataService.CloseSession();
            }

            return;
        }
Beispiel #2
0
        /// <summary>
        /// Register User
        /// </summary>
        /// <param name="userInformation"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public User RegisterUser(UserInformation userInformation, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();

            User user = new User();

            try
            {
                user.EmailAddress = userInformation.EmailAddress;
                user.FirstName    = userInformation.FirstName;
                user.LastName     = userInformation.LastName;
                user.Password     = userInformation.Password;
                user.AddressLine1 = string.Empty;
                user.AddressLine2 = string.Empty;
                user.City         = string.Empty;
                user.State        = string.Empty;
                user.ZipCode      = string.Empty;

                UserBusinessRules userBusinessRules = new UserBusinessRules(_userDataService, user, userInformation.PasswordConfirmation);
                ValidationResult  results           = userBusinessRules.Validate(user);

                bool validationSucceeded           = results.IsValid;
                IList <ValidationFailure> failures = results.Errors;

                if (validationSucceeded == false)
                {
                    transaction = ValidationErrors.PopulateValidationErrors(failures);
                    return(user);
                }

                _userDataService.CreateSession();
                _userDataService.BeginTransaction();
                _userDataService.CreateUser(user);
                _userDataService.CommitTransaction(true);

                transaction.ReturnStatus = true;
                transaction.ReturnMessage.Add("user successfully created.");
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.ReturnStatus = false;
            }
            finally
            {
                _userDataService.CloseSession();
            }

            return(user);
        }