public IActionResult OnGetAsync(int?id) { Reservation = new ReservationObj { ClientName = User.Identity.Name }; return(Page()); }
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")); }
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()); }