public IHttpActionResult Post(File file) { var db = new FilesContext(); db.Files.Add(file); db.SaveChanges(); return(Created(file)); }
public IHttpActionResult Get([FromODataUri] int key) { var db = new FilesContext(); File file = db.Files.FirstOrDefault(c => c.FileId == key); if (file == null) { return(NotFound()); } return(Ok(file)); }
public IHttpActionResult Delete(int key) { var db = new FilesContext(); File original = db.Files.FirstOrDefault(c => c.FileId == key); if (original == null) { return(NotFound()); } db.Files.Remove(original); db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Patch(int key, Delta <File> patch) { var db = new FilesContext(); var file = db.Files.SingleOrDefault(c => c.FileId == key); if (file == null) { return(NotFound()); } patch.Patch(file); db.SaveChanges(); return(Updated(file)); }
public IQueryable <File> Get() { var db = new FilesContext(); return(db.Files); }