public IHttpActionResult PuttblProImage(int id, tblProImage tblProImage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tblProImage.img_Id) { return(BadRequest()); } db.Entry(tblProImage).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tblProImageExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GettblProImage(int id) { tblProImage tblProImage = db.tblProImages.Find(id); if (tblProImage == null) { return(NotFound()); } return(Ok(tblProImage)); }
public IHttpActionResult DeletetblProImage(int id) { tblProImage tblProImage = db.tblProImages.Find(id); if (tblProImage == null) { return(NotFound()); } db.tblProImages.Remove(tblProImage); db.SaveChanges(); return(Ok(tblProImage)); }
// POST: api/tblProImages public string POST() { int counter = 0; // collecting files System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; string url = HttpContext.Current.Request.Url.AbsoluteUri; tblProImage funpic = new tblProImage(); var productId = db.products.Select(i => i).ToArray().LastOrDefault(); String Status = ""; for (int i = 0; i < files.Count; i++) { //get the posted files System.Web.HttpPostedFile file = files[i]; string fileName = new FileInfo(file.FileName).Name; if (file.ContentLength > 0) { Guid id = Guid.NewGuid(); string modifiedFileName = id.ToString() + "_" + fileName; byte[] imageb = new byte[file.ContentLength]; file.InputStream.Read(imageb, 0, file.ContentLength); funpic.img_Id = new Random().Next(); funpic.prodId = int.Parse(productId.prodId.ToString()); funpic.photo = imageb; db.tblProImages.Add(funpic); db.SaveChanges(); counter++; } else { return("error"); } } if (counter > 0) { return(Status); } return("Upload Failed"); }
/* This is used for file accessing and post a file to a database using a server */ public String POST() { int counter = 0; // collecting files System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; string url = HttpContext.Current.Request.Url.AbsoluteUri; tblProImage funpic = new tblProImage(); String Status = ""; for (int i = 0; i < files.Count; i++) { //get the posted files System.Web.HttpPostedFile file = files[i]; string fileName = new FileInfo(file.FileName).Name; if (file.ContentLength > 0) { Guid id = Guid.NewGuid(); string modifiedFileName = id.ToString() + "_" + fileName; byte[] imageb = new byte[file.ContentLength]; file.InputStream.Read(imageb, 0, file.ContentLength); funpic.Image = imageb; db.tblProImages.Add(funpic); db.SaveChanges(); counter++; } } if (counter > 0) { return(Status); } return("Upload Failed"); }