public async Task <IActionResult> UpdateTravel(int id, [FromBody] UpdateTravelRequest request) { try { var travel = await _travelRepository.FindById(id); if (request.Name != null) { travel.Name = request.Name; } if (request.TravelToId != 0) { travel.TravelTo = await _officeRepository.FindById(request.TravelToId); } if (request.TravelFromId != 0) { travel.TravelFrom = await _officeRepository.FindById(request.TravelFromId); } if (request.StartTime != null) { travel.StartTime = request.StartTime; } if (request.EndTime != null) { travel.EndTime = request.EndTime; } if (request.Cost <= 0) { travel.Cost = request.Cost; } if (request.Hotels != null) { foreach (var hotel in request.Hotels) { await _hotelRepository.Create(hotel); } var hotels = travel.Hotels; travel.Hotels = request.Hotels; foreach (var hotel in hotels) { await _hotelRepository.Delete(hotel); } } if (request.Transports != null) { foreach (var transport in request.Transports) { await _transportRepository.Create(transport); } var transports = travel.Transports; travel.Transports = request.Transports; foreach (var transport in transports) { await _transportRepository.Delete(transport); } } await _travelRepository.Update(travel); return(Ok(await _travelRepository.FindById(id))); } catch (ArgumentException e) { return(Conflict(e.Message)); } catch (InvalidOperationException) { return(NotFound()); } }
private void DeleteEntry() { transportRepository.Delete(transport); PublishEvent(new TransportDeletedMessage(this)); }