/// <summary>
        /// Login 
        /// </summary>
        /// <param name="user"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public async Task<User> Login(User user, TransactionInformation transaction)
        {
            try
            {
                _accountDataService.CreateSession();
                user = _accountDataService.Login(user.UserName, user.Password);

                if (user != null)
                {
                    _accountDataService.BeginTransaction();
                    _accountDataService.UpdateLastLogin(user);
                    await _accountDataService.CommitTransaction(true);
                    transaction.ReturnStatus = true;
                }
                else
                {
                    transaction.ReturnStatus = false;
                    transaction.ReturnMessage.Add("Invalid login or password.");
                }
            }
            catch (Exception ex)
            {
                transaction.AddExceptionMessage(ex);
            }
            finally
            {
                _accountDataService.CloseSession();
            }

            return user;
        }
        public void ValidateExistingUser(User user)
        {
            InitializeValidationRules(user);

            //require is being validate on ValidateModelState
            //ValidateRequired("FirstName", "First Name");

            ValidateUniqueUserNameForExistingUser(user.UserId, user.UserName);
        }
Пример #3
0
        /// <summary>
        /// Register User
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="userName"></param>
        /// <param name="emailAddress"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public void RegisterUser(User user)
        {
            DateTime now = DateTime.Now;

            user.UserId = Guid.NewGuid();
            user.DateCreated = now;
            user.DateLastLogin = now;
            user.DateUpdated = now;

            dbConnection.Users.Add(user);
        }
        /// <summary>
        /// Register User
        /// </summary>
        /// <param name="user"></param>
        /// <param name="confirmationPassword"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public async Task<User> RegisterUser(User user, string confirmationPassword, TransactionInformation transaction)
        {
            try
            {
                user.FirstName = Utilities.UppercaseFirstLetter(user.FirstName.Trim());
                user.LastName = Utilities.UppercaseFirstLetter(user.LastName.Trim());

                _accountDataService.CreateSession();

                _businessRules.ValidateUser(user);
                _businessRules.ValidatePassword(user.Password, confirmationPassword);

                if (_businessRules.ValidationStatus == true)
                {
                    _accountDataService.BeginTransaction();
                    _accountDataService.RegisterUser(user);
                    await _accountDataService.CommitTransaction(true);
                    transaction.ReturnStatus = true;
                    transaction.ReturnMessage.Add("User registered successfully.");
                }
                else
                {
                    transaction.ReturnStatus = _businessRules.ValidationStatus;
                    transaction.ReturnMessage = _businessRules.ValidationMessage;
                    transaction.ValidationErrors = _businessRules.ValidationErrors;
                }
            }
            catch (Exception ex)
            {
                transaction.AddExceptionMessage(ex);
            }
            finally
            {
                _accountDataService.CloseSession();
            }

            return user;
        }
 /// <summary>
 /// Initialize user Business Rules
 /// </summary>
 /// <param name="user"></param>
 /// <param name="dataService"></param>
 public void InitializeAccountsBusinessRules(User user)
 {
     InitializeValidationRules(user);
 }
        /// <summary>
        /// Validate User
        /// </summary>
        /// <param name="user"></param>
        /// <param name="dataService"></param>
        public void ValidateUser(User user)
        {
            InitializeValidationRules(user);

            ValidateUniqueUserName(user.UserName);
        }
Пример #7
0
 /// <summary>
 /// Update User
 /// </summary>
 /// <param name="user"></param>
 public void UpdateUser(User user)
 {
     DateTime now = DateTime.Now;
     user.DateUpdated = now;
 }
Пример #8
0
 public void UpdateLastLogin(User user)
 {
     user.DateLastLogin = DateTime.Now;
 }