Esempio n. 1
0
        public async Task<ActionResult> Post([FromBody] EditableFlightFields createFlightRequest)
        {
            var insertedId = await _flightService.Insert(createFlightRequest);
            var result = await _flightService.GetById(insertedId);

            var url = Url.Link("GetFlight", new {id = result.Id});

            return Created(url, result);
        }
Esempio n. 2
0
        public async Task<bool> Update(int id, EditableFlightFields updateFlightRequest)
        {
            var flightToUpdate = _mapper.Map<Flight>(updateFlightRequest);
            flightToUpdate.Id = id;
            var result = await UpdateFlight(flightToUpdate, updateFlightRequest);
            await _unitOfWork.SaveChangesAsync();

            return result;
        }
Esempio n. 3
0
        public async Task<ActionResult> Put(int id, [FromBody] EditableFlightFields updateFlightRequest)
        {
            var success = await _flightService.Update(id, updateFlightRequest);
            if (success)
            {
                return Ok();
            }

            return BadRequest();
        }
Esempio n. 4
0
        private async Task<bool> UpdateFlight(Flight flight, EditableFlightFields editableFlightFields)
        {
            var tickets =
                (await _unitOfWork.TicketRepository.GetAll()).Where(x => editableFlightFields.TicketIds.Contains(x.Id));
            flight.Tickets = tickets.ToList();
            var updateResult = await _unitOfWork.FlightRepository.Update(flight);
            await _unitOfWork.SaveChangesAsync();

            return updateResult;
        }
Esempio n. 5
0
        public async Task<int> Insert(EditableFlightFields createFlightRequest)
        {
            var entityToInsert = _mapper.Map<Flight>(createFlightRequest);
            
            await _unitOfWork.FlightRepository.Insert(entityToInsert);
            await _unitOfWork.SaveChangesAsync();

            await UpdateFlight(entityToInsert, createFlightRequest);

            return entityToInsert.Id;
        }