Пример #1
0
        /// <summary>
        /// Use Dapper to execute the sproc to create a new user
        /// </summary>
        /// <param name="input"></param>
        /// <returns>Nothing</returns>
        public async Task CreateUserAccount(CreateUserAccountDatabaseInput input)
        {
            var p = new DynamicParameters();

            p.Add("@p_UserGuid", input.UserGuid);
            p.Add("@p_UserName", input.UserName);
            p.Add("@p_UserPassword", input.UserPassword);
            p.Add("@p_UserRole", input.UserRole);
            p.Add("@p_EmployeeGuid", input.EmployeeGuid);
            p.Add("@p_FirstName", input.FirstName);
            p.Add("@p_LastName", input.LastName);

            var pUserNameCheck = new DynamicParameters();

            pUserNameCheck.Add("@p_UserName", input.UserName);

            bool isUserNameAvailable;

            using (IDbConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                isUserNameAvailable = await connection.QueryFirstAsync <bool>("sp_IsUserNameAvailable", pUserNameCheck, commandType : CommandType.StoredProcedure);

                if (!isUserNameAvailable)
                {
                    throw new CreateUserNameException("This user name is already in use. Please, enter a different one.");
                }

                await connection.ExecuteAsync("sp_CreateUserAccount", p, commandType : CommandType.StoredProcedure);
            }
        }
Пример #2
0
        public async Task <IActionResult> CreateUserAccount(CreateUserAccountInput input)
        {
            var resultList = new WorkHourTrackerListResult()
            {
                Errors = new List <string>(), WorkHourTrackList = new List <dynamic>()
            };

            //If the model state is invalid return set the Errors property of WorkHourTrackListResult object
            if (!ModelState.IsValid)
            {
                resultList.Errors = ModelState.Values.SelectMany(p => p.Errors.Select(x => x.ErrorMessage)).ToList();

                TempData.Add("ModelErrors", resultList.Errors);


                return(RedirectTo("Home", "DisplayCreateUserAccountPage"));
            }

            try
            {
                //the request is valid so transform to CreateUserAccountDatabaseInput

                var databaseInput = new CreateUserAccountDatabaseInput(input.UserName, input.UserPassword,
                                                                       input.UserRole, input.FirstName,
                                                                       input.LastName);

                //send the new account request to Domain layer
                await _IUserAccount.CreateUserAccount(databaseInput);
            }
            catch (CreateUserNameException)
            {
                resultList.Errors.Add($"The user name: {input.UserName} is already in use. Please, use a different one.");
                TempData.Add("ModelErrors", resultList.Errors);

                return(RedirectTo("Home", "DisplayCreateUserAccountPage"));
            }
            catch (Exception ex)

            {
                resultList.Errors.Add($"An unexpected error has occured.");
                TempData.Add("ModelErrors", resultList.Errors);

                return(RedirectTo("Home", "DisplayCreateUserAccountPage"));
            }

            TempData.Add("CreateUserAccountSuccess", $"User account for {input.UserName} was successfully created. You may log into the system now.");
            return(RedirectTo("Home", "UserLogin"));
        }
Пример #3
0
 public async Task CreateUserAccount(CreateUserAccountDatabaseInput input)
 {
     await _IUserAccountRepository.CreateUserAccount(input);
 }