Example #1
0
        /// <summary>
        /// Creates a restaurant user as part of first time registration
        /// </summary>
        /// <para>
        /// @author: Brian Fann
        /// @updated: 04/25/2018
        /// </para>
        /// <param name="registerRestaurantDto">Incoming Dto</param>
        /// <returns></returns>
        public ResponseDto <RegisterRestaurantDto> CreateFirstTimeRestaurantUser(RegisterRestaurantDto registerRestaurantDto)
        {
            // Validate incoming user account in the dto
            var userPreLogicValidationStrategy = new CreateFirstTimeIndividualPreLogicValidationStrategy(registerRestaurantDto);
            var userResult = userPreLogicValidationStrategy.ExecuteStrategy();

            if (userResult.Error != null)
            {
                return(new ResponseDto <RegisterRestaurantDto>
                {
                    Data = registerRestaurantDto,
                    Error = userResult.Error
                });
            }

            // Validate incoming restaurant details in the dto
            var restaurantPreLogicValidationStrategy = new CreateRestaurantPreLogicValidationStrategy(registerRestaurantDto);
            var restaurantResult = restaurantPreLogicValidationStrategy.ExecuteStrategy();

            if (restaurantResult.Error != null)
            {
                return(new ResponseDto <RegisterRestaurantDto>
                {
                    Data = registerRestaurantDto,
                    Error = restaurantResult.Error
                });
            }

            // Authenticate user credentials against the database
            var credentialsValidator = new CredentialsValidator();
            var credentialsResult    = credentialsValidator.IsCredentialsValid(registerRestaurantDto.UserAccountDto.Username, registerRestaurantDto.UserAccountDto.Password);

            if (!credentialsResult.Data)
            {
                return(new ResponseDto <RegisterRestaurantDto>()
                {
                    Data = registerRestaurantDto,
                    Error = credentialsResult.Error
                });
            }

            // Create a domain model based on the dto.
            var mappingResult = MapRestaurantDtoToModels(registerRestaurantDto, out var userAccount, out var passwordSalt, out var userClaims, out var userProfile, out var securityQuestions, out var securityAnswerSalts, out var restaurantProfile, out var businessHours, out var foodPreferences);

            if (!mappingResult.Data)
            {
                return(new ResponseDto <RegisterRestaurantDto>()
                {
                    Data = registerRestaurantDto,
                    Error = mappingResult.Error
                });
            }

            // Validate domain models created from dto
            var userPostLogicValidationStrategy = new CreateFirstTimeIndividualPostLogicValidationStrategy(userAccount, passwordSalt, userClaims, userProfile, securityQuestions, securityAnswerSalts);

            userResult = userPostLogicValidationStrategy.ExecuteStrategy();

            if (userResult.Error != null)
            {
                return(new ResponseDto <RegisterRestaurantDto>
                {
                    Data = registerRestaurantDto,
                    Error = userResult.Error
                });
            }

            // Map the user's id in the database to the generated domain model.
            var userIdResult = GetFirstTimeUserAccountId(userAccount.Username);

            if (userIdResult.Error != null)
            {
                return(new ResponseDto <RegisterRestaurantDto>()
                {
                    Data = registerRestaurantDto,
                    Error = userIdResult.Error
                });
            }

            userAccount.Id = userIdResult.Data;

            // Apply post logic validation to the user account information
            var userPostLogicValdiationStrategy = new CreateIndividualPostLogicValidationStrategy(userAccount, passwordSalt, userClaims, userProfile, securityQuestions, securityAnswerSalts);
            var userPostResult = userPostLogicValdiationStrategy.ExecuteStrategy();

            if (!userPostResult.Data)
            {
                return(new ResponseDto <RegisterRestaurantDto>
                {
                    Data = registerRestaurantDto,
                    Error = GeneralErrorMessages.GENERAL_ERROR
                });
            }

            // Apply post logic validation to the restaurant information
            var restaurantPostLogicValdiationStrategy = new CreateRestaurantPostLogicValidationStrategy(restaurantProfile, businessHours);
            var restaurantPostResult = restaurantPostLogicValdiationStrategy.ExecuteStrategy();

            if (!restaurantPostResult.Data)
            {
                return(new ResponseDto <RegisterRestaurantDto>
                {
                    Data = registerRestaurantDto,
                    Error = GeneralErrorMessages.GENERAL_ERROR
                });
            }

            // Store user in database
            using (var userGateway = new UserGateway())
            {
                var createResult = userGateway.StoreRestaurantUser(userAccount, passwordSalt, userClaims, userProfile, restaurantProfile, securityQuestions, securityAnswerSalts, foodPreferences, businessHours);

                if (!createResult.Data)
                {
                    return(new ResponseDto <RegisterRestaurantDto>()
                    {
                        Data = registerRestaurantDto,
                        Error = createResult.Error
                    });
                }
            }

            return(new ResponseDto <RegisterRestaurantDto>
            {
                Data = registerRestaurantDto
            });
        }
Example #2
0
        /// <summary>
        /// The CreateRestaurantUser method.
        /// Contains business logic for creating a restaurant user.
        /// <para>
        /// @author: Jennifer Nguyen, Brian Fann
        /// @updated: 04/25/2018
        /// </para>
        /// </summary>
        /// <param name="registerRestaurantDto"></param>
        /// <returns>ResponseDto</returns>
        public ResponseDto <RegisterRestaurantDto> CreateRestaurantUser(RegisterRestaurantDto registerRestaurantDto)
        {
            var userPreLogicValidationStrategy = new CreateIndividualPreLogicValidationStrategy(registerRestaurantDto);

            var userResult = userPreLogicValidationStrategy.ExecuteStrategy();

            if (userResult.Error != null)
            {
                return(new ResponseDto <RegisterRestaurantDto>
                {
                    Data = registerRestaurantDto,
                    Error = userResult.Error
                });
            }

            var restaurantPreLogicValidationStrategy = new CreateRestaurantPreLogicValidationStrategy(registerRestaurantDto);

            // Validate data transfer object
            var restaurantResult = restaurantPreLogicValidationStrategy.ExecuteStrategy();

            if (restaurantResult.Error != null)
            {
                return(new ResponseDto <RegisterRestaurantDto>
                {
                    Data = registerRestaurantDto,
                    Error = restaurantResult.Error
                });
            }

            // Create a domain model based on the dto.
            var mappingResult = MapRestaurantDtoToModels(registerRestaurantDto, out var userAccount, out var passwordSalt, out var userClaims, out var userProfile, out var securityQuestions, out var securityAnswerSalts, out var restaurantProfile, out var businessHours, out var foodPreferences);

            if (!mappingResult.Data)
            {
                return(new ResponseDto <RegisterRestaurantDto>()
                {
                    Data = registerRestaurantDto,
                    Error = mappingResult.Error
                });
            }

            // Validate domain models
            var userPostLogicValidationStrategy = new CreateIndividualPostLogicValidationStrategy(userAccount, passwordSalt, userClaims, userProfile, securityQuestions, securityAnswerSalts);

            userResult = userPostLogicValidationStrategy.ExecuteStrategy();

            if (userResult.Error != null)
            {
                return(new ResponseDto <RegisterRestaurantDto>
                {
                    Data = registerRestaurantDto,
                    Error = userResult.Error
                });
            }

            var createRestaurantPostLogicValdiationStrategy = new CreateRestaurantPostLogicValidationStrategy(restaurantProfile, businessHours);
            var validateResult = createRestaurantPostLogicValdiationStrategy.ExecuteStrategy();

            if (!validateResult.Data)
            {
                return(new ResponseDto <RegisterRestaurantDto>
                {
                    Data = registerRestaurantDto,
                    Error = GeneralErrorMessages.GENERAL_ERROR
                });
            }

            // Store user in database
            using (var userGateway = new UserGateway())
            {
                var createResult = userGateway.StoreRestaurantUser(userAccount, passwordSalt, userClaims, userProfile, restaurantProfile, securityQuestions, securityAnswerSalts, foodPreferences, businessHours);

                if (!createResult.Data)
                {
                    return(new ResponseDto <RegisterRestaurantDto>()
                    {
                        Data = registerRestaurantDto,
                        Error = createResult.Error
                    });
                }
            }

            return(new ResponseDto <RegisterRestaurantDto>
            {
                Data = registerRestaurantDto
            });
        }