public CountryViewModel GetCountry(string tourType, string countryUrl)
        {
            var tourTypeDomain   = TourTypesConverter.ConvertFromString(tourType);
            var country          = _countryManager.GetCountry(tourTypeDomain, countryUrl);
            var countryViewModel = new CountryViewModel(country);

            return(countryViewModel);
        }
Exemple #2
0
        public async Task <IActionResult> GetCountry(int id)
        {
            var country = await _countryManager.GetCountry(id);

            return(Ok(new ApiResponse <CountryModel>()
            {
                Data = country,
                Message = "Succesful",
                StatusCode = HttpStatusCode.OK
            }));
        }
Exemple #3
0
        public IActionResult Get(string code)
        {
            var country = _countryManager.GetCountry(code);

            if (country == null)
            {
                return(NotFound());
            }

            return(new JsonResult(country));
        }
        public IActionResult Get(long id)
        {
            if (!ModelState.IsValid)
            {
                //return 400
                return(BadRequest(ModelState));
            }

            var result = countryManager.GetCountry(id);

            if (result == null)
            {
                //return 404
                return(NotFound(id));
            }

            //return 200
            return(this.HAL(result, new Link[] {
                new Link(Link.RelForSelf, $"/api/v1/countries/{id}"),
                new Link("updateCountry", $"/api/v1/countries/{id}", "Update Country", "PUT"),
                new Link("deleteCountry", $"/api/v1/countries/{id}", "Delete Country", "DELETE")
            }));
        }
Exemple #5
0
        public IActionResult BookingForm(BookingFormViewModel formData)
        {
            if (!ModelState.IsValid)
            {
                //Restore accommodation object from ID
                Accommodation accommodation;
                try
                {
                    accommodation = _accommodationManager.GetAccommodation(formData.AccommodationId);
                    formData.AccommodationName = accommodation.Name;
                }
                catch (KeyNotFoundException)
                {
                    return(NotFound());
                }

                ViewBag.Countries  = _countryManager.GetCountries();
                ViewBag.MaxPersons = formData.Persons.Count();

                //Initialize BookingPersons up to the maximum that the accommodation will support.
                //Old values entered by the user should be kept.
                for (int i = 0; i < accommodation.MaxPersons; i++)
                {
                    if (formData.Persons.ElementAtOrDefault(i) == null)
                    {
                        formData.Persons.Add(new BookingPerson());
                    }
                }

                return(View("BookingForm", formData));
            }
            else
            {
                //Get accommodation from posted ID
                Accommodation accommodation;
                try
                {
                    accommodation = _accommodationManager.GetAccommodation(formData.AccommodationId);
                }
                catch (KeyNotFoundException)
                {
                    return(BadRequest());
                }

                //Get country and nationality objects from ID
                foreach (BookingPerson person in formData.Persons)
                {
                    person.Country     = _countryManager.GetCountry(person.Country.Id);
                    person.Nationality = _countryManager.GetCountry(person.Nationality.Id);
                }

                //Store model in Session
                HttpContext.Session.Set(BOOKINGSESSIONKEY, new Booking()
                {
                    Accommodation = accommodation,
                    Persons       = formData.Persons,
                });

                return(RedirectToAction("InsuranceForm"));
            }
        }