// id to Guid // PUT api/PhotoAnnotation/1 public HttpResponseMessage PutPhotoAnnotation(Guid id, PhotoAnnotation photoAnnotation) { if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.Values.SelectMany(v => v.Errors))); } try { // Check that all constrains are met PhotoAnnotationService.CheckConstrains(photoAnnotation, true); Photo photo = db.Photos.Where(p => p.PhotoId == id).Include(p => p.Event.EventOption).SingleOrDefault(); bool successed = false; if (photo != null) { if (photo.Status == (byte)PhotoStatus.Submitted) { successed = PhotoAnnotationService.ReannotatePhoto(photo, photoAnnotation, db); } else { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, string.Format("The photo status is {0}, so it is invalid for this request.", Enum.GetName(typeof(PhotoStatus), photo.Status)))); } } else { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "Photo not found.")); } if (successed) { db.SaveChanges(); // Restore the photo back to the event's folder if its status is back to Unselected if (photo.Status == (byte)PhotoStatus.Unselected) { PhotoAnnotationService.RestorePhoto(photo.Folder, Constants.STR_PROCESSED, photo.Filename); } } } catch (DbUpdateConcurrencyException ex) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, ex.ToString())); } catch (DbEntityValidationException ex) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.EntityValidationErrors)); } catch (ArgumentNullException ex) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NoContent, ex.Message)); } catch (Exception ex) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.ToString())); } return(Request.CreateResponse(HttpStatusCode.OK)); }
private HttpResponseMessage UpdateClaimingPhotoStatus(int id, string filename, PhotoStatus status) { Event ev = EventsController.GetEvent(id, CurrentUser.Id, Request, db); try { if (status == PhotoStatus.Unclaimed) { PhotoAnnotationService.MovePhoto(ev.EventFolder, Constants.STR_UNCLAIMED, filename); } else if (status == PhotoStatus.Unselected) { PhotoAnnotationService.RestorePhoto(ev.EventFolder, Constants.STR_UNCLAIMED, filename); } return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, ex.ToString())); } }