public void ScheduleFlight(int PilotId, ScheduleFlight scheduleFlight) { var crew = GetCrewData(); if (crew.First(x => x.Id == PilotId).ScheduledFlight == null) { var schedule = new List <ScheduleFlight> { scheduleFlight }; crew.First(x => x.Id == PilotId).ScheduledFlight = schedule; } else { var schedule = crew.First(x => x.Id == PilotId).ScheduledFlight; schedule.Add(scheduleFlight); crew.First(x => x.Id == PilotId).ScheduledFlight = schedule; } using var outputStream = File.OpenWrite(JsonCrew); JsonSerializer.Serialize <IEnumerable <Crew> >( new Utf8JsonWriter(outputStream, new JsonWriterOptions { SkipValidation = true, Indented = true }), crew ); }
public async Task <ActionResult> Edit([Bind(Include = "Id,FlightCode,DepartureDate,ArrivalDate,DepartureCity,ArrivalCity,SeatsFirstclass,SeatsEconomyclass")] ScheduleFlight flight) { if (ModelState.IsValid) { db.Entry(flight).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(flight)); }
public void SchedulesANewFlightTest() { // Arrange var crewMember = this.crewService.GetCrewData().FirstOrDefault(); var countFlightsBeforeSchedule = crewMember.ScheduledFlight != null?crewMember.ScheduledFlight.Count() : 0; var newFlight = new ScheduleFlight { DepartureDateTime = DateTime.Now.AddHours(-1), ReturnDateTime = DateTime.Now.AddHours(1), }; // Act this.crewService.ScheduleFlight(crewMember.Id, newFlight); var crewMemberUpdated = this.crewService.GetCrewData().FirstOrDefault(); var countFlightsAfterSchedule = crewMemberUpdated.ScheduledFlight.Count(); // Assert Assert.True(countFlightsBeforeSchedule < countFlightsAfterSchedule); }
public ActionResult ScheduleFlight([FromQuery] int pilotId, [FromBody] ScheduleFlight schedule) { CrewService.ScheduleFlight(pilotId, schedule); return(Ok()); }