示例#1
0
 protected RestaurantSelectionManager(RestaurantSelectionDto restaurantSelectionDto)
 {
     RestaurantSelectionDto = restaurantSelectionDto;
     SelectedRestaurantDto  = new SelectedRestaurantDto();
     _restaurantSelectionPreLogicValidationStrategy = new RestaurantSelectionPreLogicValidationStrategy(restaurantSelectionDto);
     _geocodeService  = new GoogleGeocodeService();
     _timeZoneService = new GoogleTimeZoneService();
     _dateTimeService = new DateTimeService();
 }
示例#2
0
        /// <summary>
        /// Instantiate domain model equivalent of Dto's
        /// <para>
        /// @author: Brian Fann
        /// @updated: 4/25/18
        /// </para>
        /// </summary>
        /// <param name="dto">Dto to map</param>
        /// <param name="param">Parameter Object to map to</param>
        /// <returns></returns>
        private ResponseDto <bool> MapRestaurantDtoToModels(RegisterRestaurantDto dto, out UserAccount userAccount, out PasswordSalt passwordSalt, out UserClaims userClaims, out UserProfile userProfile, out IList <SecurityQuestion> securityQuestions, out IList <SecurityAnswerSalt> securityAnswerSalts, out RestaurantProfile restaurantProfile, out IList <BusinessHour> businessHours, out IList <FoodPreference> foodPreferences)
        {
            // Try to map user dto
            var mappingResult = MapUserDtoToModel(dto, out userAccount, out passwordSalt, out userProfile, out securityQuestions, out securityAnswerSalts);

            if (!mappingResult.Data)
            {
                restaurantProfile = null;
                foodPreferences   = null;
                businessHours     = null;
                userClaims        = null;

                return(mappingResult);
            }

            restaurantProfile = new RestaurantProfile(
                phoneNumber: dto.RestaurantProfileDto.PhoneNumber,
                address: dto.RestaurantProfileDto.Address,
                details: dto.RestaurantProfileDto.Details);

            // Call GeocodeService to get geocoordinates of the restaurant
            var geocodeService  = new GoogleGeocodeService();
            var geocodeResponse = geocodeService.Geocode(restaurantProfile.Address);

            var dateTimeService = new DateTimeService();

            businessHours = dto.BusinessHourDtos
                            .Select(businessHourDto => new BusinessHour(
                                        timeZone: dto.TimeZone,
                                        day: businessHourDto.Day,
                                        openTime: dateTimeService.ConvertLocalMeanTimeToUtc(dateTimeService.ConvertTimeToDateTimeUnspecifiedKind(businessHourDto.OpenTime), dto.TimeZone),
                                        closeTime: dateTimeService.ConvertLocalMeanTimeToUtc(dateTimeService.ConvertTimeToDateTimeUnspecifiedKind(businessHourDto.CloseTime), dto.TimeZone)))
                            .ToList();

            foodPreferences = new List <FoodPreference>();

            if (dto.FoodPreferences != null)
            {
                foodPreferences = dto.FoodPreferences.Select(foodPreference => new FoodPreference(foodPreference)).ToList();
            }

            // Set user claims to be stored in UserClaims table
            var claimsFactory = new ClaimsFactory();

            userClaims = new UserClaims(claimsFactory.Create(AccountTypes.Restaurant));

            if (geocodeResponse.Error != null)
            {
                return(new ResponseDto <bool>
                {
                    Data = false,
                    Error = geocodeResponse.Error
                });
            }

            restaurantProfile.GeoCoordinates = new GeoCoordinates(latitude: geocodeResponse.Data.Latitude, longitude: geocodeResponse.Data.Longitude);

            // Successful response
            return(new ResponseDto <bool>()
            {
                Data = true
            });
        }
示例#3
0
        public ResponseDto <bool> EditProfile(RestaurantProfileDto restaurantProfileDto, string token)
        {
            var geocodeService = new GoogleGeocodeService();
            var restaurantBusinessHourDtoService = new RestaurantBusinessHourDtoService();
            var tokenService = new TokenService();

            var editRestaurantProfilePreLogicValidationStrategy = new EditRestaurantUserProfilePreLogicValidationStrategy(restaurantProfileDto);

            var result = editRestaurantProfilePreLogicValidationStrategy.ExecuteStrategy();

            if (result.Error != null)
            {
                return(new ResponseDto <bool>
                {
                    Data = false,
                    Error = GeneralErrorMessages.GENERAL_ERROR
                });
            }

            // Retrieve account by username
            var userGateway = new UserGateway();

            var userAccountResponseDto = userGateway.GetUserByUsername(tokenService.GetTokenUsername(token));

            // Extrant user profile domain
            var userProfileDomain = new UserProfile
            {
                DisplayName = restaurantProfileDto.DisplayName
            };

            var geocodeResponse = geocodeService.Geocode(restaurantProfileDto.Address);

            if (geocodeResponse.Error != null)
            {
                return(new ResponseDto <bool>
                {
                    Data = false,
                    Error = GeneralErrorMessages.GENERAL_ERROR
                });
            }


            // Extract restaurant profile domain
            var restaurantProfileDomain = new RestaurantProfile(
                restaurantProfileDto.PhoneNumber,
                restaurantProfileDto.Address,
                restaurantProfileDto.Details)
            {
                GeoCoordinates = new GeoCoordinates(geocodeResponse.Data.Latitude, geocodeResponse.Data.Longitude)
            };

            // Extract business hours domains
            var restaurantBusinessHourDtos = restaurantProfileDto.BusinessHours;

            // Call the RestaurantBusinessHourDtoService
            var convertedRestaurantBusinessHourDtos = restaurantBusinessHourDtoService.SetDateTimesFromStringTimes(restaurantBusinessHourDtos);

            // Extract restaurant menus
            if (restaurantProfileDto.RestaurantMenusList.Count == 0)
            {
            }
            var restaurantMenuDomains = restaurantProfileDto.RestaurantMenusList;

            // Execute update of database
            var profileGateway = new RestaurantProfileGateway();

            var responseDtoFromGateway = profileGateway.EditRestaurantProfileById(userAccountResponseDto.Data.Id, userProfileDomain, restaurantProfileDomain, convertedRestaurantBusinessHourDtos, restaurantMenuDomains);

            return(responseDtoFromGateway);
        }