public async Task <ActionResult> GetSlip(Guid id) { if (id == Guid.Empty) { return(Ok((await _slipService.GetAsync()).Select(x => new SlipResponseEntity(x)))); } try { var test = await _slipService.GetAsync(id); return(Ok(new SlipResponseEntity(await _slipService.GetAsync(id)))); } catch (DocumentClientException ex) { if (ex.Message.Contains("Resource Not Found")) { return(BadRequest("Slip does not exist")); } throw; } catch { return(StatusCode(500)); } }
public async Task <ActionResult> GetSlipBoat(Guid id) { SlipEntity slip; try { slip = await _slipService.GetAsync(id); } catch (DocumentClientException ex) { if (ex.Message.Contains("Resource Not Found")) { return(BadRequest("Slip does not exist")); } throw; } catch { return(StatusCode(500)); } if (!slip.CurrentBoat.HasValue) { return(NotFound("The current slip has no boat")); } try { return(Ok(new BoatResponseEntity(await _boatService.GetAsync(slip.CurrentBoat.Value)))); } catch (DocumentClientException ex) { if (ex.Message.Contains("Resource Not Found")) { return(BadRequest("Slip does not exist")); } throw; } 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)); } }