public HttpResponseMessage Delete(int id) { string deleteFromFolder = System.Configuration.ConfigurationManager.AppSettings["ArtFileFolder"]; order_art_file orderArtFile = db.order_art_file.Find(id); try { if (orderArtFile == null) { if (File.Exists(HttpContext.Current.Server.MapPath("~/" + deleteFromFolder + "/" + orderArtFile.image_file))) { File.Delete(HttpContext.Current.Server.MapPath("~/" + deleteFromFolder + "/" + orderArtFile.image_file)); return(Request.CreateResponse(HttpStatusCode.OK, id)); } return(Request.CreateResponse(HttpStatusCode.NotFound, id)); } db.order_art_file.Remove(orderArtFile); db.SaveChanges(); if (File.Exists(HttpContext.Current.Server.MapPath("~/" + deleteFromFolder + "/" + orderArtFile.image_file))) { File.Delete(HttpContext.Current.Server.MapPath("~/" + deleteFromFolder + "/" + orderArtFile.image_file)); return(Request.CreateResponse(HttpStatusCode.OK, id)); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } return(Request.CreateResponse(HttpStatusCode.OK, id)); }
public HttpResponseMessage Put(order_art_file orderArtFile) { HttpResponseMessage result = null; if (orderArtFile.order_art_id < 0) // Insert { orderArtFile.order_art_id = 0; db.order_art_file.Add(orderArtFile); db.SaveChanges(); result = Request.CreateResponse(HttpStatusCode.OK, orderArtFile); } else // Must be an update { var artFile = db.order_art_file.Find(orderArtFile.order_art_id); if (artFile != null) { // artFile = orderArtFile; db.Entry(artFile).CurrentValues.SetValues(orderArtFile); db.SaveChanges(); result = Request.CreateResponse(HttpStatusCode.OK, orderArtFile); } } return(result); }
// POST: odata/OrderArtFile public async Task <IHttpActionResult> Post(order_art_file order_art_file) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.order_art_file.Add(order_art_file); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (order_art_fileExists(order_art_file.order_art_id)) { return(Conflict()); } else { throw; } } return(Created(order_art_file)); }
// DELETE: odata/OrderArtFile(5) public async Task <IHttpActionResult> Delete([FromODataUri] long key) { order_art_file order_art_file = await db.order_art_file.FindAsync(key); if (order_art_file == null) { return(NotFound()); } db.order_art_file.Remove(order_art_file); await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
// PUT: odata/OrderArtFile(5) public async Task <IHttpActionResult> Put([FromODataUri] long key, Delta <order_art_file> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } order_art_file order_art_file = await db.order_art_file.FindAsync(key); if (order_art_file == null) { return(NotFound()); } patch.Put(order_art_file); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!order_art_fileExists(key)) { return(NotFound()); } else { throw; } } return(Updated(order_art_file)); }