public ActionResult Create([Bind(Include = "UserId,Name,Email")] FlyUser flyUser)
        {
            if (ModelState.IsValid)
            {
                db.FlyUsers.Add(flyUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(flyUser));
        }
Exemple #2
0
        public ActionResult Create([Bind(Include = "TicketNo,FlightId,DateOfBooking,JourneyDate,Origin,Destination,PassengerName,ContactNo,Email,NoOfTickets,TotalFare,Status")] FlyReservation flyReservation)
        {
            if (ModelState.IsValid)
            {
                db.FlyReservations.Add(flyReservation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.FlightId = new SelectList(db.FlightsDetails, "FlightId", "Origin", flyReservation.FlightId);
            return(View(flyReservation));
        }
        public void GetBooking()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetBooking")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.AddRange(
                    new Booking {
                    Id = 1, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 5, 10)
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Get(1);
                Assert.IsTrue(result is ObjectResult);
                var objectResult = result as ObjectResult;
                Assert.IsTrue(objectResult.Value is Booking);
                var booking = objectResult.Value as Booking;
                Assert.AreEqual(1, booking.Id);
                Assert.AreEqual("Joe Bloggs", booking.PassengerName);
                Assert.AreEqual(new DateTime(2018, 5, 10), booking.Date);
            }
        }
        public void CreateBookingWithInvalidFlight()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "CreateBookingWithInvalidFlight")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Create(new Booking
                {
                    PassengerName = "Joe Bloggs",
                    Date          = new DateTime(2018, 5, 10),
                    FlightNumber  = 2
                });
                Assert.IsTrue(result is BadRequestResult);
            }
        }
Exemple #5
0
        public void AvailableFlightsWithStartAndEndDate()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "AvailableFlightsWithStartAndEndDate")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var search  = new Search(flightContext);
                var results = search.GetAvailableFlights(new DateTime(2018, 5, 10), new DateTime(2018, 5, 12), null);
                Assert.AreEqual(3, results.Count);
                Assert.AreEqual(new DateTime(2018, 5, 10), results[0].Date);
                Assert.AreEqual(1, results[0].Flight.Number);
                Assert.AreEqual(1, results[0].RemainingCapacity);
                Assert.AreEqual(new DateTime(2018, 5, 11), results[1].Date);
                Assert.AreEqual(1, results[1].Flight.Number);
                Assert.AreEqual(1, results[1].RemainingCapacity);
                Assert.AreEqual(new DateTime(2018, 5, 12), results[2].Date);
                Assert.AreEqual(1, results[2].Flight.Number);
                Assert.AreEqual(1, results[2].RemainingCapacity);
            }
        }
Exemple #6
0
        public override void Seed()
        {
            if (FlightsContext.FlightRates.Any())
            {
                Console.WriteLine("Skipping FlightRates seeder because table is not empty.");
                return;
            }
            ;

            var flights = FlightsContext.Flights.ToList();
            var random  = new Random();

            foreach (var flight in flights)
            {
                var numberOfClasses = random.Next(1, 3);
                var price           = new Price(new decimal(random.Next(5000, 30000) / 2), Currency.EUR);

                flight.AddRate("Economy class", price, random.Next(20, 100));

                if (numberOfClasses > 1)
                {
                    var secondPrice = new Price(price.Value + new decimal(random.Next(5000, 30000) / 2), Currency.EUR);
                    flight.AddRate("Business class", secondPrice, random.Next(20, 100));
                }

                if (numberOfClasses > 2)
                {
                    var thirdPrice = new Price(price.Value + new decimal(random.Next(5000, 30000) / 2), Currency.EUR);
                    flight.AddRate("First class", thirdPrice, random.Next(20, 100));
                }
            }

            FlightsContext.SaveChanges();
        }
        public override void Seed()
        {
            if (FlightsContext.Airports.Any())
            {
                Console.WriteLine("Skipping Airports seeder because table is not empty.");
                return;
            }

            var airports = new List <Airport>()
            {
                new Airport("AMS", "Amsterdam Airport Schiphol"),
                new Airport("FRA", "Frankfurt am Main Airport"),
                new Airport("LHR", "London Heathrow Airport"),
                new Airport("BCN", "Barcelona International Airport"),
                new Airport("CDG", "Charles de Gaulle International"),
                new Airport("IST", "Istanbul Airport"),
                new Airport("MUC", "Munich Airport"),
                new Airport("ZRH", "Zurich Airport"),
                new Airport("DUB", "Dublin Airport"),
                new Airport("FCO", "Rome Fiumicino Airport"),
                new Airport("ARN", "Stockholm Arlanda Airport"),
                new Airport("CPH", "Copenhagen Airport"),
            };

            FlightsContext.Airports.AddRange(airports);
            FlightsContext.SaveChanges();
        }
        public void GetBookingsUsingSearchWithNoResults()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetBookingsUsingSearchWithNoResults")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.AddRange(
                    new Booking {
                    Id = 1, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 5, 10)
                },
                    new Booking {
                    Id = 2, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 4, 10)
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Get("John", DateTime.MinValue, null, string.Empty, string.Empty);
                Assert.IsTrue(result is NotFoundResult);
            }
        }
Exemple #9
0
        public IHttpActionResult PostPlace(PlaceData data)
        {
            FlightPlace place  = new FlightPlace();
            DateTime    Actual = DateTime.Now;

            place.Place_Owner_DNI  = data.ClientDNI;
            place.Place_Owner_Name = data.ClientName;
            place.idFlight         = data.idFlight;
            place.FP_Date          = Actual;


            db.FlightPlaces.Add(place);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (FlightPlaceExists(place.numPlace))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = place.numPlace }, place));
        }
Exemple #10
0
        public void SearchWithPassengerName()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "SearchWithPassengerName")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Bookings.AddRange(
                    new Booking {
                    PassengerName = "Joe Bloggs"
                },
                    new Booking {
                    PassengerName = "Jane Smith"
                }
                    );
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var search  = new Search(flightContext);
                var results = search.SearchForBooking("Bloggs", DateTime.MinValue, null, string.Empty, string.Empty);

                Assert.AreEqual(1, results.Count);
                Assert.AreEqual("Joe Bloggs", results[0].PassengerName);
            }
        }
Exemple #11
0
        public override void Seed()
        {
            if (FlightsContext.Flights.Any())
            {
                Console.WriteLine("Skipping Flights seeder because table is not empty.");
                return;
            }
            ;

            for (int i = 0; i < 100; i++)
            {
                var random            = new Random();
                var randomSkip        = random.Next(0, FlightsContext.Airports.Count() - 2);
                var twoRandomAirports = FlightsContext.Airports.OrderBy(o => o.Id).Skip(randomSkip).Take(2).ToList();

                var departure = new DateTimeOffset(
                    random.Next(2021, 2023), random.Next(1, 12), 01, random.Next(0, 23),
                    random.Next(0, 59), 0, TimeSpan.Zero);

                FlightsContext.Flights.Add(new Flight(
                                               departure,
                                               departure.AddHours(random.Next(1, 16)),
                                               twoRandomAirports[0].Id,
                                               twoRandomAirports[1].Id
                                               ));
            }

            FlightsContext.SaveChanges();
        }
        public void GetFlight()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetFlight")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var flightController = new FlightController(flightContext);
                var result           = flightController.Get(1);
                Assert.IsTrue(result is ObjectResult);
                var objectResult = result as ObjectResult;
                Assert.IsTrue(objectResult.Value is Flight);
                var flight = objectResult.Value as Flight;
                Assert.AreEqual(1, flight.Number);
                Assert.AreEqual(1, flight.Capacity);
            }
        }
        public IActionResult Post([FromBody] Flight flight)
        {
            _context.Flights.Add(flight);
            _context.SaveChanges();

            return(CreatedAtAction(nameof(Get), flight.Id));
        }
        public void GetBookingsUsingSearch()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetBookingsUsingSearch")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.AddRange(
                    new Booking {
                    Id = 1, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 5, 10)
                },
                    new Booking {
                    Id = 2, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 4, 10)
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Get("Bloggs", DateTime.MinValue, null, string.Empty, string.Empty);
                Assert.IsTrue(result is ObjectResult);
                var objectResult = result as ObjectResult;
                Assert.IsTrue(objectResult.Value is IList <Booking>);
                var bookings = (objectResult.Value as IList <Booking>).ToList();
                Assert.AreEqual(2, bookings.Count);
                Assert.AreEqual(1, bookings[0].Id);
                Assert.AreEqual("Joe Bloggs", bookings[0].PassengerName);
                Assert.AreEqual(new DateTime(2018, 5, 10), bookings[0].Date);
                Assert.AreEqual(2, bookings[1].Id);
                Assert.AreEqual("Joe Bloggs", bookings[1].PassengerName);
                Assert.AreEqual(new DateTime(2018, 4, 10), bookings[1].Date);
            }
        }
Exemple #15
0
        public void SearchWithDate()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "SearchWithDate")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Bookings.AddRange(
                    new Booking {
                    Date = new DateTime(2018, 5, 10)
                },
                    new Booking {
                    Date = new DateTime(2018, 5, 11)
                }
                    );
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var search  = new Search(flightContext);
                var results = search.SearchForBooking(string.Empty, new DateTime(2018, 5, 10), null, string.Empty, string.Empty);

                Assert.AreEqual(1, results.Count);
                Assert.AreEqual(new DateTime(2018, 5, 10), results[0].Date);
            }
        }
        public void GetAvailableFlightWithStartAndEndDate()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetAvailableFlightWithEndDate")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var flightController = new FlightController(flightContext);
                var result           = flightController.Get(new DateTime(2018, 5, 10), new DateTime(2018, 5, 10), null);
                Assert.IsTrue(result is ObjectResult);
                var objectResult = result as ObjectResult;
                Assert.IsTrue(objectResult.Value is IList <AvailableFlight>);
                var flights = (objectResult.Value as IList <AvailableFlight>).ToList();
                Assert.AreEqual(1, flights.Count);
                Assert.AreEqual(new DateTime(2018, 5, 10), flights[0].Date);
                Assert.AreEqual(1, flights[0].RemainingCapacity);
                Assert.AreEqual(1, flights[0].Flight.Number);
            }
        }
Exemple #17
0
        public void AvailableFlightsWithToManyPassengersDueToBookings()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "AvailableFlightsWithToManyPassengersDueToBookings")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                var flight = new Flight {
                    Number = 1, Capacity = 1
                };
                flightContext.Add(flight);
                flightContext.Add(new Booking {
                    Date = new DateTime(2018, 5, 11), FlightNumber = 1, Flight = flight
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var search  = new Search(flightContext);
                var results = search.GetAvailableFlights(new DateTime(2018, 5, 10), new DateTime(2018, 5, 12), 1);
                Assert.AreEqual(2, results.Count);
                Assert.AreEqual(new DateTime(2018, 5, 10), results[0].Date);
                Assert.AreEqual(1, results[0].Flight.Number);
                Assert.AreEqual(1, results[0].RemainingCapacity);
                Assert.AreEqual(new DateTime(2018, 5, 12), results[1].Date);
                Assert.AreEqual(1, results[1].Flight.Number);
                Assert.AreEqual(1, results[1].RemainingCapacity);
            }
        }
Exemple #18
0
        public void SearchWithDepartureCity()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "SearchWithDepartureCity")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Bookings.AddRange(
                    new Booking {
                    Flight = new Flight {
                        DepartureCity = "Camooweal"
                    }
                },
                    new Booking {
                    Flight = new Flight {
                        DepartureCity = "Einasleigh"
                    }
                }
                    );
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var search  = new Search(flightContext);
                var results = search.SearchForBooking(string.Empty, DateTime.MinValue, null, string.Empty, "Camooweal");

                Assert.AreEqual(1, results.Count);
                Assert.AreEqual("Camooweal", results[0].Flight.DepartureCity);
            }
        }
Exemple #19
0
        public void SearchWithFlightNumber()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "SearchWithFlightNumber")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Bookings.AddRange(
                    new Booking {
                    Flight = new Flight {
                        Number = 1
                    }
                },
                    new Booking {
                    Flight = new Flight {
                        Number = 2
                    }
                }
                    );
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var search  = new Search(flightContext);
                var results = search.SearchForBooking(string.Empty, DateTime.MinValue, 1, string.Empty, string.Empty);

                Assert.AreEqual(1, results.Count);
                Assert.AreEqual(1, results[0].Flight.Number);
            }
        }
 public ActionResult Registration(FlyRegister objUser)
 {
     if (ModelState.IsValid)
     {
         FlightsContext db = new FlightsContext();
         db.FlyRegisters.Add(objUser);
         db.SaveChanges();
     }
     ViewBag.Message = "Successfull Created";
     return(RedirectToAction("Login"));
 }
        public ActionResult Create([Bind(Include = "UserName,Password,Role,EmailID")] FlyRegister flyAdmin)
        {
            if (ModelState.IsValid)
            {
                db.FlyRegisters.Add(flyAdmin);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(flyAdmin));
        }
Exemple #22
0
        public void AvailableFlightsWithToManyPassengers()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "AvailableFlightsWithToManyPassengers")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var search  = new Search(flightContext);
                var results = search.GetAvailableFlights(new DateTime(2018, 5, 10), new DateTime(2018, 5, 12), 2);
                Assert.AreEqual(0, results.Count);
            }
        }
        public void GetInvalidFlight()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetInvalidFlight")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var flightController = new FlightController(flightContext);
                var result           = flightController.Get(2);
                Assert.IsTrue(result is NotFoundResult);
            }
        }
        public void GetBookingInvalidId()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetBookingInvalidId")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.AddRange(
                    new Booking {
                    Id = 1, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 5, 10)
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Get(2);
                Assert.IsTrue(result is NotFoundResult);
            }
        }
        public void CreateBooking()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "CreateBooking")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                var flight = new Flight {
                    Number = 1, Capacity = 1
                };
                flightContext.Add(flight);
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Create(new Booking
                {
                    PassengerName = "Joe Bloggs",
                    Date          = new DateTime(2018, 5, 10),
                    FlightNumber  = 1
                });
                Assert.IsTrue(result is CreatedAtRouteResult);
                var objectResult = result as CreatedAtRouteResult;
                Assert.IsTrue(objectResult.Value is Booking);
                var bookings = objectResult.Value as Booking;
                Assert.AreEqual(1, bookings.Id);
                Assert.AreEqual("Joe Bloggs", bookings.PassengerName);
                Assert.AreEqual(new DateTime(2018, 5, 10), bookings.Date);
                Assert.AreEqual(1, flightContext.Bookings.Count());
                Assert.AreEqual(1, flightContext.Bookings.First().Id);
                Assert.AreEqual("Joe Bloggs", flightContext.Bookings.First().PassengerName);
                Assert.AreEqual(new DateTime(2018, 5, 10), flightContext.Bookings.First().Date);
            }
        }
Exemple #26
0
        public IHttpActionResult PutPreBooks(string id, int cant)

        {
            CommercialFlight vuelo = db.CommercialFlights.Find(id);

            if (id != vuelo.IdFlight)
            {
                return(BadRequest());
            }

            vuelo.Disponible_Places = vuelo.Disponible_Places - cant;


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Entry(vuelo).State = EntityState.Modified;
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommercialFlightExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #27
0
 public void Delete(T entity)
 {
     _context.Set <T>().Remove(entity);
     _context.SaveChanges();
 }
 public void Save()
 {
     _flightsContext.SaveChanges();
 }