Ejemplo n.º 1
0
        public RedirectToRouteResult AddToCart(Cart cart, int tourId, string returnUrl)
        {
            Tour tour = repository.GetAllTours()
                        .FirstOrDefault(b => b.TourId == tourId);

            if (tour != null)
            {
                cart.AddItem(tour, 1);
            }

            return(RedirectToAction("Index", new { returnUrl }));
        }
Ejemplo n.º 2
0
        public ViewResult Edit(int tourId)
        {
            Tour tour = repository.GetAllTours().FirstOrDefault(b => b.TourId == tourId);

            TourEditViewModel model = new TourEditViewModel
            {
                Tour         = tour,
                Formats      = formatRepository.GetAllFormats(),
                CurentFormat = tour.FormatId
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public IActionResult Index(string searchString)
        {
            var Tours = _tourRepository.GetAllTours().ToList();

            if (!String.IsNullOrEmpty(searchString))
            {
                Tours = _tourRepository.GetAllTours().Where(t => t.Countries.Contains(searchString)).ToList();
            }
            else
            {
                Tours = _tourRepository.GetAllTours().ToList();
            }
            return(View(Tours));
        }
Ejemplo n.º 4
0
        public PartialViewResult Menu(string type = null)
        {
            ViewBag.SelectedType = type;

            IEnumerable <string> types = repository.GetAllTours()
                                         .Select(tour => tour.Type)
                                         .Distinct()
                                         .OrderBy(x => x);

            return(PartialView(types));
        }
Ejemplo n.º 5
0
        public ViewResult List(string type, int page = 1)
        {
            ToursListViewModel model = new ToursListViewModel
            {
                Tours = repository.GetAllTours()
                        .Where(b => type == null || b.Type == type)
                        .OrderBy(tour => tour.TourId)
                        .Skip((page - 1) * pageSize)
                        .Take(pageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = type == null?
                                   repository.GetAllTours().Count() :
                                       repository.GetAllTours().Where(tour => tour.Type == type).Count()
                },
                CurrentType = type
            };

            return(View(model));
        }
Ejemplo n.º 6
0
 public ICollection <Contracts.Tour> GetTours()
 {
     return(_mapper.Map <ICollection <Model.Tour>, ICollection <Contracts.Tour> >(_tourRepository.GetAllTours()));
 }
Ejemplo n.º 7
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");
        }
Ejemplo n.º 8
0
        public IActionResult Index()
        {
            List <Tour> Tours = _tourRepository.GetAllTours().ToList();

            return(View(Tours));
        }
Ejemplo n.º 9
0
        public IActionResult Wakacje()
        {
            var trips = repo.GetAllTours();

            return(View(trips));
        }