Example #1
0
        public IActionResult Add(FlightViewModel model, string returnUrtl = null)
        {
            var flight = new Flight {
                Id                 = model.Id,
                Airplane           = _dbContext.Airplanes.Find(model.AirplaneId),
                AviaCompany        = _dbContext.AviaCompanies.Find(model.AviaCompanyId),
                HomeAirport        = _dbContext.Airports.Find(model.HomeAirportId),
                DestinationAirport = _dbContext.Airports.Find(model.DestinationAirportId),
                Departure          = model.Departure,
                Arrival            = model.Arrival
            };
            var curFlights = _dbContext.Flights.ToList().OrderByDescending(item => item.Id);

            if (curFlights == null)
            {
                flight.Id = 1;
            }
            else
            {
                flight.Id = curFlights.First().Id + 1;
            }
            _dbContext.Flights.Add(flight);
            _dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #2
0
        public FlightRecordPage(Flight flight)
        {
            viewModel = new FlightViewModel(flight);

            this.BindingContext = viewModel;

            InitializeComponent();

            this.Title = StringResources.recordingFlight.Replace("%", flight.Info.Number);

            Button button = this.FindByName <Button> ("StartStopButton");

            if (flight.Info.IsPending)
            {
                button.Text = StringResources.startRecording;
            }
            else if (flight.Info.IsRecording)
            {
                button.Text = StringResources.stopRecording;
            }
            else if (flight.Info.IsStopped)
            {
                button.IsVisible = false;
            }
        }
        public JsonResult GetFlightById(int FlightId)
        {
            Flight          flight = _flightrepos.GetFlightByID(FlightId);
            FlightViewModel model  = new FlightViewModel();

            if (flight.FlightId == FlightId)
            {
                model.FlightId             = flight.FlightId;
                model.FlightDeparture      = flight.FlightDeparture;
                model.FlightArrival        = flight.FlightArrival;
                model.DepartureAirportName = flight.DepartureAirport.Name;
                model.ArrivalAirportName   = flight.ArrivalAirport.Name;
                model.DepartureId          = flight.DepartureAirport.Id;
                model.ArrivalId            = flight.ArrivalAirport.Id;
                model.AirlineName          = flight.FlightAirline.Name;
                model.AirlineId            = flight.FlightAirline.Id;
                model.AircraftName         = flight.Aircraft.Name;
                model.AircraftId           = flight.Aircraft.Id;
            }
            string value = JsonConvert.SerializeObject(model, Formatting.Indented, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(Json(value));
        }
Example #4
0
        public async Task <IActionResult> Index()
        {
            FlightViewModel fvm = new FlightViewModel();

            fvm.RealAltitude    = 0;
            fvm.RealWeight      = 18000;
            fvm.Icing           = "No";
            fvm.Rain            = "No";
            fvm.Snow            = "No";
            fvm.RunwayDirection = 0;
            fvm.WindDirection   = 0;
            fvm.WindSpeed       = 0;
            fvm.OutsideAirTemp  = 0;

            fvm.FlapData = await _context.Flap5Data.ToListAsync();

            fvm.Flap10Data = await _context.Flap10Data.ToListAsync();

            fvm.Flap15Data = await _context.Flap15Data.ToListAsync();

            fvm.Landing5Data = await _context.Landing5Data.ToListAsync();

            fvm.Landing10Data = await _context.Landing10Data.ToListAsync();

            return(View(fvm));
        }
Example #5
0
        public ActionResult ConfirmYourTicket(FlightViewModel viewModel)
        {
            try
            {
                if (!string.IsNullOrEmpty(viewModel.BlockingNumber))
                {
                    var flightReservation = db.FLIGHT_RESERVATION.Where(f => f.BlockingNumber.Contains(viewModel.BlockingNumber)).FirstOrDefault();
                    if (flightReservation != null)
                    {
                        flightReservation.Status          = "CONFIRMED";
                        db.Entry(flightReservation).State = EntityState.Modified;

                        db.SaveChanges();
                        var message = new Message()
                        {
                            MessageCategory = (int)MessageCategory.SUCCESS, MessageText = "Ticket was confirmed"
                        };
                        SetMessage(message);
                    }
                    else
                    {
                        var message = new Message()
                        {
                            MessageCategory = (int)MessageCategory.ERROR, MessageText = "No ticket was reserved under this number"
                        };
                        SetMessage(message);
                    }
                }

                return(View(viewModel));
            }
            catch (Exception ex) { throw ex; }
        }
Example #6
0
        public ActionResult Edit(FlightViewModel flightinfo)
        {
            if (ModelState.IsValid)
            {
                //insert gar
                //converting view model to entity model
                tblFlight dbFlight = new tblFlight();
                dbFlight.ID         = flightinfo.ID;
                dbFlight.FlightNo   = flightinfo.FlightNo;
                dbFlight.Detail     = flightinfo.Detail;
                dbFlight.FlightName = flightinfo.FlightName;

                if (flightinfo.FileFlightLogo != null)
                {
                    var fileName = dbFlight.FlightNo + ".jpg";
                    var path     = Server.MapPath("~/FlightImages");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    flightinfo.FileFlightLogo.SaveAs(path + "/" + fileName);
                    dbFlight.FlightLogo = fileName;
                }

                db.Entry(dbFlight).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(flightinfo));
        }
Example #7
0
        public async Task <IActionResult> Edit(string id, FlightViewModel flightViewModel)
        {
            if (id != flightViewModel.Id)
            {
                return(this.NotFound());
            }

            if (!this.ModelState.IsValid)
            {
                this.ViewData["CompanyId"]    = new SelectList(this.flightCompaniesService.GetAll(), "Id", "Name", flightViewModel.CompanyId);
                this.ViewData["EndPointId"]   = new SelectList(this.destinationsService.GetAll(), "Id", "Continent", flightViewModel.EndPointId);
                this.ViewData["StartPointId"] = new SelectList(this.destinationsService.GetAll(), "Id", "Continent", flightViewModel.StartPointId);

                return(this.View(flightViewModel));
            }

            try
            {
                await this.flightsService.EditAsync(id, flightViewModel);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!this.FlightExists(flightViewModel.Id))
                {
                    return(this.NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(this.RedirectToAction(nameof(this.Index)));
        }
Example #8
0
        public async Task <IActionResult> Create(FlightViewModel view)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                if (view.ImageFile != null && view.ImageFile.Length > 0)
                {
                    var guid = Guid.NewGuid().ToString();
                    var file = $"{guid}.jpg";

                    path = Path.Combine(
                        Directory.GetCurrentDirectory(),
                        "wwwroot\\images\\Flights",
                        file);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await view.ImageFile.CopyToAsync(stream);
                    }

                    path = $"~/images/Flights/{file}";
                }

                var flight = this.ToFlight(view, path);

                flight.User = await _userHelper.GetUserByEmailAsync(this.User.Identity.Name);

                await _flightRepository.CreateAsync(flight);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(view));
        }
Example #9
0
        public async Task <ActionResult> Create(FlightViewModel model)
        {
            var airportsList = await GetAirportModelList();

            if (!ModelState.IsValid)
            {
                model.AirportsList = new List <SelectListItem>();
                foreach (var airportModel in airportsList)
                {
                    model.AirportsList.Add(new SelectListItem {
                        Text = airportModel.Name, Value = airportModel.AirportId.ToString()
                    });
                }

                return(View(model));
            }
            var flightModel = new FlightModel
            {
                Name               = model.Name,
                DepartureAirport   = airportsList.FirstOrDefault(airport => airport.AirportId.Equals(model.DepartureAirportId)),
                DestinationAirport = airportsList.FirstOrDefault(airport => airport.AirportId.Equals(model.DestinationAirportId))
            };

            ExecutePostAction(JsonConvert.SerializeObject(flightModel), Constants.CreateFlightActionName);
            return(RedirectToAction("Index", "Flight/Index"));
        }
 /// <summary>
 /// Used to pull the most recent flight information from the database. this keeps all buttons the proper color
 /// </summary>
 /// <param name="sqlStatement"></param>
 /// <param name="TheSelectedFlight"></param>
 private void updateButtonColor(string sqlStatement, FlightViewModel TheSelectedFlight)
 {
     try
     {
         MainWindowViewModel mwvm = ((MainWindowViewModel)Application.Current.MainWindow.DataContext);
         //Pulls in the sql statement that was passed
         ds = db.ExecuteSQLStatement(sqlStatement, ref iRet);
         assignPassengers(iRet, ds);
         //Sets TheGrid to the appropriate flight so we can look through and load the correct colors. If it is not airbus, then boeing
         Grid TheGrid = TheSelectedFlight.AircraftType == "Airbus A380" ? AirbusA380 : Boeing767;
         foreach (Button btn in TheGrid.Children.OfType <Button>())
         {
             SolidColorBrush theColorWeDoneGonnaUse = null;
             if (mwvm.AvailablePassengers.Any(x => Convert.ToInt16(x.SSeat) == Convert.ToInt16(btn.Content)))
             {
                 theColorWeDoneGonnaUse = Brushes.Red;
             }
             else
             {
                 theColorWeDoneGonnaUse = Brushes.Blue;
             }
             btn.Background = theColorWeDoneGonnaUse;
         }
     }
     catch (Exception ex)
     {
         throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
     }
 }
        public IActionResult EditFlight(FlightViewModel model, string flightId)
        {
            if (!ModelState.IsValid)
            {
                return(View("EditFlight", CreateDefaultEditFlightViewModel(flightId)));
            }

            if (model.NewFlightDepartureAirport == model.NewFlightArrivalAirport)
            {
                ModelState.AddModelError("NewFlightArrivalAirport", "Departure and destination airports can't be the same !");
                return(View("EditFlight", CreateDefaultEditFlightViewModel(flightId)));
            }

            try
            {
                _flightsManager.EditFlight(Guid.Parse(flightId), model.NewFlightDepartureAirport, model.NewFlightArrivalAirport, model.NewFuelConsumptionLitersPerKm, model.NewFuelConsumptionTakeoffEffortInLiters);
            }
            catch (Exception)
            {
                ModelState.AddModelError("NewFlightArrivalAirport", "An error occured");
                return(View("EditFlight", CreateDefaultEditFlightViewModel(flightId)));
            }

            return(RedirectToAction(nameof(Index)));
        }
Example #12
0
        public IActionResult Edit(int id, [Bind("FlightId,AirCraftType,FromLocation,ToLocation,DepartureTime,ArrivalTime")] FlightViewModel flightViewModel)
        {
            if (id != flightViewModel.FlightId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _iFlightRepository.UpdateFlight(id);
                    //await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FlightViewModelExists(flightViewModel.FlightId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(flightViewModel));
        }
Example #13
0
        public void ReturnViewWithModelWithCorrectProperties_WhenThereIsAModelWithThePassedId()
        {
            // Arrange
            var flightServiceMock  = new Mock <IFlightService>();
            var airlineServiceMock = new Mock <IAirlineService>();
            var flightModel        = new FlightModel()
            {
                Id          = Guid.NewGuid(),
                Title       = "BA123",
                Price       = 50,
                Duration    = TimeSpan.Parse("01:10:00"),
                TravelClass = TravelClass.First
            };

            var flightViewModel = new FlightViewModel(flightModel);

            flightServiceMock.Setup(m => m.GetById(flightModel.Id)).Returns(flightModel);

            var flightController = new FlightController(flightServiceMock.Object, airlineServiceMock.Object);

            // Act & Assert
            flightController
            .WithCallTo(b => b.Details(flightModel.Id))
            .ShouldRenderDefaultView()
            .WithModel <FlightViewModel>(viewModel =>
            {
                Assert.AreEqual(flightModel.Title, viewModel.Title);
                Assert.AreEqual(flightModel.Price, viewModel.Price);
                Assert.AreEqual(flightModel.Duration, viewModel.Duration);
                Assert.AreEqual(flightModel.TravelClass, viewModel.TravelClass);
            });
        }
Example #14
0
        public static FlightViewModel FindFlight(string idFlight)
        {
            var entity = new QUANLIXEContext();
            var flight = entity.Flight.FirstOrDefault(f => f.IdFlight == idFlight);

            if (flight != null)
            {
                var    route = entity.Route.FirstOrDefault(r => r.IdRoute == flight.IdRoute);
                string dep   = entity.Place.Where(p => p.IdPlace == route.IdDepacture).Select(p => p.Placename).FirstOrDefault();
                string des   = entity.Place.Where(p => p.IdPlace == route.IdDestination).Select(p => p.Placename).FirstOrDefault();
                List <ViewModel.Ticket.ClassViewModel> classes = new List <ViewModel.Ticket.ClassViewModel>();
                try
                {
                    var query = (
                        from d in entity.DeatailClass
                        join c in entity.Class
                        on d.IdType equals c.IdType
                        where d.IdFlight == idFlight
                        select new ViewModel.Ticket.ClassViewModel(d.IdType, c.TypeName, d.Price, d.StartingRow, d.EndingRow)
                        );
                    classes = query.ToList();
                }
                catch (Exception)
                {
                    entity.Dispose();
                }

                FlightViewModel res = new FlightViewModel(idFlight, flight.Starting, flight.Ending, flight.FlightDetail, flight.IdRoute, dep, des, flight.IdPlane, classes);
                return(res);
            }
            entity.Dispose();
            return(null);
        }
Example #15
0
        public IActionResult Edit(int id, [Bind("Id,Name,DeparatureId,DestinationId")] FlightViewModel flightvm)
        {
            if (id != flightvm.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _flightService.Save(flightvm.Flight);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FlightExists(flightvm.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            flightvm.AirportsList = _airportService.GetAll();
            return(View(flightvm));
        }
Example #16
0
        public IActionResult Edit(int id)
        {
            var         model       = new FlightViewModel();
            FlightModel flightModel = model.Load(id);

            return(View(flightModel));
        }
        public async Task <IActionResult> Create(ReservationInputModel model)
        {
            int ecenomyTickets           = model.Passengers.Count(p => p.TicketType == TicketType.Economy);
            int bussinesTickets          = model.Passengers.Count(p => p.TicketType == TicketType.Bussines);
            int availableEconomyTickets  = flightService.AvailableEconomyTickets(model.FlightId);
            int availableBusinessTickets = flightService.AvailableBussinesTickets(model.FlightId);

            if (availableEconomyTickets < ecenomyTickets)
            {
                ModelState.AddModelError(string.Empty, $"There are only {availableEconomyTickets} economy tickets left.");
            }
            if (availableBusinessTickets < bussinesTickets)
            {
                ModelState.AddModelError(string.Empty, $"There are only {availableBusinessTickets} business tickets left.");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            await reservationService.Create(model);

            await flightService.UpdateAvailableTickets(model.FlightId, ecenomyTickets, bussinesTickets);

            FlightViewModel flight = flightService.GetById <FlightViewModel>(model.FlightId);

            await SendConfirmationEmailsToPassengers(model.Passengers, flight);
            await SendEmailToClient(model.Client.Email, flight, model.Passengers);

            return(Redirect("/"));
        }
Example #18
0
        public void ReturnViewWithEmptyModel_WhenThereNoModelWithThePassedId()
        {
            // Arrange
            var flightServiceMock  = new Mock <IFlightService>();
            var airlineServiceMock = new Mock <IAirlineService>();

            var flightViewModel = new FlightViewModel();

            Guid?flightId  = Guid.NewGuid();
            Guid?airlineId = Guid.NewGuid();

            flightServiceMock.Setup(m => m.GetById(flightId.Value)).Returns((FlightModel)null);
            //airlineServiceMock.Setup(m => m.GetById(airlineId.Value)).Returns((AirlineModel)null);

            var flightController = new FlightController(flightServiceMock.Object, airlineServiceMock.Object);

            // Act & Assert
            flightController
            .WithCallTo(b => b.Details(flightId.Value))
            .ShouldRenderDefaultView()
            .WithModel <FlightViewModel>(viewModel =>
            {
                Assert.AreEqual(null, viewModel.Title);
                Assert.AreEqual(0, viewModel.Price);
                Assert.AreEqual(TimeSpan.Zero, viewModel.Duration);
                Assert.AreEqual((TravelClass)0, viewModel.TravelClass);
            });
        }
Example #19
0
        public async Task <IActionResult> Filter(FilterViewModel filterViewModel)
        {
            List <FlightViewModel> viewModel = new List <FlightViewModel>();

            if (filterViewModel.MaxStops == 1)
            {
                var flights = await _context.Flights
                              .Where(f => f.Arrival.Date == filterViewModel.Arrival.Date && f.Departure.Date == filterViewModel.Departure.Date)
                              .Where(f => f.ArrivalLocation.Destination.DestinationName == filterViewModel.Destination)
                              .Where(f => f.DepartureLocation.Destination.DestinationName == filterViewModel.Origin)
                              .Include(f => f.DepartureLocation)
                              .Include(f => f.DepartureLocation.Destination)
                              .Include(f => f.ArrivalLocation)
                              .Include(f => f.ArrivalLocation.Destination)
                              .ToListAsync();

                foreach (var flight in flights)
                {
                    FlightViewModel flightViewModel = new FlightViewModel {
                        Arrival   = flight.Arrival,
                        Departure = flight.Departure,
                        Price     = flight.Price
                    };

                    flightViewModel.Flights.Add(flight);

                    viewModel.Add(flightViewModel);
                }
            }

            return(View(viewModel));
        }
Example #20
0
        // GET: Flights/Details/5
        public ActionResult Details(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Flight flight = db.Flights.FirstOrDefault(p => p.PublicId == id);

            if (flight == null)
            {
                return(HttpNotFound());
            }

            FlightViewModel model = new FlightViewModel()
            {
                PublicId          = flight.PublicId,
                AirRouteId        = flight.AirRouteId,
                AirRoute          = flight.AirRoute,
                NumberOfFreeSeats = flight.NumberOfFreeSeats,
                ArrivalDate       = flight.ArrivalDate,
                DepartureDate     = flight.DepartureDate,
                Price             = flight.Price
            };

            return(View(model));
        }
Example #21
0
        public IActionResult UpdateFlight(int Id, [FromBody] FlightViewModel flightModel)
        {
            if (flightModel == null)
            {
                return(BadRequest());
            }

            // check if model state which include the flight business rules(FlightViewModelValidators) are all valid
            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }

            var aFlight = _flightService.GetFlightById(Id);

            if (aFlight == null)
            {
                return(NotFound());
            }

            aFlight    = flightModel.ToEntity();
            aFlight.Id = Id;
            bool saved = _flightService.UpdateExistingFlight(aFlight);

            if (!saved)
            {
                _logger.LogCritical("Could not update flight details.");
                return(StatusCode(500, $"Updating flight {Id} failed on save operation."));
            }
            return(NoContent());
        }
Example #22
0
        public IActionResult DeleteFlight(FlightViewModel flight)
        {
            var parent = _service.GetFlightById(flight.Id).AircraftId;

            _service.DeleteFlight(flight.Id);

            return(RedirectToAction("ListFlight", new { parentId = parent }));
        }
Example #23
0
        public FlightViewModel UpdateConfirmViewModel(FlightViewModel model)
        {
            var temp = (from c in dao.Schedules where c.ID == model.ID select c).FirstOrDefault();

            temp.Confirmed = !temp.Confirmed;
            dao.SaveChanges();
            return(GetFlightViewModel(temp.ID));
        }
Example #24
0
        public ActionResult Create()
        {
            FlightViewModel model = new FlightViewModel();

            ViewBag.Planes = db.Planes.ToArray();

            return(View(model));
        }
Example #25
0
        public IActionResult GetFlights()
        {
            var tableModel = new DataTablesAjaxRequestModel(Request);
            var model      = new FlightViewModel();
            var data       = model.GetFlights(tableModel);

            return(Json(data));
        }
Example #26
0
        public FlightAddPage()
        {
            viewModel = new FlightViewModel();

            this.BindingContext = viewModel;

            InitializeComponent();
        }
Example #27
0
 public FlightView()
 {
     InitializeComponent();
     this.viewModel = new FlightViewModel();
     //if a property changes in viewModel- activate Vm_PropertyChanged.
     viewModel.PropertyChanged += Vm_PropertyChanged;
     DataContext = viewModel;
 }
Example #28
0
        public ActionResult Details(Guid?id)
        {
            FlightModel flight = this.flightService.GetById(id);

            FlightViewModel viewModel = new FlightViewModel(flight);

            return(this.View(viewModel));
        }
        public ActionResult Index()
        {
            FlightViewModel model = new FlightViewModel();

            model.stationVM = GetStationDetails();
            model.programVM = GetProgramDetails();
            return(View(model));
        }
Example #30
0
        public ActionResult Save(FlightViewModel model)
        {
            Flights FlyingAircraft = CreateFlight(model);

            DistanceCalculatorMiddle.AddFlight(FlyingAircraft);

            return(View("ComputedDistance"));
        }