Esempio n. 1
0
        public ActionResult EditProperties(ImageGalleryEditPropertiesViewModel viewModel, string newName)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageImageGallery, T("Cannot edit image gallery")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            if (string.IsNullOrEmpty(newName))
            {
                ModelState.AddModelError("NewName", T("Invalid image gallery name").ToString());
                return(View(viewModel));
            }

            try {
                _imageGalleryService.UpdateImageGalleryProperties(viewModel.ImageGallery.Name, viewModel.ImageGallery.ThumbnailHeight,
                                                                  viewModel.ImageGallery.ThumbnailWidth, viewModel.ImageGallery.KeepAspectRatio);

                if (viewModel.ImageGallery.Name != newName)
                {
                    _imageGalleryService.RenameImageGallery(viewModel.ImageGallery.Name, newName);
                }

                Services.Notifier.Information(T("Image gallery properties successfully modified"));
                return(RedirectToAction("Images", new { imageGalleryName = newName }));
            }
            catch (Exception exception) {
                Services.Notifier.Error(T("Editing image gallery failed: {0}", exception.Message));
                return(View(viewModel));
            }
        }
Esempio n. 2
0
        public void EditProperties_Should_Return_ImageGalleryEditPropertiesViewModel()
        {
            // Arrange
            _imageGalleryServiceMock.Setup(galleryService => galleryService.GetImageGallery("gallery")).Returns(
                new Models.ImageGallery {
                Name = "gallery"
            });

            // Act
            var result = _adminController.EditProperties("gallery");

            // Assert
            result.AssertViewRendered().ForView("").WithViewData <ImageGalleryEditPropertiesViewModel>();
            ImageGalleryEditPropertiesViewModel model =
                ((ViewResult)result).Model as ImageGalleryEditPropertiesViewModel;

            Assert.IsNotNull(model);
            Assert.AreEqual("gallery", model.ImageGallery.Name);
        }
Esempio n. 3
0
        public void EditProperties_Post_Should_Save_And_Return_To_Images()
        {
            // Arrange
            _imageGalleryServiceMock.Setup(o => o.UpdateImageGalleryProperties("gallery", 80, 100, false, false)).Verifiable();
            var imageGallery = new Models.ImageGallery
            {
                Name = "gallery", ThumbnailHeight = 80, ThumbnailWidth = 100
            };
            ImageGalleryEditPropertiesViewModel viewModel = new ImageGalleryEditPropertiesViewModel
            {
                ImageGallery = imageGallery
            };

            // Act
            var result = _adminController.EditProperties(viewModel, "gallery");

            // Assert
            _imageGalleryServiceMock.Verify();
            result.AssertActionRedirect().ToAction("Images");
        }
Esempio n. 4
0
        public ActionResult EditProperties(ImageGalleryEditPropertiesViewModel viewModel, string newName)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageImageGallery, T("Cannot edit image gallery"))) {
                return new HttpUnauthorizedResult();
            }

            if (!ModelState.IsValid) {
                return View(viewModel);
            }

            if (string.IsNullOrEmpty(newName)) {
                ModelState.AddModelError("NewName", T("Invalid image gallery name").ToString());
                return View(viewModel);
            }

            try {
                _imageGalleryService.UpdateImageGalleryProperties(viewModel.ImageGallery.Name, viewModel.ImageGallery.ThumbnailHeight,
                                                                  viewModel.ImageGallery.ThumbnailWidth, viewModel.ImageGallery.KeepAspectRatio);

                if (viewModel.ImageGallery.Name != newName) {
                    _imageGalleryService.RenameImageGallery(viewModel.ImageGallery.Name, newName);
                }

                Services.Notifier.Information(T("Image gallery properties successfully modified"));
                return RedirectToAction("Images", new {imageGalleryName = newName});
            }
            catch (Exception exception) {
                Services.Notifier.Error(T("Editing image gallery failed: {0}", exception.Message));
                return View(viewModel);
            }
        }