public async Task <ActionResult> DeleteSlip(Guid id) { if (id == null || id == Guid.Empty) { return(BadRequest()); } SlipEntity slip; try { slip = await _slipService.GetAsync(id); } catch (DocumentClientException ex) { if (ex.Message.Contains("Resource Not Found")) { return(BadRequest("Slip does not exist")); } return(StatusCode(500)); } if (slip.CurrentBoat.HasValue) { try { BoatEntity boat = await _boatService.GetAsync(slip.CurrentBoat.Value); boat.AtSea = true; await _boatService.UpsertAsync(boat); } catch (DocumentClientException ex) { if (!ex.Message.Contains("Resource Not Found")) { return(StatusCode(500)); } } } try { await _slipService.DeleteAsync(slip.Id); return(Ok()); } catch { return(StatusCode(500)); } }
public async Task <ActionResult> DeleteBoat(Guid id) { if (id == null || id == Guid.Empty) { return(BadRequest()); } BoatEntity boat; try { boat = await _boatService.GetAsync(id); } catch (DocumentClientException ex) { if (ex.Message.Contains("Resource Not Found")) { return(BadRequest("Boat does not exist")); } return(StatusCode(500)); } //Check and see if we have a slip that we need to remove the boat from SlipEntity slip = (await _slipService.GetAsync()).SingleOrDefault(x => x.CurrentBoat == id); try { await _boatService.DeleteAsync(boat.Id); if (slip != null) { slip.CurrentBoat = null; slip.ArrivalDate = null; await _slipService.UpsertAsync(slip); } return(Ok()); } catch { return(StatusCode(500)); } }