/// <summary> /// Schedules a flight for take off by finding the availabilitiy of the runways and calculating the time for takeoff /// </summary> /// <param name="flight"> The flight to be taken off</param> /// <param name="buffer"> Buffer time between different operations</param> /// <param name="weatherOffset"> Delay due to weather conditions </param> /// <returns> Take off info </returns> public async Task <TakeOff> ScheduleTakeOff(Flight flight, int buffer, int weatherOffset) { var updatedFlightInfo = await _airportRepository.GetFlightById(flight.Id); if (updatedFlightInfo == null) { throw new IndexOutOfRangeException($"Flight id : {flight.Id} is not a valid flight id."); } var availableRunway = await FindAvailableRunway(); var timeRequired = CalculateDuration(updatedFlightInfo.LandingDuration, buffer, weatherOffset); TakeOff takeOff = new TakeOff { FlightId = updatedFlightInfo.Id, IsFinished = false, RunwayId = availableRunway.Id, StartTime = availableRunway.NextAvailableTime, }; await _airportRepository.AddTakeOff(takeOff); //updating the runway by adding the time required for take off to NextAvailable time. availableRunway.NextAvailableTime = availableRunway.NextAvailableTime.Add(timeRequired); availableRunway.TakeOffs.Add(takeOff); await _airportRepository.UpdateRunway(availableRunway); await _airportRepository.SaveChangesAsync(); return(takeOff); }
public void Create() { selected = new TakeOff() { CrewId = new Crew(), FlightNum = new Flight(), PlaneId = new Plane() }; gr.Children.Clear(); DatePicker dDate = new DatePicker(); dDate.Header = "Departure Date"; dDate.MinWidth = 150; //dDate.Date = selected.Date; TextBox Crew = new TextBox(); Crew.Header = "Crew"; //Crew.Text = selected.CrewId.Id.ToString(); //model.Width = 300; TextBox Flight = new TextBox(); Flight.Header = "Flight"; //Flight.Text = selected.FlightNum.FlightNum.ToString(); TextBox Plane = new TextBox(); Plane.Header = "Plane"; //Plane.Text = selected.PlaneId.Id.ToString(); Button submit = new Button { Name = "submit", Content = "Submit Create", Width = 150 }; submit.Margin = new Thickness(0, 10, 0, 10); submit.Click += async(sender, e) => await SubmitCreate(dDate.Date.Date, Convert.ToInt32(Crew.Text), Convert.ToInt32(Plane.Text), Convert.ToInt32(Flight.Text)); ColumnDefinition cd = new ColumnDefinition(); RowDefinition rd0 = new RowDefinition(); RowDefinition rd1 = new RowDefinition(); RowDefinition rd2 = new RowDefinition(); RowDefinition rd3 = new RowDefinition(); RowDefinition rd4 = new RowDefinition(); gr.Children.Add(dDate); gr.Children.Add(Crew); gr.Children.Add(Flight); gr.Children.Add(Plane); gr.Children.Add(submit); Grid.SetRow(dDate, 0); Grid.SetRow(Crew, 1); Grid.SetRow(Flight, 2); Grid.SetRow(Plane, 3); Grid.SetRow(submit, 4); }
public async Task Delete(int id) { TakeOff temp = await db.TakeOff.FindAsync(id); if (temp != null) { db.TakeOff.Remove(temp); await db.SaveChangesAsync(); } }
public void Delete(int id) { TakeOff temp = db.TakeOff.Find(id); if (temp != null) { db.TakeOff.Remove(temp); db.SaveChanges(); } }
public void Delete(int id) { TakeOff temp = takeoffs.FirstOrDefault(t => t.Id == id); if (temp != null) { takeoffs.Remove(temp); SaveChanges(); } }
public void Update(int id, TakeOff item) { TakeOff temp = takeoffs.FirstOrDefault(t => t.Id == id); if (temp != null) { temp.Id = item.Id; temp.FlightNum = item.FlightNum; temp.Date = item.Date; temp.CrewId = item.CrewId; temp.PlaneId = item.PlaneId; SaveChanges(); } }
public void CreateTakeOff(TakeOffDTO item) { TakeOff temp = Mapper.Map <TakeOffDTO, TakeOff>(item); temp.CrewId = IunitOfWork.CrewRepository.Get(item.CrewId); temp.FlightNum = IunitOfWork.FlightRepository.Get(item.FlightNum); temp.PlaneId = IunitOfWork.PlaneRepository.Get(item.PlaneId); if (temp.CrewId != null && temp.PlaneId != null && temp.FlightNum != null) { IunitOfWork.TakeOffRepository.Create(temp); } }
public async Task UpdateTakeOff(int id, InputTakeOffDTO item) { TakeOff temp = Mapper.Map <InputTakeOffDTO, TakeOff>(item); temp.CrewId = await IunitOfWork.CrewRepository.Get(item.CrewId); temp.FlightNum = await IunitOfWork.FlightRepository.Get(item.FlightNum); temp.PlaneId = await IunitOfWork.PlaneRepository.Get(item.PlaneId); if (temp.CrewId != null && temp.PlaneId != null && temp.FlightNum != null) { await IunitOfWork.TakeOffRepository.Update(id, temp); } else { throw new Exception(); } }
public void Update(int id, TakeOff item) { TakeOff temp = takeoffs.FirstOrDefault(t => t.Id == id); if (temp != null) { //temp.Id = item.Id; temp.FlightNum = item.FlightNum; temp.Date = item.Date; temp.CrewId = item.CrewId; temp.PlaneId = item.PlaneId; db.SaveChanges(); } //TakeOff temp = db.TakeOff.Find(id); //if (temp != null) //{ // db.TakeOff.Remove(temp); // db.TakeOff.Add(item); //} }
public async Task Update(int id, TakeOff item) { TakeOff temp = await db.TakeOff.FindAsync(id); if (temp != null) { //temp.Id = item.Id; temp.FlightNum = item.FlightNum; temp.Date = item.Date; temp.CrewId = item.CrewId; temp.PlaneId = item.PlaneId; db.TakeOff.Update(temp); await db.SaveChangesAsync(); } //TakeOff temp = db.TakeOff.Find(id); //if (temp != null) //{ // db.TakeOff.Remove(temp); // db.TakeOff.Add(item); //} }
public void Update(int id, TakeOff item) { takeOff = item; }
public void Create(TakeOff item) { takeoffs.Add(item); SaveChanges(); }
public void Create(TakeOff item) { db.Add(item); db.SaveChanges(); }
public void Seed() { //Pilot.RemoveRange(Pilot); //Stewardess.RemoveRange(Stewardess); //Ticket.RemoveRange(Ticket); //Flight.RemoveRange(Flight); //PLane.RemoveRange(PLane); //PlaneType.RemoveRange(PlaneType); //this.SaveChanges(); /////////////////////////////////////////////////////////////////////////////////////////////////////// Pilot p1 = new Pilot() { Name = "Skyler", Surname = "Bunker", Birth = new DateTime(1998, 6, 28), Experience = new TimeSpan(0, 1, 3, 4) }; Pilot p2 = new Pilot() { Name = "Garry", Surname = "Murdoch", Birth = new DateTime(1998, 6, 28), Experience = new TimeSpan(0, 1, 3, 4) }; Pilot p3 = new Pilot() { Name = "Dennisson", Surname = "Keegan", Birth = new DateTime(1998, 6, 28), Experience = new TimeSpan(0, 1, 3, 4) }; if (!Pilot.Any()) { Pilot.AddRange(p1, p2, p3); } ///////////////////////////////////////////////////////////////////////////////////////////////////////// Stewardess s1 = new Stewardess { Name = "Zelda", Surname = "Gouse", Birth = new DateTime(1998, 6, 28), }; Stewardess s2 = new Stewardess { Name = "Anna", Surname = "Rosser", Birth = new DateTime(1998, 6, 28), }; Stewardess s3 = new Stewardess { Name = "Bobina", Surname = "Vaccaro", Birth = new DateTime(1998, 6, 28), }; Stewardess s4 = new Stewardess { Name = "Sharron", Surname = "Herwitz", Birth = new DateTime(1998, 6, 28), }; Stewardess s5 = new Stewardess { Name = "Isa", Surname = "Dorwart", Birth = new DateTime(1998, 6, 28), }; if (!Stewardess.Any()) { Stewardess.AddRange(s1, s2, s3, s4, s5); } /////////////////////////////////////////////////////////////////////////////////////////////////////// Crew cr1 = new Crew() { PilotId = p1, StewardessIds = new List <Stewardess>() { s1, s2 } }; Crew cr2 = new Crew() { PilotId = p2, StewardessIds = new List <Stewardess>() { s3, s5 } }; Crew cr3 = new Crew() { PilotId = p3, StewardessIds = new List <Stewardess>() { s4 } }; if (!Crew.Any()) { Crew.AddRange(cr1, cr2, cr3); } ; //////////////////////////////////////////////////////////////////////////////////////////////////////////// Flight f1 = new Flight() { DeperturePlace = "Kyiv", DepartureTime = new DateTime(1998, 6, 28), ArrivalPlace = "London", ArrivalTime = new DateTime(1998, 6, 28) }; Flight f2 = new Flight() { DeperturePlace = "Kyiv", DepartureTime = new DateTime(1998, 6, 28), ArrivalPlace = "Manchester", ArrivalTime = new DateTime(1998, 6, 28), }; Flight f3 = new Flight() { DeperturePlace = "Kyiv", DepartureTime = new DateTime(1998, 6, 28), ArrivalPlace = "Frankfurt", ArrivalTime = new DateTime(1998, 6, 28), }; if (!Flight.Any()) { Flight.AddRange(f1, f2, f3); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// Ticket t1 = new Ticket() { Price = 500, FlightNum = f1 }; Ticket t2 = new Ticket() { Price = 800, FlightNum = f2 }; Ticket t3 = new Ticket() { Price = 500, FlightNum = f1 }; Ticket t4 = new Ticket() { Price = 800, FlightNum = f2 }; Ticket t5 = new Ticket() { Price = 600, FlightNum = f3 }; Ticket t6 = new Ticket() { Price = 600, FlightNum = f3 }; Ticket t7 = new Ticket() { Price = 1000, FlightNum = f2 }; if (!Ticket.Any()) { Ticket.AddRange(t1, t2, t3, t4, t5, t6, t7); } ////////////////////////////////////////////////////////////////////////////////////////////////////////// PlaneType pt1 = new PlaneType() { Model = "Airbus A310", Places = 183, CarryCapacity = 164000 }; PlaneType pt2 = new PlaneType() { Model = "Boeing", Places = 235, CarryCapacity = 242000 }; if (!PlaneType.Any()) { PlaneType.AddRange(pt1, pt2); } ////////////////////////////////////////////////////////////////////////////////////////////////////////// Plane pl1 = new Plane() { Name = "Skyshark", Made = new DateTime(1998, 6, 28), Exploitation = new TimeSpan(0, 1, 3, 4), Type = pt1 }; Plane pl2 = new Plane() { Name = "Dragon", Made = new DateTime(1998, 6, 28), Exploitation = new TimeSpan(0, 1, 3, 4), Type = pt2 }; Plane pl3 = new Plane() { Name = "Airking", Made = new DateTime(1998, 6, 28), Exploitation = new TimeSpan(0, 1, 3, 4), Type = pt2 }; Plane pl4 = new Plane() { Name = "Kondor", Made = new DateTime(1998, 6, 28), Exploitation = new TimeSpan(0, 1, 3, 4), Type = pt2 }; if (!PLane.Any()) { PLane.AddRange(pl1, pl2, pl3, pl4); } ////////////////////////////////////////////////////////////////////////////////////////////////////////// TakeOff to1 = new TakeOff() { FlightNum = f1, CrewId = cr3, PlaneId = pl2, Date = new DateTime(1998, 6, 28) }; TakeOff to2 = new TakeOff() { FlightNum = f2, CrewId = cr2, PlaneId = pl4, Date = new DateTime(1998, 6, 28) }; TakeOff to3 = new TakeOff() { FlightNum = f1, CrewId = cr1, PlaneId = pl3, Date = new DateTime(1998, 6, 28) }; if (!TakeOff.Any()) { TakeOff.AddRange(to1, to2, to3); } }
public async Task Create(TakeOff item) { await db.AddAsync(item); await db.SaveChangesAsync(); }
public void Create(TakeOff item) { takeOff = item; }
/// <summary> /// Updates a particluar take off info /// </summary> /// <param name="takeOff"> take off info </param> /// <returns></returns> public async Task UpdateTakeOff(TakeOff takeOff) { var takeOffEntity = _mapper.Map <Entities.TakeOff>(takeOff); _airportDbContext.TakeOffs.Update(takeOffEntity); }
/// <summary> /// Add new take off info /// </summary> /// <param name="takeOff"> Take off info </param> /// <returns></returns> public async Task AddTakeOff(TakeOff takeOff) { var takeOffEntity = _mapper.Map <Entities.TakeOff>(takeOff); await this._airportDbContext.TakeOffs.AddAsync(takeOffEntity); }
public void TakeOffCreate() { TakeOffService takeOffService = new TakeOffService(unitOfWork); TakeOffDTO takeOffDTO = new TakeOffDTO() { Date = new DateTime(1, 2, 3), FlightNum = new FlightDTO() { DeperturePlace = "testing", ArrivalPlace = "test", DepartureTime = new DateTime(1, 4, 3), ArrivalTime = new DateTime(1, 3, 4) }, PlaneId = new PlaneDTO() { Name = "test", Made = new DateTime(1, 2, 3), Exploitation = new TimeSpan(0, 1, 2), Type = new PlaneTypeDTO() { Model = "test", CarryCapacity = 12, Places = 15 } }, CrewId = new CrewDTO() { PilotId = new PilotDTO() { Name = "pilotCreateTest", Surname = "pilotCreateTest", Birth = new DateTime(1990, 1, 1), Experience = new TimeSpan(1, 2, 3) }, StewardessIds = new StewardessDTO[] { new StewardessDTO() { Name = "stewCreateTest1", Surname = "stewCreateTest1", Birth = new DateTime(1990, 1, 1) }, new StewardessDTO() { Name = "stewCreateTest2", Surname = "stewCreateTest2", Birth = new DateTime(1990, 1, 1) } } } }; takeOffService.CreateTakeOff(takeOffDTO); TakeOff takeOff = fakeTakeOffRepository.Get(1); Assert.AreEqual(takeOff.Date, takeOffDTO.Date); Assert.AreEqual(takeOff.PlaneId.Name, takeOffDTO.PlaneId.Name); Assert.AreEqual(takeOff.CrewId.PilotId.Name, takeOffDTO.CrewId.PilotId.Name); }