public static void Main()
public int Id { get; set; }
public string FlightNumber { get; set; }
public string From { get; set; }
public string To { get; set; }
public DateTime DepartureTime { get; set; }
public DateTime ArrivalTime { get; set; }
public int AvailableSeats { get; set; }
public int Id { get; set; }
public string FullName { get; set; }
public string PhoneNumber { get; set; }
public string Nationality { get; set; }
public string ReservationType { get; set; }
public int FlightId { get; set; }
public Flight Flight { get; set; }
public bool IsConfirmed { get; set; }
public DateTime ReservationDate { get; set; }
using Microsoft.EntityFrameworkCore;
public class FlightManagerContext : DbContext
public DbSet<Flight> Flights { get; set; }
public DbSet<Reservation> Reservations { get; set; }
public FlightManagerContext(DbContextOptions<FlightManagerContext> options) : base(options) { }
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
[Route("api/[controller]")]
public class ReservationController : ControllerBase
private readonly FlightManagerContext _context;
public ReservationController(FlightManagerContext context)
public async Task<IActionResult> MakeReservation([FromBody] Reservation reservation)
if (string.IsNullOrEmpty(reservation.FullName) || string.IsNullOrEmpty(reservation.PhoneNumber))
return BadRequest("All fields are required.");
var flight = await _context.Flights.FindAsync(reservation.FlightId);
if (flight == null || flight.AvailableSeats <= 0)
return BadRequest("Flight not available.");
reservation.ReservationDate = DateTime.Now;
reservation.IsConfirmed = false;
_context.Reservations.Add(reservation);
await _context.SaveChangesAsync();
return (new { message = "Reservation made successfully. Confirmation pending." });
Authorize(Roles = "Admin")
public async Task<IActionResult> GetReservations()
var reservations = await _context.Reservations.Include(r => r.Flight).ToListAsync();