예제 #1
0
 public ActionResult Edit(int id, EditPhotosViewModel model)
 {
     try
     {
         string FileName = UploadFile(model.File, model.ImageUrl);
         if (ModelState.IsValid)
         {
             var Projects = projectRepository.Find(model.ProjectId);
             if (Projects == null)
             {
                 ModelState.AddModelError("", "please review the input fileds");
                 return(View(GetAllProjects()));
             }
             var photo = new Photo
             {
                 Image   = FileName,
                 Project = Projects
             };
             PhotoRepository.Update(model.Id, photo);
             return(RedirectToAction("index"));
         }
         return(View(model));
     }
     catch
     {
         return(View(model));
     }
 }
예제 #2
0
        public ActionResult Edit(int id)
        {
            var image = PhotoRepository.Find(id);

            if (image == null)
            {
                return(NotFound());
            }

            var projectid = image.Project == null ? image.Project.ID = 0 : image.Project.ID;
            var model     = new EditPhotosViewModel
            {
                Id        = image.ID,
                ImageUrl  = image.Image,
                ProjectId = projectid,
                Projects  = FillProjects()
            };

            return(View(model));
        }
        public ActionResult Show()
        {
            var currentUserId = User.Identity.GetUserId();
            var userAlbums    = GetUserAlbums(currentUserId);

            var albumsToShow = new List <ShowAlbumViewModel>();

            albumsToShow = userAlbums.Select(album => new ShowAlbumViewModel
            {
                Id             = album.Id,
                Name           = album.Name,
                NumberOfPhotos = album.Photos.Count,
                FirstPhotoId   = album.Photos.FirstOrDefault()?.Id,
                IsEditable     = true
            })
                           .ToList();

            var model = new EditPhotosViewModel()
            {
                Albums = albumsToShow
            };

            return(View(model));
        }