Exemple #1
0
        /// <summary>
        /// Install the plugin
        /// </summary>
        /// <returns>A task that represents the asynchronous operation</returns>
        public override async Task InstallAsync()
        {
            //sample pickup point
            var country = await _countryService.GetCountryByThreeLetterIsoCodeAsync("USA");

            var state = await _stateProvinceService.GetStateProvinceByAbbreviationAsync("NY", country?.Id);

            var address = new Address
            {
                Address1        = "21 West 52nd Street",
                City            = "New York",
                CountryId       = country?.Id,
                StateProvinceId = state?.Id,
                ZipPostalCode   = "10021",
                CreatedOnUtc    = DateTime.UtcNow
            };
            await _addressService.InsertAddressAsync(address);

            var pickupPoint = new StorePickupPoint
            {
                Name         = "New York store",
                AddressId    = address.Id,
                OpeningHours = "10.00 - 19.00",
                PickupFee    = 1.99m
            };
            await _storePickupPointService.InsertStorePickupPointAsync(pickupPoint);

            //locales
            await _localizationService.AddOrUpdateLocaleResourceAsync(new Dictionary <string, string>
            {
                ["Plugins.Pickup.PickupInStore.AddNew"]                                      = "Add a new pickup point",
                ["Plugins.Pickup.PickupInStore.Fields.Description"]                          = "Description",
                ["Plugins.Pickup.PickupInStore.Fields.Description.Hint"]                     = "Specify a description of the pickup point.",
                ["Plugins.Pickup.PickupInStore.Fields.DisplayOrder"]                         = "Display order",
                ["Plugins.Pickup.PickupInStore.Fields.DisplayOrder.Hint"]                    = "Specify the pickup point display order.",
                ["Plugins.Pickup.PickupInStore.Fields.Latitude"]                             = "Latitude",
                ["Plugins.Pickup.PickupInStore.Fields.Latitude.Hint"]                        = "Specify a latitude (DD.dddddddd°).",
                ["Plugins.Pickup.PickupInStore.Fields.Latitude.InvalidPrecision"]            = "Precision should be less then 8",
                ["Plugins.Pickup.PickupInStore.Fields.Latitude.InvalidRange"]                = "Latitude should be in range -90 to 90",
                ["Plugins.Pickup.PickupInStore.Fields.Latitude.IsNullWhenLongitudeHasValue"] = "Latitude and Longitude should be specify together",
                ["Plugins.Pickup.PickupInStore.Fields.Longitude"]                            = "Longitude",
                ["Plugins.Pickup.PickupInStore.Fields.Longitude.Hint"]                       = "Specify a longitude (DD.dddddddd°).",
                ["Plugins.Pickup.PickupInStore.Fields.Longitude.InvalidPrecision"]           = "Precision should be less then 8",
                ["Plugins.Pickup.PickupInStore.Fields.Longitude.InvalidRange"]               = "Longitude should be in range -180 to 180",
                ["Plugins.Pickup.PickupInStore.Fields.Longitude.IsNullWhenLatitudeHasValue"] = "Latitude and Longitude should be specify together",
                ["Plugins.Pickup.PickupInStore.Fields.Name"]                                 = "Name",
                ["Plugins.Pickup.PickupInStore.Fields.Name.Hint"]                            = "Specify a name of the pickup point.",
                ["Plugins.Pickup.PickupInStore.Fields.OpeningHours"]                         = "Opening hours",
                ["Plugins.Pickup.PickupInStore.Fields.OpeningHours.Hint"]                    = "Specify opening hours of the pickup point (Monday - Friday: 09:00 - 19:00 for example).",
                ["Plugins.Pickup.PickupInStore.Fields.PickupFee"]                            = "Pickup fee",
                ["Plugins.Pickup.PickupInStore.Fields.PickupFee.Hint"]                       = "Specify a fee for the shipping to the pickup point.",
                ["Plugins.Pickup.PickupInStore.Fields.Store"]                                = "Store",
                ["Plugins.Pickup.PickupInStore.Fields.Store.Hint"]                           = "A store name for which this pickup point will be available.",
                ["Plugins.Pickup.PickupInStore.Fields.TransitDays"]                          = "Transit days",
                ["Plugins.Pickup.PickupInStore.Fields.TransitDays.Hint"]                     = "The number of days of delivery of the goods to pickup point.",
                ["Plugins.Pickup.PickupInStore.NoPickupPoints"]                              = "No pickup points are available"
            });

            await base.InstallAsync();
        }
        /// <returns>A task that represents the asynchronous operation</returns>
        public async Task <IActionResult> Create(StorePickupPointModel model)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageShippingSettings))
            {
                return(AccessDeniedView());
            }

            var address = new Address
            {
                Address1        = model.Address.Address1,
                City            = model.Address.City,
                County          = model.Address.County,
                CountryId       = model.Address.CountryId,
                StateProvinceId = model.Address.StateProvinceId,
                ZipPostalCode   = model.Address.ZipPostalCode,
                CreatedOnUtc    = DateTime.UtcNow
            };
            await _addressService.InsertAddressAsync(address);

            var pickupPoint = new StorePickupPoint
            {
                Name         = model.Name,
                Description  = model.Description,
                AddressId    = address.Id,
                OpeningHours = model.OpeningHours,
                PickupFee    = model.PickupFee,
                DisplayOrder = model.DisplayOrder,
                StoreId      = model.StoreId,
                Latitude     = model.Latitude,
                Longitude    = model.Longitude,
                TransitDays  = model.TransitDays
            };
            await _storePickupPointService.InsertStorePickupPointAsync(pickupPoint);

            ViewBag.RefreshPage = true;

            return(View("~/Plugins/Pickup.PickupInStore/Views/Create.cshtml", model));
        }