Ejemplo n.º 1
0
        public async Task <IActionResult> Create(Vacation vacation)
        {
            TravelerPlacesViewModel travelerPlaces = new TravelerPlacesViewModel();
            bool exists;

            if (ModelState.IsValid)
            {
                var userId   = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                var traveler = await _repo.Traveler.GetTraveler(userId);

                var vacations = await _repo.Vacation.GetVacations(traveler.Id);

                var startDates = vacations.Select(v => v.VacationStart.Value).ToList();
                if (startDates.Contains(vacation.VacationStart.Value))
                {
                    exists = true;
                    travelerPlaces.exists = exists;
                    return(RedirectToAction("Index", "Traveler", travelerPlaces));
                }
                DestinationInfo info = await _destinationIdService.GetDestinationId(vacation);

                vacation.DestinationId = info.data[0].result_object.location_id;
                _repo.Vacation.CreateVacation(vacation);
                _repo.Save();
                return(RedirectToAction("Index", "Traveler", travelerPlaces));
            }
            ViewData["TravelerId"] = new SelectList(_context.Travelers, "Id", "Id", vacation.TravelerId);
            return(RedirectToAction("Index", "Traveler"));
        }
        public async Task <IActionResult> Index(TravelerPlacesViewModel travelerPlaces)
        {
            var userId   = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var traveler = await _repo.Traveler.GetTraveler(userId);

            if (traveler == null)
            {
                return(RedirectToAction("Create"));
            }
            travelerPlaces.Traveler  = traveler;
            travelerPlaces.Vacations = await _repo.Vacation.GetVacations(traveler.Id);

            return(View(travelerPlaces));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Index(int?Id, TravelerPlacesViewModel travelerPlaces)
        {
            var userId   = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var traveler = await _repo.Traveler.GetTraveler(userId);

            Vacation vacation = new Vacation();

            if (Id != null && Id.Value > 0)
            {
                traveler.VacationId = Id.Value;
                _repo.Traveler.EditTraveler(traveler);
                _repo.Save();
            }
            vacation = await _repo.Vacation.GetVacation(traveler.VacationId);

            var hotels = await _repo.Hotel.GetHotels(vacation.Id);

            if (hotels.Count > 0)
            {
                travelerPlaces.Hotels = hotels[0];
            }
            var flights = await _repo.Flight.GetFlights(vacation.Id);

            if (flights.Count > 0)
            {
                travelerPlaces.Flight = flights[0];
            }
            var excursions = await _repo.Excursion.GetExcursions(vacation.Id);

            travelerPlaces.Excursions = excursions.OrderByDescending(e => e.Importance).ToList();
            travelerPlaces.PlacesOne  = await _interestOneService.GetInterestOnePlaces(traveler, vacation);

            travelerPlaces.PlacesTwo = await _interestTwoService.GetInterestTwoPlaces(vacation, traveler);

            travelerPlaces.PlacesThree = await _interestThreeService.GetInterestThreePlaces(vacation, traveler);

            travelerPlaces.Traveler = traveler;
            travelerPlaces.Vacation = vacation;
            return(View(travelerPlaces));
        }