public IHttpActionResult PutPhoto(int id, Photo photo) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != photo.Id) { return BadRequest(); } db.Entry(photo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PhotoExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostPhoto(Photo photo) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Photos.Add(photo); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = photo.Id }, photo); }
public DTOphoto(Photo photo) { id = photo.Id; imageAsString = Convert.ToBase64String(photo.Image); }