public IHttpActionResult UpdateImage(Image image) { var userId = this.User.Identity.GetUserId(); var imageFromDb = this.data .Images .All() .Where(i => i.ImageID == image.ImageID) .FirstOrDefault(); if (imageFromDb == null) { return BadRequest("The image does not exist"); } if(userId != imageFromDb.UserID) { return BadRequest("You are not authorized to change this image"); } imageFromDb.Name = image.Name; imageFromDb.Url = image.Url; imageFromDb.Description = image.Description; this.data.SaveChanges(); return Ok(); }
public IHttpActionResult Upload(Image image) { if (!ModelState.IsValid) { return BadRequest(ModelState); } this.data.Images.Add(image); this.data.SaveChanges(); return Ok(); }