public async Task CreateAsync_ShouldSuccessfullyAddToDatabase()
        {
            // Arrange
            var context          = ApplicationDbContextInMemoryFactory.InitializeContext();
            var flightRepository = new EfDeletableEntityRepository <Flight>(context);

            var service    = new FlightsService(flightRepository);
            var inputModel = new FlightInputModel();

            inputModel.FlightNumber      = "FlightNumber";
            inputModel.AvailableSeats    = 20;
            inputModel.PricePerPerson    = 50;
            inputModel.ReservationType   = ReservationType.Flight;
            inputModel.StartPointId      = 1;
            inputModel.StartPointAirPort = "StartAirPort";
            inputModel.EndPointId        = 2;
            inputModel.EndPointAirPort   = "EndAirPort";
            inputModel.DepartureDateTime = new DateTime(2020, 03, 03, 13, 00, 00);
            inputModel.FlightTime        = new TimeSpan(30, 30, 00);
            inputModel.CompanyId         = 1;

            var expectedResult = 1;

            // Act
            await service.CreateAsync(inputModel);

            var actualResult = flightRepository.All().Count();

            // Assert
            Assert.True(expectedResult == actualResult);
        }
        public async Task Create(FlightInputModel model)
        {
            Flight flight = model.To <Flight>();

            flight.Origin      = GetFlightLocation(model.Origin);
            flight.Destination = GetFlightLocation(model.Destination);
            await context.Flights.AddAsync(flight);

            await context.SaveChangesAsync();
        }
示例#3
0
        public IActionResult Create()
        {
            this.ViewData["CompanyId"]    = new SelectList(this.flightCompaniesService.GetAll(), "Id", "Name");
            this.ViewData["EndPointId"]   = new SelectList(this.destinationsService.GetAll(), "Id", "Town");
            this.ViewData["StartPointId"] = new SelectList(this.destinationsService.GetAll(), "Id", "Town");

            var inputModel = new FlightInputModel();

            return(this.View(inputModel));
        }
示例#4
0
 public IActionResult RegisterFlight(FlightInputModel flightInputModel)
 {
     if (this.ModelState.IsValid)
     {
         this.flightService.RegisterInboundFlight(flightInputModel);
         this.flightService.RegisterOutboundFlight(flightInputModel);
         return(this.RedirectToAction("RegisterAircraft"));
     }
     else
     {
         return(this.View(flightInputModel));
     }
 }
示例#5
0
        public async Task <IActionResult> Create(FlightInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                this.ViewData["CompanyId"]    = new SelectList(this.flightCompaniesService.GetAll(), "Id", "Name", inputModel.CompanyId);
                this.ViewData["EndPointId"]   = new SelectList(this.destinationsService.GetAll(), "Id", "Town", inputModel.EndPointId);
                this.ViewData["StartPointId"] = new SelectList(this.destinationsService.GetAll(), "Id", "Town", inputModel.StartPointId);
                return(this.View(inputModel));
            }

            await this.flightsService.CreateAsync(inputModel);

            return(this.RedirectToAction(nameof(this.Index)));
        }
        public async Task Update(FlightInputModel model, int id)
        {
            Flight flight = context.Flights.Find(id);

            flight.Origin            = GetFlightLocation(model.Origin);
            flight.Destination       = GetFlightLocation(model.Destination);
            flight.AvailableBussines = model.AvailableBussines;
            flight.AvailableEconomy  = model.AvailableEconomy;
            flight.LandingTime       = model.LandingTime;
            flight.PilotName         = model.PilotName;
            flight.PlaneNumber       = model.PlaneNumber;
            flight.PlaneType         = model.PlaneType;
            flight.TakeOffTime       = model.TakeOffTime;

            context.Flights.Update(flight);
            await context.SaveChangesAsync();
        }
        public void RegisterInboundFlight(FlightInputModel inboundFlightInputModel)
        {
            string[] splitFlightNumbers =
                inboundFlightInputModel
                .FlightNumber
                .Split("/", StringSplitOptions.RemoveEmptyEntries);

            string inboundFlightNumber = splitFlightNumbers[0];
            var    newInboundFlight    = new InboundFlight
            {
                FlightNumber = inboundFlightNumber,
                Origin       = inboundFlightInputModel.Origin,
                STA          = inboundFlightInputModel.STA,
            };

            this.dbContext.InboundFlights.Add(newInboundFlight);
            this.dbContext.SaveChanges();
        }
示例#8
0
        public async Task CreateAsync(FlightInputModel inputModel)
        {
            var flight = new Flight
            {
                FlightNumber      = inputModel.FlightNumber,
                PricePerPerson    = inputModel.PricePerPerson,
                CompanyId         = inputModel.CompanyId,
                DepartureDateTime = inputModel.DepartureDateTime,
                FlightTime        = inputModel.FlightTime,
                StartPointId      = inputModel.StartPointId,
                StartPointAirPort = inputModel.StartPointAirPort,
                EndPointId        = inputModel.EndPointId,
                EndPointAirPort   = inputModel.EndPointAirPort,
                AvailableSeats    = inputModel.AvailableSeats,
                ReservationType   = inputModel.ReservationType,
            };

            await this.flightsRepository.AddAsync(flight);

            await this.flightsRepository.SaveChangesAsync();
        }
        public void RegisterOutboundFlight(FlightInputModel outboundFlightInputModel)
        {
            string[] splitFlightNumbers =
                outboundFlightInputModel
                .FlightNumber
                .Split("/", StringSplitOptions.RemoveEmptyEntries);

            string outboundFlightNumber = splitFlightNumbers[1];

            var newOutboundFlight = new OutboundFlight
            {
                FlightNumber    = outboundFlightNumber,
                HandlingStation = outboundFlightInputModel.HandlingStation,
                BookedPAX       = outboundFlightInputModel.BookedPax,
                STD             = outboundFlightInputModel.STD,
                Destination     = outboundFlightInputModel.Destination
            };

            this.dbContext.OutboundFlights.Add(newOutboundFlight);
            this.dbContext.SaveChanges();
        }
        public async Task <IActionResult> Create(FlightInputModel model)
        {
            if (model.LandingTime < DateTime.Now)
            {
                ModelState.AddModelError(nameof(FlightInputModel.LandingTime), "Landing time must be in the future!");
            }
            if (model.TakeOffTime < DateTime.Now)
            {
                ModelState.AddModelError(nameof(FlightInputModel.LandingTime), "Take off time must be in the future!");
            }
            if (model.LandingTime < model.TakeOffTime)
            {
                ModelState.AddModelError(nameof(FlightInputModel.TakeOffTime), "Take off time must be before landing time!");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await flightService.Create(model);

            return(Redirect("/Flight/All"));
        }
        public async Task <IActionResult> Edit(FlightInputModel model, int id)
        {
            await flightService.Update(model, id);

            return(Redirect("/Flight/All"));
        }
        public IActionResult Edit(int id)
        {
            FlightInputModel model = flightService.GetById <FlightInputModel>(id);

            return(View(model));
        }