예제 #1
0
        async Task <TourDTO> IService <TourDTO, int> .Delete(TourDTO entity)
        {
            Tour tour = await _tourRepository.Get(entity.Id);

            tour.CountOfTours = 0;
            tour = await _tourRepository.Update(tour);

            return(_mapper.Map <Tour, TourDTO>(tour));
        }
예제 #2
0
        async Task <OrderDTO> IService <OrderDTO, int> .Add(OrderDTO entity)
        {
            Order order = await _orderRepository.Add(_mapper.Map <OrderDTO, Order>(entity));

            if (order != null)
            {
                Tour tour = await _tourRepository.Get(entity.Tour.Id);

                tour.CountOfTours--;
                tour = await _tourRepository.Update(tour);
            }
            return(_mapper.Map <Order, OrderDTO>(order));
        }
예제 #3
0
 public async Task <IEnumerable <Tour> > GetTours()
 {
     return(await _repository.Get());
 }
        public async Task <IActionResult> Index()
        {
            var results = await _repository.Get();

            return(View(results));
        }
예제 #5
0
        public async Task Execute(int providerId)
        {
            _logger.LogInformation("Download Started");

            var apiResponse = await _apiDownloader.Download();

            var provider = await _providerRepository.Get(providerId);

            try
            {
                if (provider != null)
                {
                    if (apiResponse.StatusCode == (int)HttpStatusCode.OK)
                    {
                        var mappings = new List <TourAvailability>();

                        var existingTours         = _tourRepository.GetAllTours().Result;
                        var productCodesToTourIds = existingTours.Values.ToDictionary(t => t.TourRef, t => t.TourId);

                        // map to existing model
                        foreach (var availability in apiResponse.Body)
                        {
                            if (!apiResponse.Body.Any())
                            {
                                break;
                            }

                            // ignore updates for non-existent tours
                            if (!productCodesToTourIds.ContainsKey(availability.ProductCode))
                            {
                                break;
                            }

                            var startDateValid = DateTime.TryParse(availability.DepartureDate, out var startDate);

                            if (startDateValid)
                            {
                                var tourId = productCodesToTourIds[availability.ProductCode];

                                mappings.Add(
                                    new TourAvailability
                                {
                                    TourId            = tourId,
                                    StartDate         = startDate,
                                    TourDuration      = availability.Nights,
                                    AdultPrice        = AdjustPrice(availability.Price, provider), //adjust price with discount and commission,
                                    AvailabilityCount = availability.Spaces
                                });

                                var tour = _tourRepository.Get(tourId).Result;
                                tour.Availabilities = mappings.Where(mapping => mapping.TourId == tourId).ToList();

                                // save to repository
                                await _tourRepository.Update(tour);
                            }
                            else
                            {
                                _logger.LogError($"Could not parse the given date: {availability.DepartureDate}");
                            }
                        }
                    }
                    else
                    {
                        _logger.LogError($"Download failed with status code {apiResponse.StatusCode}");
                    }
                }
                else
                {
                    _logger.LogError("Provider does not exist");
                }
            }
            catch
            {
                throw new Exception("Download Request Failed");
            }

            _logger.LogInformation("Download Finished");
        }