Пример #1
0
        public ViewResult EditPicture(int pictureId)
        {
            var picture = unitOfWork.PictureRepository.GetById(pictureId);
            var editPictureModel = new EditPictureModel()
                                       {
                                           Camera = picture.Camera,
                                           Description = picture.Description,
                                           Flash = picture.Flash,
                                           Diaphragm = picture.Diaphragm,
                                           FocalDistance = picture.FocalDistance,
                                           ISO = picture.ISO,
                                           PictureId = picture.PictureId,
                                           RecordingDate = picture.RecordingDate,
                                           RecordingPlace = picture.RecordingPlace,
                                           ShutterSpeed = picture.ShutterSpeed,
                                           AlbomList = new List<PictureAlbomModel>()
                                       };
            var albomList = unitOfWork.AlbomRepository.GetAlbomByUser(User.Identity.Name);

            foreach (var albom in albomList)
            {
                editPictureModel.AlbomList.Add(new PictureAlbomModel()
                                                   {
                                                       AlbomId = albom.AlbomId,
                                                       AlbomName = albom.AlbomName,
                                                       HasCurrentPicture = albom.Pictures.Contains(picture)
                                                   });
            }

            return View(editPictureModel);
        }
Пример #2
0
        public ViewResult EditPicture(EditPictureModel model)
        {
            if (ModelState.IsValid)
            {
                var picture = new Picture
                                  {
                                      PictureId = model.PictureId,
                                      Camera = model.Camera,
                                      Description = model.Description,
                                      Flash = model.Flash,
                                      Diaphragm = model.Diaphragm,
                                      FocalDistance = model.FocalDistance,
                                      ISO = model.ISO,
                                      RecordingDate = model.RecordingDate,
                                      RecordingPlace = model.RecordingPlace,
                                      ShutterSpeed = model.ShutterSpeed
                                  };
                var newAlbomList = new List<int>();
                foreach (var albom in model.AlbomList)
                {
                    if (albom.HasCurrentPicture)
                    {
                        newAlbomList.Add(albom.AlbomId);
                    }
                }

                unitOfWork.PictureRepository.UpdatePicture(picture, newAlbomList);
                unitOfWork.PictureRepository.Save();
            }

            return View(model);
        }