public void Edit(PhotoEditDTO photoInfo) { var photo = context.Photos.Find(photoInfo.PhotoId); if (photo.UserId != photoInfo.UserId) { throw new UnauthorizedException(); } photo.Name = photoInfo.Title; photo.Description = photoInfo.Description; context.SaveChanges(); }
public IHttpActionResult EditPhotoInfo(int id, [FromBody] PhotoEditViewModel model) { if (model == null) { throw new ArgumentNullException(); } var photoInfo = new PhotoEditDTO() { Title = model.Title, Description = model.Description, UserId = User.Identity.GetUserId(), PhotoId = id }; Service.Edit(photoInfo); return(Ok()); }