public ActionResult DeleteImage(int id)
        {
            var gallery = _galleryService.GetGalleryImageById(id);

            if (gallery == null)
            {
                //No gallery found with the specified id
                return(RedirectToAction("ImagesList"));
            }

            _galleryService.DeleteGalleryImage(gallery);

            SuccessNotification(_localizationService.GetResource("Plugin.Widgets.Gallery.GalleryConfigureController.ImageDeleted"));
            return(RedirectToAction("ImagesList"));
        }
        public IActionResult AddGallery(AddGalleryImageViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewData["GeneralError"] = Messages.RequiredInput;
                ViewData["Categories"]   = (List <CategoryImage>)(_categoryImageService.GetAll()).Data.Where(x => x.IsActive);
                return(View(model));
            }

            var source = _galleryService.UploadGalleryImage(model.File, ImageSavePaths.GallerySavePath);

            if (source.Success)
            {
                GalleryImage galleryImage = new GalleryImage();
                galleryImage.Source      = source.Data;
                galleryImage.Description = model.Description;

                var image = _galleryService.Add(galleryImage);

                if (image.Success)
                {
                    foreach (var categoryId in model.CategoriesId)
                    {
                        GalleryCategory galleryCategory = new GalleryCategory();

                        galleryCategory.GalleryImageId  = galleryImage.Id;
                        galleryCategory.CategoryImageId = categoryId;

                        _galleryCategoryService.Add(galleryCategory);
                    }
                    ViewData["GeneralSuccess"] = image.Message;
                    return(RedirectToAction("ListGallery", "ManagementPanel"));
                }

                _galleryService.Delete(galleryImage);
            }

            _galleryService.DeleteGalleryImage(source.Data);
            ViewData["GeneralError"] = Messages.GeneralError;
            ViewData["Categories"]   = (List <CategoryImage>)(_categoryImageService.GetAll()).Data;
            return(View(model));
        }