Exemplo n.º 1
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);
        }
        /// <summary>
        /// Account Business Rules
        /// </summary>
        public UserBusinessRules(IUserDataService userDataService, User user, string passwordConfirmation)
        {
            userDataService.CreateSession();

            if (user.EmailAddress.Length > 0)
            {
                _user = userDataService.GetUser(user.EmailAddress);
                if (_user != null)
                {
                    _emailAddressIsValid = false;
                }
            }

            userDataService.CloseSession();

            passwordConfirmation = passwordConfirmation.Trim();
            if (passwordConfirmation == null || passwordConfirmation == string.Empty || passwordConfirmation.Length == 0)
            {
                _passwordConfirmationEntered = false;
            }

            RuleFor(a => a.FirstName).NotEmpty().WithMessage("First Name is required.");
            RuleFor(a => a.LastName).NotEmpty().WithMessage("Last Name is required.");
            RuleFor(a => a.Password).NotEmpty().WithMessage("Password is required.");
            RuleFor(a => a.Password).Must(PasswordConfirmationRequired).WithMessage("Password Confirmation is required.");
            RuleFor(a => a.Password).Matches(passwordConfirmation).WithMessage("Passwords do not match");
            RuleFor(a => a.EmailAddress).NotEmpty().WithMessage("Email Address is required.");
            RuleFor(a => a.EmailAddress).EmailAddress().WithMessage("Invalid Email Address.");
            RuleFor(a => a.EmailAddress).Must(ValidateDuplicateEmailAddress).WithMessage("Email Address already exists.");
        }
Exemplo n.º 3
0
        public IEnumerable <sp_UserMngmt_TissueBank_GetByTissueBankId_Result> GetUser(int TissueBankId, string SearchBy, int CurrentPage, int PageSize, string SortDirection, string SortExpression, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();
            UserBusinessRule userBusinessRule = new UserBusinessRule(userDataService);

            IEnumerable <sp_UserMngmt_TissueBank_GetByTissueBankId_Result> lstUser = null;

            try
            {
                userDataService.CreateSession();

                userBusinessRule.ValidateUserRequest(TissueBankId, SearchBy, CurrentPage, PageSize, SortDirection, SortExpression);

                if (userBusinessRule.ValidationStatus == true)
                {
                    lstUser = userDataService.GetUser(TissueBankId, SearchBy, CurrentPage, PageSize, SortDirection, SortExpression, out transaction);
                }
                else
                {
                    transaction.ReturnStatus     = userBusinessRule.ValidationStatus;
                    transaction.ReturnMessage    = userBusinessRule.ValidationMessage;
                    transaction.ValidationErrors = userBusinessRule.ValidationErrors;
                }
            }
            catch (Exception ex)
            {
                transaction.ReturnMessage = new List <string>();
                string errorMessage = ex.Message;
                transaction.ReturnStatus = false;
                transaction.ReturnMessage.Add(errorMessage);
            }
            finally
            {
                userDataService.CloseSession();
            }

            return(lstUser);
        }