public HttpResponseMessage SelectPhoto(int id, string filename)
        {
            Event ev    = EventsController.GetEvent(id, CurrentUser.Id, Request, db);
            Photo photo = GetPhotoFromId(id)
                          .Where(p => p.Filename.Equals(filename, StringComparison.InvariantCultureIgnoreCase)).SingleOrDefault();

            if (photo == null)
            {
                string folder    = ev.EventFolder.EndsWith(Path.DirectorySeparatorChar.ToString()) ? ev.EventFolder : (ev.EventFolder + Path.DirectorySeparatorChar);
                string thumbnail = File.Exists(folder + Constants.STR_THUMB + "/" + filename) ? (ev.EventVirtualPath + "/" + Constants.STR_THUMB + "/" + filename) : "";
                photo = new Photo {
                    PhotoId   = Guid.NewGuid(),
                    Folder    = ev.EventFolder,
                    Filename  = filename,
                    Image     = ev.EventVirtualPath + '/' + filename,
                    Thumbnail = thumbnail,
                    Created   = File.GetCreationTime(folder + filename),
                    Event     = ev
                };
                ev.Photos.Add(photo);
            }
            else if (photo.Status == (byte)PhotoStatus.Selected)
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict, string.Format("The {0} photo is editing by someone else.", filename)));
            }

            photo.Status = (byte)PhotoStatus.Selected;

            try {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex) {
                LogManager.Error(EventPhotosController._logger, ex.ToString());
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, ex.ToString()));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, EventPhotosService.GenerateTDO(ev, photo)));
        }
        private HttpResponseMessage UpdatePhotoStatus(int id, string filename, PhotoStatus condStatus, PhotoStatus status, string error = "")
        {
            Event ev = EventsController.GetEvent(id, CurrentUser.Id, Request, db);
            HttpResponseMessage response = null;

            try {
                response = DoUpdatePhotoStatus(id, filename, condStatus, status, error);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    db.SaveChanges();
                }
            }
            catch (DbUpdateConcurrencyException ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                this.GenerateException(HttpStatusCode.NotFound, ex.Message);
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                this.GenerateException(HttpStatusCode.InternalServerError, ex.Message);
            }

            return(response);
        }
        private HttpResponseMessage UpdateEventStatus(int id, EventStatus status)
        {
            Event ev = EventsController.GetEvent(id, CurrentUser.Id, Request, db);

            try {
                ev.EventStatus = (byte)status;
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex) {
                string validationErrors = GetValidationErrors(ex.EntityValidationErrors);
                this.GenerateException(HttpStatusCode.NotFound, validationErrors, _logger);
            }
            catch (DbUpdateConcurrencyException ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                this.GenerateException(HttpStatusCode.NotFound, ex.Message);
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                this.GenerateException(HttpStatusCode.InternalServerError, ex.Message);
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }