Beispiel #1
0
 public IActionResult OnGetAsync(int?id)
 {
     Reservation = new ReservationObj {
         ClientName = User.Identity.Name
     };
     return(Page());
 }
Beispiel #2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            try
            {
                var client = _clientFactory.CreateClient("webApi");
                HttpResponseMessage response = await client.PostAsJsonAsync($"api/reservation", Reservation);

                if (response.IsSuccessStatusCode)
                {
                    Reservation = await response.Content.ReadAsAsync <ReservationObj>();
                }

                Message = $"Reservation for {Reservation.ClientName} in {Reservation.Location} has been added!";
            }
            catch
            {
                if (await ReservationExists(Reservation.ReservationId))
                {
                    throw;
                }
                else
                {
                    return(NotFound());
                }
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var request = new HttpRequestMessage(HttpMethod.Get, $"api/reservation/{id}");
            var client  = _clientFactory.CreateClient("webApi");
            HttpResponseMessage response = await client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                Reservation = await response.Content.ReadAsAsync <ReservationObj>();
            }
            return(Page());
        }