public async Task <IActionResult> GetReservation(int eventId) { var booking = await _context.FoodBookings.FindAsync(eventId); if (booking == null) { return(NotFound()); } FoodBookingDto bookingDto = new FoodBookingDto(booking); return(Ok(bookingDto)); }
//BOOKMENUE public async Task <IActionResult> BookMenu(int?eventid, int?menuid) { if (eventid == null || menuid == null) { return(BadRequest()); } var @event = await _context.Events.FindAsync(eventid); HttpClient client = getClient("32824"); HttpResponseMessage response = await client.GetAsync("api/Menus/" + menuid); Menu menu = await response.Content.ReadAsAsync <Menu>(); @event.Menu = menu.Starter + " | " + menu.Main + " | " + menu.Dessert; @event.FoodCost = menu.Cost; _context.Update(@event); await _context.SaveChangesAsync(); FoodBookingDto booking = new FoodBookingDto(); booking.EventId = (int)eventid; booking.MenuId = (int)menuid; HttpResponseMessage delete = await client.DeleteAsync("api/bookings/" + eventid); HttpResponseMessage post = await client.PostAsJsonAsync("api/bookings", booking); if (post.IsSuccessStatusCode) { HttpResponseMessage getBooking = await client.GetAsync("api/foodmenus/" + menuid); var x = await getBooking.Content.ReadAsAsync <Menu>(); ViewData["EventId"] = eventid; return(View("BookMenu", x)); } else { return(RedirectToAction(nameof(Index))); } }
public async Task <IActionResult> CreateReservation([FromBody] FoodBookingDto bookingDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var booking = new FoodBooking(bookingDto); try { _context.Add(booking); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception e) { } return(NotFound()); }
//Posts/puts chosen menu to catering API and saves a menu id to local database for reference //Unlike venue information, menu data stored locally is minimal to prevent too much unecessary data duplication //and to ensure menu info is always queries from the API to ensure it is up to date public async Task <IActionResult> SelectMenu(int menuId, int eventId) { FoodBookingDto booking = new FoodBookingDto(menuId, eventId); string uri = "/api/FoodBooking"; var client = setupCateringClient(); string getUri = uri + "?eventId=" + eventId; HttpResponseMessage existingBooking = await client.GetAsync(getUri); HttpResponseMessage response; if (existingBooking.IsSuccessStatusCode) { response = await client.PutAsJsonAsync <FoodBookingDto>(uri, booking); } else { response = await client.PostAsJsonAsync <FoodBookingDto>(uri, booking); } if (response.IsSuccessStatusCode) { Event @event = await _context.Events.Where(e => e.IsActive == true).FirstOrDefaultAsync(e => e.Id == eventId); try { @event.menuId = menuId; await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } catch (Exception e) { } } return(RedirectToAction("BookMenu", new { eventId, message = "Something went wrong, please try again" })); }
public async Task <IActionResult> EditReservation([FromBody] FoodBookingDto bookingDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var booking = await _context.FoodBookings.FindAsync(bookingDto.EventId); if (booking != null) { try { booking.MenuNumber = bookingDto.MenuId; await _context.SaveChangesAsync(); return(Ok()); } catch (Exception e) { } } return(NotFound()); }