Beispiel #1
0
        async public Task Update(FlightDto flight)
        {
            this.flights.Remove(this.flights.Single(f => f.Id == flight.Id));
            this.flights.Add(flight);

            await Task.CompletedTask;
        }
        public IActionResult CreateFlight([FromBody] FlightDto flight)
        {
            if (flight == null)
            {
                return(BadRequest());
            }

            // custom validation to make sure duplicate flights don't get created
            if (_flightInfoRepository.GetFlightByFlightNumber(flight.FlightNumber) != null)
            {
                _logger.LogCritical("Flight Already Exists");
                ModelState.AddModelError("Flight", "Flight Already Exists.");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var flightEntity = AutoMapper.Mapper.Map <Flight>(flight);

            _flightInfoRepository.AddFlight(flightEntity);

            if (!_flightInfoRepository.Save())
            {
                _logger.LogCritical($"An Error Occured While saving flight with flight number: {flightEntity.FlightNumber}");
                return(StatusCode(500, "An Error Occured While Handing Your Request."));
            }

            var newFlight = AutoMapper.Mapper.Map <FlightDto>(flightEntity);

            return(CreatedAtRoute("GetFlightByFlightNumber", new { flightNumber = newFlight.FlightNumber }, newFlight));
        }
Beispiel #3
0
        /// <summary>
        /// Notifing the clients that the flight event occured.
        /// </summary>
        /// <param name="args">The arrguments processed and send to the client about the event.</param>
        private void OnFlightMove(FlightMoveArgs args)
        {
            IHubContext _hub      = GlobalHost.ConnectionManager.GetHubContext <FlightsHub>();
            FlightDto   flightDto = GetFlightDto(args);

            _hub.Clients.All.FlightMove(flightDto);
        }
        public void Update_When_flightDto_is_null_Then_throw_NullBodyException()
        {
            FlightDto nullDto = null;
            int       id      = 1;

            Assert.Throws <NullBodyException>(() => _service.Update(id, nullDto));
        }
        public void Update_Bed()
        {
            //arange
            FlightsService fs = new FlightsService(unitOfWork, mapper, validator);

            var expected = new Flight
            {
                Id               = 1,
                FlightNumber     = "QW11",
                DeparturePoint   = "London",
                DepartureTime    = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00"),
                DestinationPoint = "Ukraine",
                ArrivalTime      = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00") + TimeSpan.FromHours(5)
            };

            var fightDtoToTest = new FlightDto
            {
                Id               = 1,
                FlightNumber     = "QW",
                DeparturePoint   = "London",
                DepartureTime    = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00"),
                DestinationPoint = "Ukraine",
                ArrivalTime      = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00") + TimeSpan.FromHours(5)
            };

            //act
            fs.Update(fightDtoToTest);

            var actual = (unitOfWork.Set <Flight>() as FakeRpository <Flight>).updatedItem;

            //assert

            Assert.IsNull(actual);
        }
Beispiel #6
0
        public async Task Create(FlightDto item)
        {
            var newItem = _mapper.Map <FlightDto, Flight>(item);
            await _unitOfWork.Repository <Flight>().Create(newItem);

            await _unitOfWork.SaveAsync();
        }
Beispiel #7
0
        public async Task <Flight> MapFlight(FlightDto value)
        {
            var list = await unitOfWork.Tickets.Get();

            var res = new List <Ticket>();

            foreach (var item in value.Tickets)
            {
                foreach (var tick in list)
                {
                    if (item.ID == tick.Id)
                    {
                        res.Add(tick);
                    }
                }
            }
            return(new Flight()
            {
                Id = value.ID,
                DeparturePoint = value.DeparturePoint,
                DepartureTime = value.DepartureTime,
                DestinationPoint = value.Destination,
                DestinationTime = value.DestinationTime,
                Number = value.Number,
                Tickets = res
            });
        }
Beispiel #8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,DepartureId,DestinationId,DateTime,StopNumber,SeatNumber")] FlightDto flight)
        {
            if (id != flight.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    flight = await _service.Update(flight);

                    await _signalrHub.Clients.All.SendAsync("LoadFlights");
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (await _service.Get(flight.Id) == null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(flight));
        }
Beispiel #9
0
        private FlightDto CollectRawData(FlightDataModel flightDataModel)
        {
            var flight = new FlightDto()
            {
                Number = flightDataModel.Number,
                From   = new CityDto()
                {
                    Id = flightDataModel.FromCity
                },
                To = new CityDto()
                {
                    Id = flightDataModel.ToCity
                },
                DepartureDate = flightDataModel.DepartureDate,
                ArrivalDate   = flightDataModel.ArrivalDate,
                Status        = _flightService.Status(flightDataModel.Status)
            };

            if (flightDataModel.Id != null)
            {
                flight.Id = flightDataModel.Id.Value;
            }

            var members = GetMemberCollection(flightDataModel);

            flight.AircrewMembers = members;

            return(flight);
        }
        async public Task <IActionResult> Edit(FlightEditViewModel flightEditViewModel)
        {
            this.EnforceCustomValidation(flightEditViewModel);

            if (this.ModelState.IsValid)
            {
                var flightDto = new FlightDto
                {
                    Id = flightEditViewModel.Id,
                    DepartureAirport = new AirportDto {
                        Id = flightEditViewModel.DepartureAirportId
                    },
                    DestinationAirport = new AirportDto {
                        Id = flightEditViewModel.DestinationAirportId
                    },
                    Aircraft = new AircraftDto {
                        Id = flightEditViewModel.AircraftId
                    }
                };

                await this.flightApiService.Update(flightDto);

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                await this.PopulateLists(flightEditViewModel);

                return(View(flightEditViewModel));
            }
        }
        public List <FlightDto> Execute()
        {
            var flights      = new List <FlightDto>();
            var destinations = Enum.GetValues(typeof(DestinationEnum));

            for (int i = 1, j = 1; i <= App.Default.FlightScheduledDays; i++)
            {
                foreach (var destination in destinations)
                {
                    if (Enum.IsDefined(typeof(ScheduledFlightDestinationEnum), destination.ToString()))
                    {
                        var flight = new FlightDto()
                        {
                            FlightNo  = j++,
                            Departure = ArrivalEnum.YUL,
                            Arrival   = (DestinationEnum)destination,
                            Day       = i
                        };

                        flights.Add(flight);
                    }
                }
            }

            return(flights);
        }
Beispiel #12
0
        /// <summary>
        /// Get set of available statuses to selected flight.
        /// </summary>
        /// <param name="flight">Flight identifier</param>
        /// <returns>Service result that contain result(available statuses) success/failure execution and error list of method.</returns>
        public ServiceResult <IEnumerable <string> > GetAvailableStatuses(FlightDto flight = null)
        {
            var result = new ServiceResult <IEnumerable <string> >()
            {
                Result = new List <string>()
                {
                    "Cancelled"
                },
                Status = AnswerStatus.Success
            };

            if (flight == null)
            {
                (result.Result as IList <string>).Add("Preparing");
                (result.Result as IList <string>).Add("In Air");
                (result.Result as IList <string>).Add("Landed");

                return(result);
            }
            else if (flight.DepartureDate > flight.ArrivalDate)
            {
                (result.Result as IList <string>).Clear();
                result.Errors.Add("Date error", "Departure date is later than arrival.");
                result.Status = AnswerStatus.Failure;
            }
            else if (flight.Status == FlightStatus.Preparing)
            {
                if (DateTime.Now.Date >= flight.DepartureDate.Date)
                {
                    (result.Result as IList <string>).Add("In Air");

                    if (DateTime.Now.Date >= flight.ArrivalDate.Date)
                    {
                        (result.Result as IList <string>).Add("Landed");
                    }
                }
            }
            else if (flight.Status == FlightStatus.InAir)
            {
                if (DateTime.Now.Date >= flight.ArrivalDate.Date)
                {
                    (result.Result as IList <string>).Add("Landed");
                }
            }
            else if (flight.Status == FlightStatus.Landed)
            {
                if (DateTime.Now.Date >= flight.ArrivalDate.Date)
                {
                    (result.Result as IList <string>).Remove("Cancelled");
                }
            }
            else
            {
                (result.Result as IList <string>).Clear();
                result.Errors.Add("Flight status error", "Invalid value of flight.");
                result.Status = AnswerStatus.Failure;
            }

            return(result);
        }
        public async Task <ActionResult <FlightDto> > PutFlightById(int id, [FromBody] FlightDto flightDto)
        {
            try
            {
                var oldFlight = await _flightRepository.GetFlightById(id);

                if (oldFlight == null)
                {
                    return(NotFound($"Couldn't find any flight with id: {id}"));
                }

                var newFlight = _mapper.Map(flightDto, oldFlight);
                _flightRepository.Update(newFlight);

                if (await _flightRepository.Save())

                {
                    return(NoContent());
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}"));
            }
            return(BadRequest());
        }
Beispiel #14
0
        public async Task Update(FlightDto item)
        {
            var updItem = _mapper.Map <FlightDto, Flight>(item);
            await _unitOfWork.Repository <Flight>().Update(updItem);

            await _unitOfWork.SaveAsync();
        }
Beispiel #15
0
        public async Task WhenAddCompleteFlightButWrongValuesTheGetArgumentNullException()
        {
            var flightDto = new FlightDto {
                DepartureAirportId = 1, DestinationAirportId = 3, AircraftId = 1
            };

            var result = await _business.AddSync(flightDto);
        }
Beispiel #16
0
        public void FlightUpdated(FlightDto flight)
        {
            var hubContext = GlobalHost.ConnectionManager.GetHubContext <FlightHub>();

            if (hubContext != null)
            {
                hubContext.Clients.All.flightUpdated(flight);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Extension method for mapping one model to another with assignment all properties
        /// </summary>
        /// <param name="model">The model to which to assign</param>
        /// <param name="other">The model to be assigned</param>
        /// <returns></returns>
        public static FlightDto ToEditWith(this FlightDto model, FlightDto other)
        {
            model.Description    = other.Description;
            model.Status         = other.Status;
            model.ArrivalPlace   = other.ArrivalPlace;
            model.DeparturePlace = other.DeparturePlace;
            model.Distance       = other.Distance;

            return(model);
        }
        public IActionResult Get(int id)
        {
            FlightDto flight = service.GetById(id);

            if (flight == null)
            {
                return(NotFound());
            }
            return(Ok(flight));
        }
Beispiel #19
0
        public async Task WhenAddCompleteFlightTheReturnsTrue()
        {
            var flightDto = new FlightDto {
                DepartureAirportId = 1, DestinationAirportId = 2, AircraftId = 1
            };
            var result = await _business.AddSync(flightDto);

            result.Should().Be(true);
            _flightServiceMock.Verify(f => f.AddAsync(flightDto), Times.Once);
        }
        public async Task Update_WhenFlightNull_ThenReturnExeption()
        {
            var Flights = new IFakeRepository <Flight>();
            var context = new IFakeUnitOfFactory();

            FlightDto FlightDto = null;

            FlightService service        = new FlightService(context);
            FlightDto     FlightDtoSaved = await service.Update(FlightDto);
        }
Beispiel #21
0
        public async Task <IActionResult> Get(int id)
        {
            FlightDto flight = await service.GetById(id);

            if (flight == null)
            {
                return(NotFound());
            }
            return(Ok(flight));
        }
Beispiel #22
0
        public FlightDto Update(Guid id, FlightDto flightDto)
        {
            var flight = mapper.Map <FlightDto, Flight>(flightDto);

            flight.Id      = id;
            flight.Tickets = db.TicketRepository.GetAll().Where(i => flightDto.TicketsId.Contains(i.Id)).ToList();

            db.FlightRepository.Update(flight);
            return(mapper.Map <Flight, FlightDto>(flight));
        }
        public async Task <IActionResult> Put(int id, [FromBody] FlightDto entity)
        {
            var result = await _flightsSrvice.UpdateAsync(entity, id);

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

            return(Ok(result));
        }
        public async Task <IActionResult> Post([FromBody] FlightDto entity)
        {
            var result = await _flightsSrvice.AddAsync(entity);

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

            return(Ok(result));
        }
Beispiel #25
0
        /// <summary>
        /// Convert the instance into data transfer objet.
        /// </summary>
        /// <returns>FlightDto instance associated with this FlightModel.</returns>
        public FlightDto ConvertToFlightDto()
        {
            FlightDto flightDto = new FlightDto();

            flightDto.ID          = ID;
            flightDto.IsDeparture = IsDeparture;
            flightDto.IsFinish    = IsFinish;
            flightDto.Time        = Time;
            flightDto.FlightName  = FlightName;
            return(flightDto);
        }
Beispiel #26
0
 public async Task Post([FromServices] IFlightBusiness business, [FromBody] FlightDto flight)
 {
     try
     {
         await business.AddSync(flight);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
     }
 }
Beispiel #27
0
        public FlightDto Create(FlightDto flightDto)
        {
            var flight = mapper.Map <FlightDto, Flight>(flightDto);

            flight.Id      = Guid.NewGuid();
            flight.Tickets = db.TicketRepository.GetAll().Where(i => flightDto.TicketsId.Contains(i.Id)).ToList();

            db.FlightRepository.Create(flight);
            db.SaveChanges();

            return(mapper.Map <Flight, FlightDto>(flight));
        }
Beispiel #28
0
 public IActionResult Put(int id, [FromBody] FlightDto value)
 {
     if (ModelState.IsValid)
     {
         var item = service.Update(value);
         if (item != null)
         {
             return(Ok(item));
         }
     }
     return(BadRequest());
 }
        public FlightEntity toEntity(FlightDto flightDto)
        {
            FlightEntity flight = new FlightEntity();

            flight.FlightId       = flightDto.FlightId;
            flight.TimeDeparture  = flightDto.TimeDeparture;
            flight.TimeArrival    = flightDto.TimeArrival;
            flight.AimArrivalId   = flightDto.AimArrivalId;
            flight.AimDepartureId = flightDto.AimDepartureId;
            flight.PlaneId        = flightDto.PlaneId;
            return(flight);
        }
Beispiel #30
0
        internal FlightDto HateoasMainLinksFlight(FlightDto flight)
        {
            var flightDto = flight;

            flightDto.Links.Add(UrlLink("all", "GetFlights", null));
            flightDto.Links.Add(UrlLink("_self", "GetFlightById", new { id = flightDto.Id }));
            flightDto.Links.Add(UrlLink("_next", "GetFlightById", new { id = flightDto.Id + 1 }));
            flightDto.Links.Add(UrlLink("_Manufacturer = boeing", "GetFlightsByManufacturer", new { Manufacturer = "boeing" }));
            flightDto.Links.Add(UrlLink("_model = 182", "GetFlightsByModel", new { Model = "182" }));

            return(flightDto);
        }