Esempio n. 1
0
        /// <summary>
        /// Prepare store pickup point list model
        /// </summary>
        /// <param name="searchModel">Store pickup point search model</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the store pickup point list model
        /// </returns>
        public async Task <StorePickupPointListModel> PrepareStorePickupPointListModelAsync(StorePickupPointSearchModel searchModel)
        {
            var pickupPoints = await _storePickupPointService.GetAllStorePickupPointsAsync(pageIndex : searchModel.Page - 1,
                                                                                           pageSize : searchModel.PageSize);

            var model = await new StorePickupPointListModel().PrepareToGridAsync(searchModel, pickupPoints, () =>
            {
                return(pickupPoints.SelectAwait(async point =>
                {
                    var store = await _storeService.GetStoreByIdAsync(point.StoreId);

                    return new StorePickupPointModel
                    {
                        Id = point.Id,
                        Name = point.Name,
                        OpeningHours = point.OpeningHours,
                        PickupFee = point.PickupFee,
                        DisplayOrder = point.DisplayOrder,

                        StoreName = store?.Name
                                    ?? (point.StoreId == 0 ? (await _localizationService.GetResourceAsync("Admin.Configuration.Settings.StoreScope.AllStores")) : string.Empty)
                    };
                }));
            });

            return(model);
        }
        /// <summary>
        /// Get pickup points for the address
        /// </summary>
        /// <param name="address">Address</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the represents a response of getting pickup points
        /// </returns>
        public async Task <GetPickupPointsResponse> GetPickupPointsAsync(Address address)
        {
            var result = new GetPickupPointsResponse();
            var store  = await _storeContext.GetCurrentStoreAsync();

            foreach (var point in await _storePickupPointService.GetAllStorePickupPointsAsync(store.Id))
            {
                var pointAddress = await _addressService.GetAddressByIdAsync(point.AddressId);

                if (pointAddress == null)
                {
                    continue;
                }

                result.PickupPoints.Add(new PickupPoint
                {
                    Id                 = point.Id.ToString(),
                    Name               = point.Name,
                    Description        = point.Description,
                    Address            = pointAddress.Address1,
                    City               = pointAddress.City,
                    County             = pointAddress.County,
                    StateAbbreviation  = (await _stateProvinceService.GetStateProvinceByAddressAsync(pointAddress))?.Abbreviation ?? string.Empty,
                    CountryCode        = (await _countryService.GetCountryByAddressAsync(pointAddress))?.TwoLetterIsoCode ?? string.Empty,
                    ZipPostalCode      = pointAddress.ZipPostalCode,
                    OpeningHours       = point.OpeningHours,
                    PickupFee          = point.PickupFee,
                    DisplayOrder       = point.DisplayOrder,
                    ProviderSystemName = PluginDescriptor.SystemName,
                    Latitude           = point.Latitude,
                    Longitude          = point.Longitude,
                    TransitDays        = point.TransitDays
                });
            }

            if (!result.PickupPoints.Any())
            {
                result.AddError(await _localizationService.GetResourceAsync("Plugins.Pickup.PickupInStore.NoPickupPoints"));
            }

            return(result);
        }