Exemplo n.º 1
0
 public ActionResult Edit(EditModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var user     = unitOfWork.UserRepository.GetByID(WebSecurity.CurrentUserId);
             var oldPhoto = unitOfWork.PhotoRepository.GetByID(model.ID);
             oldPhoto.Description = model.Description;
             oldPhoto.User        = user;
             if (oldPhoto.Effect != (int)model.Effect)
             {
                 PhotoService.ApplyEffect(model.Effect, model.Photo);
             }
             oldPhoto.Effect = (int)model.Effect;
             if ((model.Tags != null) && !String.IsNullOrWhiteSpace(model.Tags))
             {
                 SetTags(model.Tags, oldPhoto);
             }
             else
             {
                 unitOfWork.PhotoRepository.DeletePhotoTag(oldPhoto.ID);
             }
             unitOfWork.PhotoRepository.Update(oldPhoto);
             unitOfWork.Save();
             return(RedirectToAction("Details", "Photo", new { id = model.ID }));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Unable to edit photo. Try again, and if the problem persists, see your system administrator.");
     }
     return(View(model));
 }