public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Booking.Add(Booking); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> Post([FromBody] Booking booking) { var bookingEntry = new Booking { ServiceDate = booking.ServiceDate, ServiceTime = booking.ServiceTime, ServicePrice = booking.ServicePrice, ServiceApproximateDuration = booking.ServiceApproximateDuration, ServiceStreet = booking.ServiceStreet, ServiceCity = booking.ServiceCity, ServiceState = booking.ServiceState, ServiceZipCode = booking.ServiceZipCode, ServiceResidence = booking.ServiceResidence, ServiceBedrooms = booking.ServiceBedrooms, ServiceBathrooms = booking.ServiceBathrooms, ServiceType = booking.ServiceType, ServiceNotes = booking.ServiceNotes, ServiceDateTime = booking.ServiceDateTime, FirstName = booking.FirstName, LastName = booking.LastName, EmailAddress = booking.EmailAddress, PhoneNumber = booking.PhoneNumber }; try { _context.Add(bookingEntry); await _context.SaveChangesAsync(); } catch (Exception ex) { var exception = ex.Message; } return(Ok(true)); }