예제 #1
0
        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
                );
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }
예제 #4
0
        public ActionResult ScheduleFlight([FromQuery] int pilotId, [FromBody] ScheduleFlight schedule)
        {
            CrewService.ScheduleFlight(pilotId, schedule);

            return(Ok());
        }