示例#1
0
        protected override async Task Handle(ShoppingPackageCommand command)
        {
            var villages = _valueRetailVillageRepository.GetAll();

            foreach (var village in villages)
            {
                ValueRetailCommanRequestModel ValueRetailCommanRequestModel = new ValueRetailCommanRequestModel
                {
                    cultureCode = village.CultureCode,
                    villageCode = village.VillageCode,
                    from        = DateTime.UtcNow
                };

                var routeResonseString = await _valueRetailAPI.GetValueRetailAPIData(ValueRetailCommanRequestModel, "Routes", "ShoppingPackage");

                if (routeResonseString.Success == true)
                {
                    ShoppingPackageRouteResponse shoppingPackageRouteResponse = Mapper <ShoppingPackageRouteResponse> .MapFromJson(routeResonseString.Result);

                    foreach (var package in shoppingPackageRouteResponse.Packages)
                    {
                        if (package.Package.PackageID == 367 || package.Package.PackageID == 366 || package.Package.PackageID == 368)
                        {
                            continue;
                        }
                        ValueRetailCommanRequestModel httpRequest = new ValueRetailCommanRequestModel
                        {
                            from        = DateTime.UtcNow,
                            to          = DateTime.UtcNow.AddYears(1),
                            packageId   = package.Package.PackageID,
                            cultureCode = village.CultureCode,
                            villageCode = village.VillageCode
                        };

                        var routeDetailResponseString = await _valueRetailAPI.GetValueRetailAPIData(httpRequest, "RouteDetails", "ShoppingPackage");

                        ShoppingPackageRouteDetail shoppingPackageRouteDetail = Mapper <ShoppingPackageRouteDetail> .MapFromJson(routeDetailResponseString.Result);

                        if (shoppingPackageRouteDetail.RequestStatus.Success)
                        {
                            var @event = SaveToEvent(shoppingPackageRouteDetail, village);
                            if (!objectComparersFactory.GetObjectsComparer <Event>().Compare(@event, new Event()))
                            {
                                var cityAndCurrency = await SaveCityStateCountry(shoppingPackageRouteDetail, village);

                                var eventVenueMapping = SaveToVenue(shoppingPackageRouteDetail, @event, cityAndCurrency, village);
                                SaveDepartureLocations(shoppingPackageRouteDetail, eventVenueMapping);
                                var eventDetail = SaveToEventDetails(shoppingPackageRouteDetail, eventVenueMapping, @event);
                                SaveBlockedDates(shoppingPackageRouteDetail, @event, eventDetail);
                                SaveTicketDetail(shoppingPackageRouteDetail, eventDetail, cityAndCurrency);
                            }
                            else
                            {
                                throw new TaskCanceledException("Data insertion for Value Retail Package failed!");
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        public async Task FetchAndSavePackageRoutes(ValueRetailVillage village)
        {
            var httpRequest = new ValueRetailCommanRequestModel
            {
                from        = DateTime.UtcNow,
                cultureCode = village.CultureCode,
                villageCode = village.VillageCode
            };

            var responseString = await _valueRetailAPI.GetValueRetailAPIData(httpRequest, "Routes", "ShoppingPackage");

            ShoppingPackageRouteResponse responseData = new ShoppingPackageRouteResponse();

            try
            {
                responseData = Mapper <ShoppingPackageRouteResponse> .MapFromJson(responseString.Result);
            }
            catch (ArgumentNullException ex)
            {
                throw ex;
            }

            foreach (var package in responseData.Packages)
            {
                var currentPackage = _valueRetailPackageRouteRepository.GetOneByPackageId(package.Package.PackageID);
                if (currentPackage == null)
                {
                    foreach (var journey in package.Journeys)
                    {
                        foreach (var route in journey.Routes)
                        {
                            try
                            {
                                currentPackage = _valueRetailPackageRouteRepository.Save(new ValueRetailPackageRoute
                                {
                                    VillageId       = village.Id,
                                    PackageId       = package.Package.PackageID,
                                    JourneyType     = journey.JourneyType,
                                    RouteId         = route.RouteId,
                                    DepartureTime   = route.DepartureTime,
                                    LinkedRouteId   = route.LinkedRouteId,
                                    ReturnTime      = route.ReturnTime,
                                    Name            = route.Name,
                                    LocationId      = route.LocationId,
                                    LocationName    = route.LocationName,
                                    LocationAddress = route.LocationAddress,
                                    StopId          = route.StopId,
                                    StopOrder       = route.StopOrder,
                                    Latitude        = route.Latitude,
                                    Longitude       = route.Longitude,
                                    AdultPrice      = route.Prices.Adult == null ? 0 : Convert.ToDecimal(route.Prices.Adult.Price),
                                    ChildrenPrice   = route.Prices.Children == null ? 0 : Convert.ToDecimal(route.Prices.Children.Price),
                                    FamilyPrice     = route.Prices.Family == null ? 0 : Convert.ToDecimal(route.Prices.Family.Price),
                                    InfantPrice     = route.Prices.Infant == null ? 0 : Convert.ToDecimal(route.Prices.Infant.Price),
                                    CreatedUtc      = DateTime.UtcNow,
                                    CreatedBy       = Guid.NewGuid(),
                                });

                                if (route.ReturnStops != null && route.ReturnStops.Count > 0)
                                {
                                    foreach (var returnStop in route.ReturnStops)
                                    {
                                        var currentReturnStop = _valueRetailPackageReturnRepository.Save(new ValueRetailPackageReturn
                                        {
                                            ValueRetailPackageRouteId = currentPackage.Id,
                                            RouteId         = returnStop.RouteId,
                                            StopId          = returnStop.StopId,
                                            StopOrder       = returnStop.StopOrder,
                                            Name            = returnStop.Name,
                                            LocationId      = returnStop.LocationId,
                                            LocationName    = returnStop.LocationName,
                                            LocationAddress = returnStop.LocationAddress,
                                            ReturnTime      = returnStop.ReturnTime,
                                            Latitude        = returnStop.Latitude,
                                            Longitude       = returnStop.Longitude,
                                            CreatedUtc      = DateTime.UtcNow,
                                            CreatedBy       = Guid.NewGuid(),
                                        });
                                    }
                                }
                            }
                            catch (TaskCanceledException ex)
                            {
                                _logger.Log(LogCategory.Error, ex);
                            }
                            catch (Exception ex)
                            {
                                _logger.Log(LogCategory.Error, new Exception("Failed to save Value Retail Package Routes in Db", ex));
                            }
                        }
                    }
                }
            }
        }