Esempio n. 1
0
        // GET: Photos/Edit/5
        public ActionResult Edit(int id)
        {
            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Photo photo = db.Photos.Find(id);

            if (photo == null)
            {
                return(HttpNotFound());
            }


            PhotoUpdateViewModel photoUpdateViewModel = new PhotoUpdateViewModel
            {
                PhotoId      = photo.ID,
                PhotoName    = photo.PhotoName,
                PhotoUrl     = photo.PhotoUrl,
                Location     = photo.Location,
                Diaphragm    = photo.Diaphragm,
                ISO          = photo.ISO,
                LensId       = photo.LensModel.LensId,
                Albums       = photo.Albums,
                CameraId     = photo.CameraModel.CameraId,
                ShutterSpeed = photo.ShutterSpeed
                               //AlbumsNotAssignedToPhoto = GetAlbumsNotAssignedToPhototest(photo.ID)
            };

            SetPhotoInfo(photoUpdateViewModel.ISO, photoUpdateViewModel.ShutterSpeed, photoUpdateViewModel.Diaphragm);
            //GetAlbumsAssignedToPhoto(id);
            return(View(photoUpdateViewModel));
        }
Esempio n. 2
0
        public ActionResult Edit(PhotoUpdateViewModel photoUpdateViewModel)
        {
            if (ModelState.IsValid)
            {
                var photoToUpdate = db.Photos.Find(photoUpdateViewModel.PhotoId);
                if (TryUpdateModel(photoToUpdate))
                {
                    try
                    {
                        photoToUpdate.CameraModel = db.Cameras.Find(photoUpdateViewModel.CameraId);
                        photoToUpdate.LensModel   = db.Lenses.Find(photoUpdateViewModel.LensId);


                        //if (photoUpdateViewModel.AlbumsNotAssigned != null)
                        //{
                        //    var selectedAlbumsSet = new HashSet<int>(photoUpdateViewModel.AlbumsNotAssigned);
                        //    var photoAlbums = new HashSet<int>(photoToUpdate.Albums.Select(a => a.ID));
                        //    foreach (var album in db.Albums)
                        //    {
                        //        if (selectedAlbumsSet.Contains(album.ID))
                        //        {
                        //            if (!photoAlbums.Contains(album.ID))
                        //            {
                        //                photoToUpdate.Albums.Add(album);
                        //            }
                        //        }
                        //        else
                        //        {
                        //            if (!photoAlbums.Contains(album.ID))
                        //            {

                        //            }
                        //        }
                        //    }
                        //}

                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception)
                    {
                        ModelState.AddModelError("", "Unable to save");
                    }
                }

                //    db.Entry(photo).State = EntityState.Modified;
                //     db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(photoUpdateViewModel));
        }