public IHttpActionResult GetShipboard(int id) { Shipboard shipboard = db.Shipboards.Find(id); if (shipboard == null) { return(NotFound()); } return(Ok(shipboard)); }
public IHttpActionResult DeleteShipboard(int id) { Shipboard shipboard = db.Shipboards.Find(id); if (shipboard == null) { return(NotFound()); } db.Shipboards.Remove(shipboard); db.SaveChanges(); return(Ok(shipboard)); }
public IHttpActionResult PutShipboard(int id, int CruiseID = -1, int ObserverID = -1, int ObserverNo = -1, string ShipDuty = "") { Shipboard shipboard = db.Shipboards.Find(id); if (shipboard == null) { return(NotFound()); } shipboard.CruiseID = CruiseID != -1 ? CruiseID : shipboard.CruiseID; shipboard.ObserverID = ObserverID != -1 ? ObserverID : shipboard.ObserverID; shipboard.ObserverNo = ObserverNo != -1 ? ObserverNo : shipboard.ObserverNo; shipboard.ShipDuty = ShipDuty != "" ? ShipDuty : shipboard.ShipDuty; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != shipboard.ID) { return(BadRequest()); } db.Entry(shipboard).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ShipboardExists(id)) { return(NotFound()); } else { throw; } } return(Ok(shipboard)); }
public IHttpActionResult PostShipboard(int CruiseID, int ObserverID, int ObserverNo, string ShipDuty) { Shipboard shipboard = new Shipboard(); shipboard.CruiseID = CruiseID; shipboard.ObserverID = ObserverID; shipboard.ObserverNo = ObserverNo; shipboard.ShipDuty = ShipDuty; shipboard.InsertTimeStamp = DateTime.Now; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Shipboards.Add(shipboard); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = shipboard.ID }, shipboard)); }