Beispiel #1
0
        public async Task <Traveler> CreateTravelerAsync()
        {
            var dto = new TravelerDTO()
            {
                TravelerUserIdentity = GetHardwareId()
            };
            var json     = JsonSerializerHelper.Serialize(dto);
            var uri      = new Uri(Addresses.CreateTravelerUri);
            var response = await PostAsync(uri, json);

            return(JsonSerializerHelper.Deserialize <TravelerDTO>(response.Content).ToObject());
        }
Beispiel #2
0
        public async Task <Traveler> CreateTravelerAsync()
        {
            var dto = new TravelerDTO()
            {
                TravelerUserIdentity = GetHardwareId(),
                FirstName            = "John",
                LastName             = "Doe",
                Email       = "*****@*****.**",
                MobilePhone = "55555555",
                HomeAddress = "New York"
            };
            var json     = JsonSerializerHelper.Serialize(dto);
            var uri      = new Uri(Addresses.CreateTravelerUri);
            var response = await PostAsync(uri, json);

            return(JsonSerializerHelper.Deserialize <TravelerDTO>(response.Content).ToObject());
        }
        // TODO: Lab 03 Exercise 2: Task 1.6: Review the UpdateTravelerAsync method
        public async Task <Traveler> CreateTravelerAsync()
        {
            var dto = new TravelerDTO()
            {
                TravelerUserIdentity = GetHardwareId()
            };
            string     json    = JsonConvert.SerializeObject(dto);
            HttpClient client  = new HttpClient();
            var        content = new StringContent(json);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = await client.PostAsync(new Uri(_createTravelerUri), content);

            var resultJson = await response.Content.ReadAsStringAsync();

            return(await JsonConvert.DeserializeObjectAsync <Traveler>(resultJson));
        }
        public PartialViewResult Reservations(int travelerId)
        {
            IEnumerable <ReservationDTO> reservations = null;

            using (var proxy = new HttpClient()
            {
                BaseAddress = new Uri(_companionService)
            })
            {
                TravelerDTO traveler = proxy.GetAsync("travelers/" + travelerId).Result.Content.
                                       ReadAsAsync <TravelerDTO>().Result;

                reservations = proxy.GetAsync("travelers/" + travelerId + "/reservations").Result.Content.
                               ReadAsAsync <IEnumerable <ReservationDTO> >().Result;

                ViewBag.UserId = traveler.TravelerUserIdentity;
            }

            return(PartialView(reservations));
        }