Esempio n. 1
0
        public async Task AddingFlightReturnsOkResult()
        {
            // Arrange
            Flight flight = new Flight()
            {
                FromAirportId = 1,
                ToAirportId   = 2,
                DepartureTime = new DateTimeOffset(
                    new DateTime(2019, 5, 20, 16, 0, 0),
                    new TimeSpan(3, 0, 0)
                    ),
                ArrivalTime = new DateTimeOffset(
                    new DateTime(2019, 5, 20, 17, 0, 0),
                    new TimeSpan(3, 0, 0)
                    ),
                AirplaneId = 1,
            };

            // Act
            AddResult addResult = await _flightService.AddAsync(flight);

            // Assert
            Assert.AreEqual(ResultTypes.Ok, addResult.ResultType);
        }
Esempio n. 2
0
        public async Task <bool> AddSync(FlightDto flight)
        {
            if (flight == null)
            {
                throw new ArgumentNullException(nameof(AddSync));
            }
            try
            {
                flight = await CompleteFlight(flight);
            }
            catch (ArgumentNullException)
            {
                throw;
            }

            return(await _flightService.AddAsync(flight));
        }
Esempio n. 3
0
        public async Task <IActionResult> AddAsync([FromBody] Flight flight)
        {
            BlFlight flightBl = _mapper.Map <BlFlight>(flight);

            AddResult addResult = await _flightService.AddAsync(flightBl);

            switch (addResult.ResultType)
            {
            case ResultTypes.Duplicate:
                return(BadRequest());

            case ResultTypes.InvalidData:
                return(BadRequest());

            case ResultTypes.NotFound:
                return(NotFound());
            }

            return(Ok(new { Id = addResult.ItemId }));
        }
 public Task <long> Post([FromBody] AddFlightRequestModel model)
 {
     return(_flightService.AddAsync(model));
 }