Пример #1
0
 public ActionResult Edit(int id)
 {
     var photo = unitOfWork.PhotoRepository.GetByID(id);
     if (photo.UserID != WebSecurity.CurrentUserId) return RedirectToAction("Http403", "Error");
     var model = new EditModel
     {
         ID = photo.ID,
         Description = photo.Description,
         Photo = photo.Filename,
         Effect = (Effect)photo.Effect
     };
     var tags = photo.Tags.Select(item => item.Name).ToList();
     model.Tags = String.Join(", ", tags);
     return View(model);
 }
Пример #2
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);
 }