public void CleanAfterTest()
        {
            _dbContext.Passengers.RemoveRange(_dbContext.Passengers.Where(p => p.Id > _lastPassengerId));
            _dbContext.SaveChanges();

            _dbContext.Bookings.RemoveRange(_dbContext.Bookings.Where(b => b.Id > _lastBookingId));
            _dbContext.SaveChanges();
        }
Beispiel #2
0
        public async Task <IActionResult> CreateNewFlight([FromBody] Flight flight)
        {
            await _db.Flights.AddAsync(flight);

            _db.SaveChanges();

            return(Ok());
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "ID,Name")] Flight flight)
        {
            if (ModelState.IsValid)
            {
                db.Flights.Add(flight);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(flight));
        }
        public ActionResult Create([Bind(Include = "ID,AirportName,CityName,Longitude,Latitude")] Airport airport)
        {
            if (ModelState.IsValid)
            {
                db.Airports.Add(airport);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(airport));
        }
        public async Task GetFlightPlan_ShouldReturnFlightPlan_WhenFlightPlanExists()
        {
            Location location = new Location();

            location.ID = "DF562344";
            // Arrange
            var flightPlanDto = new FlightPlan
            {
                ID              = "NL145289",
                Passengers      = 257,
                CompanyName     = "el al",
                InitialLocation = location
            };

            flightDBContextMock.FlightPlan.Add(flightPlanDto);
            flightDBContextMock.SaveChanges();
            // Act
            var flightPlan = await flightDBContextMock.FlightPlan.FindAsync("NL145289");

            Task <ActionResult <FlightPlan> > fp1 = sut.GetFlightPlan("NL145289");

            // Assert

            /** check some attrubutes of the FlightPlan feilds in DB
             * */
            Assert.IsTrue("NL145289" == flightPlan.ID);
            Assert.IsTrue(257 == flightPlan.Passengers);
            Assert.IsTrue("el al" == flightPlan.CompanyName);
            Assert.IsTrue("DF562344" == flightPlan.InitialLocation.ID);

            /** check GetFlightPlan method
             */
            // true because we added a flight plan with that id to the DB
            Assert.IsNotNull(fp1);
        }
        public async Task <ActionResult <IEnumerable <Flight> > > GetFlight([FromQuery] string relative_to = null)
        {
            if (relative_to == null)
            {
                return(NotFound());
            }
            // True if the request contain 'sync_all'.
            Boolean sync = Request.Query.ContainsKey("sync_all");

            FlightDbContext.ServerID.Clear();
            context.SaveChanges();
            List <Flight> flights  = new List <Flight>();
            DateTime      relative = new DateTime();

            try
            {
                relative = LocalLibrary.ConvertToDateTime(relative_to);
            }
            catch (Exception)
            {
                // Relative_to is not a valid time.
                return(NotFound());
            }
            // Take internal flights.
            List <Flight> internalFlights = CreateInternalFlights(relative);

            foreach (Flight inf in internalFlights)
            {
                flights.Add(inf);
            }
            // Take external flights if the request contain 'sync_all'.
            if (sync)
            {
                List <Flight> externalFlights = CreateExternalFlights(relative_to);
                foreach (Flight exf in externalFlights)
                {
                    flights.Add(exf);
                }
            }
            Task <ActionResult <IEnumerable <Flight> > > f = Task <ActionResult <IEnumerable <Flight> > > .Factory.StartNew(() =>
            {
                return(flights);
            });

            return(await f);
        }
        private void CreateBooking(BookingRequest req, Passenger foundPassenger)
        {
            var booking = new Booking();

            booking.FlightId    = _dbCtx.Flights.FirstOrDefault(flight => flight.FlightNo == req.FlightNumber)?.Id;
            booking.PassengerId = foundPassenger.Id;
            booking.TravelDay   = req.TravelDay;
            if (_dbCtx.Bookings.Any(xb => xb.FlightId == booking.FlightId &&
                                    xb.PassengerId == foundPassenger.Id &&
                                    xb.TravelDay.Value == req.TravelDay))
            {
                throw new HttpException(400, "Booking already exists");
            }

            _dbCtx.Bookings.Add(booking);
            _dbCtx.SaveChanges();
        }
        public ActionResult UpdateFlightPlan(FlightPlanDetails flightPlan)
        {
            PlanesDbContext db  = new PlanesDbContext();
            var             db1 = new FlightDbContext();

            ViewBag.PlaneID = new SelectList(db.Planes.Where(n => n.isAllotted == false), "PlaneID", "PlaneID");
            var flight = db1.Flights.FirstOrDefault(n => n.PlaneID == flightPlan.PlaneID);

            db1.SaveChanges();


            return(View());
        }
Beispiel #9
0
        public IActionResult SignUp(CheckCustomer customer)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var _customer = new Customer
            {
                email    = customer.Email,
                name     = customer.Name,
                password = customer.Password
            };

            _context.Add(_customer);
            _context.SaveChanges();
            return(View("~/Views/Login/Login.cshtml"));
        }
        //Get all relevant flights according to given time, from a given address.
        public List <Flight> GetFlightsFromExtServer(string address, DateTime time)
        {
            List <Flight> allExtFlights = new List <Flight>();
            //Making a string as a request for external server with a relative time.
            string fullAdd = address + "api/Flights/?relative_to=" + time.ToString("yyyy-MM-ddTHH:mm:ssZ");
            //Get json string from external server.
            string jsonText = GetJsonFromServer(fullAdd);
            //Handling difference between class prop. names and json prop. names.
            var deserialSettings = new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new SnakeCaseNamingStrategy()
                }
            };
            List <Flight> extSrvFlights;

            try
            {
                extSrvFlights = JsonConvert.DeserializeObject <List <Flight> >(jsonText,
                                                                               deserialSettings);
            } catch
            {
                return(allExtFlights);
            }
            //Update flight as external and add to all active flights list.
            foreach (Flight flight in extSrvFlights)
            {
                flight.IsExternal = true;
                allExtFlights.Add(flight);
                if (!_context.IdToServer.Any(e => e.FlightID.Equals(flight.FlightID)))
                {
                    var idToServer = new IDToServer();
                    idToServer.FlightID  = flight.FlightID;
                    idToServer.ServerURL = address;
                    _context.IdToServer.Add(idToServer);
                }
            }
            _context.SaveChanges();
            return(allExtFlights);
        }
Beispiel #11
0
        public IActionResult BookFlightDetail(int classId)
        {
            var flight      = _context.Flights.Find(Int32.Parse(_session.GetString("selectedFlight")));
            var customer    = _context.Customers.Find(Int32.Parse(_session.GetString("usernow")));
            var travelClass = _context.TravelClasses.Find(1);

            var reservation = new Reservation
            {
                FlightID      = flight,
                CustomerID    = customer,
                TravelClassID = travelClass,
                TotalPrice    = travelClass.ClassPrice + flight.price,
                Status        = "false"
            };

            _context.Reservations.Add(reservation);
            _context.SaveChanges();

            var viewModel = new ViewModel(_context, _session);

            return(View("~/Views/Main/Main.cshtml", viewModel));
        }
Beispiel #12
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
        public void TestMethod1()
        {
            //Arrage
            var options = new DbContextOptionsBuilder <FlightDbContext>().
                          UseInMemoryDatabase(databaseName: "dummy").Options;
            List <Segment> segs1 = new List <Segment>();

            segs1.Add(new Segment()
            {
                ID              = 1,
                Latitude        = 10,
                Longitude       = 10,
                TimespanSeconds = 100
            });
            List <Segment>  segs2 = new List <Segment>();
            List <Segment>  segs3 = new List <Segment>();
            List <Segment>  segs4 = new List <Segment>();
            InitialLocation init1 = new InitialLocation()
            {
                ID        = 1,
                Latitude  = 10,
                Longitude = 10,
                DateTime  = new System.DateTime()
            };
            InitialLocation init2 = new InitialLocation();
            InitialLocation init3 = new InitialLocation();
            InitialLocation init4 = new InitialLocation();
            FlightPlan      fp1   = new FlightPlan()
            {
                FlightID        = "AX100",
                CompanyName     = "OneLine",
                InitialLocation = init1,
                Passengers      = 123,
                Segments        = segs1
            };
            FlightPlan fp2 = new FlightPlan()
            {
                CompanyName     = "TwoLine",
                InitialLocation = init2,
                Passengers      = 456,
                Segments        = segs2
            };
            FlightPlan fp3 = new FlightPlan()
            {
                CompanyName     = "ThreeLine",
                InitialLocation = init3,
                Passengers      = 679,
                Segments        = segs3
            };
            FlightPlan fp4 = new FlightPlan()
            {
                CompanyName     = "FourLine",
                InitialLocation = init4,
                Passengers      = 84,
                Segments        = segs4
            };

            //Act
            using (var context = new FlightDbContext(options))
            {
                context.FlightPlan.Add(fp1);
                context.SaveChanges();
            }

            //Assert
            using (var context = new FlightDbContext(options))
            {
                var controller = new FlightPlanController(context);
                var flights    = controller.GetFlightPlan("AX100");
                var returnedID = (flights.Result.Value as FlightPlan).FlightID;
                Assert.AreEqual(fp1.FlightID, (flights.Result.Value as FlightPlan).FlightID);
            }
        }