Пример #1
0
 protected RestaurantSelectionManager(RestaurantSelectionDto restaurantSelectionDto)
 {
     RestaurantSelectionDto = restaurantSelectionDto;
     SelectedRestaurantDto  = new SelectedRestaurantDto();
     _restaurantSelectionPreLogicValidationStrategy = new RestaurantSelectionPreLogicValidationStrategy(restaurantSelectionDto);
     _geocodeService  = new GoogleGeocodeService();
     _timeZoneService = new GoogleTimeZoneService();
     _dateTimeService = new DateTimeService();
 }
        /// <summary>
        /// Iterates through a list of RetaurantBusinessHourDtos, converts its OpenTime and CloseTime to DateTime type,
        /// and inserts them back into the Dto
        /// </summary>
        /// <param name="restaurantBusinessHourDtos"></param>
        /// <returns>IList<RestaurantBusinessHourDto></returns>
        public IList <RestaurantBusinessHourDto> SetDateTimesFromStringTimes(IList <RestaurantBusinessHourDto> restaurantBusinessHourDtos)
        {
            var dateTimeService = new DateTimeService();

            foreach (var restaurantBusinessHourDto in restaurantBusinessHourDtos)
            {
                restaurantBusinessHourDto.OpenDateTime  = dateTimeService.ConvertLocalMeanTimeToUtc(dateTimeService.ConvertTimeToDateTimeUnspecifiedKind(restaurantBusinessHourDto.OpenTime), restaurantBusinessHourDto.TimeZone);
                restaurantBusinessHourDto.CloseDateTime = dateTimeService.ConvertLocalMeanTimeToUtc(dateTimeService.ConvertTimeToDateTimeUnspecifiedKind(restaurantBusinessHourDto.CloseTime), restaurantBusinessHourDto.TimeZone);
            }
            return(restaurantBusinessHourDtos);
        }
Пример #3
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
            });
        }