public IHttpActionResult GetPointsofInterest(string id) { PointsofInterest pointsofInterest = db.PointsofInterests.Find(id); if (pointsofInterest == null) { return(NotFound()); } return(Ok(pointsofInterest)); }
public IHttpActionResult DeletePointsofInterest(string id) { PointsofInterest pointsofInterest = db.PointsofInterests.Find(id); if (pointsofInterest == null) { return(NotFound()); } db.PointsofInterests.Remove(pointsofInterest); db.SaveChanges(); return(Ok(pointsofInterest)); }
public IHttpActionResult PutPointsofInterest(string id, PointsofInterest pointsofInterest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pointsofInterest.PointofInterestID) { return(BadRequest()); } if (pointsofInterest.Name == null || pointsofInterest.Name.Trim() == "") { return(BadRequest("Invalid Name")); } pointsofInterest.lastUpdate = DateTime.Now; db.Entry(pointsofInterest).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PointsofInterestExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostPointsofInterest(PointsofInterest pointsofInterest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (pointsofInterest.Name == null || pointsofInterest.Name.Trim() == "") { return(BadRequest("Invalid Name")); } pointsofInterest.PointofInterestID = Guid.NewGuid().ToString(); pointsofInterest.createDate = DateTime.Now; pointsofInterest.createUserId = ""; //update after security is in place pointsofInterest.lastUpdate = DateTime.Now; db.PointsofInterests.Add(pointsofInterest); try { db.SaveChanges(); } catch (DbUpdateException) { if (PointsofInterestExists(pointsofInterest.PointofInterestID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = pointsofInterest.PointofInterestID }, pointsofInterest)); }