public override async Task <List <NearestStoreLocation> > Run(GetNearestStoreDetailsByLocationArgument locationInfo, CommercePipelineExecutionContext context)
        {
            List <InventorySet> inventorySets = new List <InventorySet>();

            GetNearestStoreDetailsByLocationBlock getNearestStoreDetailsByLocationBlock = this;

            FindEntitiesInListArgument entitiesInListArgument = await getNearestStoreDetailsByLocationBlock._findEntitiesInListPipeline.Run(new FindEntitiesInListArgument(typeof(InventorySet), string.Format("{0}", (object)CommerceEntity.ListName <InventorySet>()), 0, int.MaxValue), context);

            if (entitiesInListArgument != null)
            {
                CommerceList <CommerceEntity> list = entitiesInListArgument.List;
                if (list != null)
                {
                    list.Items.ForEach((Action <CommerceEntity>)(item =>
                    {
                        InventorySet inventorySet = (InventorySet)item;


                        inventorySets.Add(inventorySet);
                    }));
                }
            }

            var storeComponents = inventorySets.Select(x => x.GetComponent <StoreDetailsComponent>());

            storeComponents = storeComponents.Where(x => x.Lat != null).ToList();

            List <Locations> locations = new List <Locations>();

            locations.AddRange(storeComponents.Select(x => x != null ? new Locations()
            {
                City = x.City, Latitude = Convert.ToDouble(x.Lat), Longitude = Convert.ToDouble(x.Long)
            } : new Locations()));

            var coord = new GeoCoordinate(locationInfo.Latitude, locationInfo.Longitude);


            var nearestStoresinOrder = locations.Select(x => new GeoCoordinate(x.Latitude, x.Longitude))
                                       .OrderBy(x => x.GetDistanceTo(coord)).Select(z => new Locations {
                Distance = z.GetDistanceTo(coord), Latitude = z.Latitude, Longitude = z.Longitude
            }).ToList();


            List <NearestStoreLocation> stores = new List <NearestStoreLocation>();


            stores.AddRange(nearestStoresinOrder.Select(x => new NearestStoreLocation()
            {
                Distance  = x.Distance, InventoryStoreId = GetStoreId(x.Latitude, x.Longitude, inventorySets),
                Address   = GetStoreDetails(x.Latitude, x.Longitude, inventorySets).GetComponent <StoreDetailsComponent>().Address,
                Longitude = x.Longitude,
                Latitude  = x.Latitude, Name = GetStoreDetails(x.Latitude, x.Longitude, inventorySets).GetComponent <StoreDetailsComponent>().Name,
                City      = GetStoreDetails(x.Latitude, x.Longitude, inventorySets).GetComponent <StoreDetailsComponent>().City, Zip = GetStoreDetails(x.Latitude, x.Longitude, inventorySets).GetComponent <StoreDetailsComponent>().ZipCode, StateCode = GetStoreDetails(x.Latitude, x.Longitude, inventorySets).GetComponent <StoreDetailsComponent>().StateCode, CountryCode = GetStoreDetails(x.Latitude, x.Longitude, inventorySets).GetComponent <StoreDetailsComponent>().CountryCode
            }));

            return(stores);
        }
Exemple #2
0
        public async Task <IActionResult> Get(string id)
        {
            NearestStoreLocatorController nearestStoreLocatorController = this;

            if (!nearestStoreLocatorController.ModelState.IsValid || string.IsNullOrEmpty(id))
            {
                return((IActionResult)nearestStoreLocatorController.NotFound());
            }
            //id = id.EnsurePrefix(CommerceEntity.IdPrefix<InventoryInformation>());

            var input = id.Split('|');

            var args = new GetNearestStoreDetailsByLocationArgument()
            {
                Latitude = Convert.ToDouble(input[0]), Longitude = Convert.ToDouble(input[1])
            };

            var result = await nearestStoreLocatorController.Command <GetNearestStoreDetailsByLocationCommand>().Process(nearestStoreLocatorController.CurrentContext, args);

            return(result != null ? (IActionResult) new ObjectResult((object)result) : (IActionResult)nearestStoreLocatorController.NotFound());
        }
        public async Task <IActionResult> Get(string id)
        {
            NearestStoreLocatorController nearestStoreLocatorController = this;

            if (!nearestStoreLocatorController.ModelState.IsValid || string.IsNullOrEmpty(id))
            {
                return(nearestStoreLocatorController.NotFound());
            }

            nearestStoreLocatorController.CurrentContext.Logger.LogInformation("NearestStoreLocatorController: id" + id);

            var input = id.Split('|');

            var args = new GetNearestStoreDetailsByLocationArgument()
            {
                Latitude = Convert.ToDouble(input[0], System.Globalization.CultureInfo.InvariantCulture), Longitude = Convert.ToDouble(input[1], System.Globalization.CultureInfo.InvariantCulture)
            };

            nearestStoreLocatorController.CurrentContext.Logger.LogInformation("NearestStoreLocatorController Converted: Latitude " + args.Latitude + " - Longitude " + args.Longitude);

            var result = await nearestStoreLocatorController.Command <GetNearestStoreDetailsByLocationCommand>().Process(nearestStoreLocatorController.CurrentContext, args);

            return(result != null ? new ObjectResult(result) : (IActionResult)nearestStoreLocatorController.NotFound());
        }
        public async Task <List <NearestStoreLocation> > Process(CommerceContext commerceContext, GetNearestStoreDetailsByLocationArgument inputArgumentList)
        {
            GetNearestStoreDetailsByLocationCommand getNearestStoreDetailsByLocationCommand = this;
            CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.GetPipelineContextOptions();

            //InventorySet result = (InventorySet)null;
            List <NearestStoreLocation> sets = new List <NearestStoreLocation>();

            using (CommandActivity.Start(commerceContext, (CommerceCommand)getNearestStoreDetailsByLocationCommand))
            {
                sets = await getNearestStoreDetailsByLocationCommand._getNearestStoreDetailsByLocationPipeline.Run(inputArgumentList, pipelineContextOptions);
            }

            return(sets);
        }
Exemple #5
0
        public async Task <List <NearestStoreLocation> > Process(CommerceContext commerceContext, GetNearestStoreDetailsByLocationArgument inputArgumentList)
        {
            GetNearestStoreDetailsByLocationCommand getNearestStoreDetailsByLocationCommand = this;

            commerceContext.Logger.LogInformation("GetNearestStoreDetailsByLocationCommand: Latitude " + inputArgumentList.Latitude + " - Longitude " + inputArgumentList.Longitude);

            List <NearestStoreLocation> sets = new List <NearestStoreLocation>();

            using (CommandActivity.Start(commerceContext, getNearestStoreDetailsByLocationCommand))
            {
                sets = await getNearestStoreDetailsByLocationCommand._getNearestStoreDetailsByLocationPipeline.Run(inputArgumentList, commerceContext.PipelineContextOptions).ConfigureAwait(false);
            }

            return(sets);
        }