Пример #1
0
        public ActionResult Edit(AdsBannerModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageWidgets))
            {
                return(AccessDeniedView());
            }
            var adsbanner = _adsBannerService.GetById(model.Id);

            if (adsbanner == null)
            {
                return(RedirectToAction("ConfigureWidget", "Widget",
                                        new { area = "Admin", systemName = "Widgets.AdsBanner" }));
            }
            if (ModelState.IsValid)
            {
                adsbanner = model.ToEntity(adsbanner);

                var prevPictureId = adsbanner.PictureId;

                _adsBannerService.UpdateAdsBanner(adsbanner);
                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != adsbanner.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }
                SuccessNotification(_localizationService.GetResource("Plugins.Widgets.AdsBanner.Updated"));
                return(continueEditing
                    ? RedirectToAction("Edit", new { id = adsbanner.Id })
                    : RedirectToAction("ConfigureWidget", "Widget",
                                       new { area = "Admin", systemName = "Widgets.AdsBanner" }));
            }

            PrepareAdsBannerModel(model);

            return(View("~/Plugins/Widgets.AdsBanner/Views/WidgetsAdsBanner/Edit.cshtml", model));
        }
Пример #2
0
        /// <summary>
        /// Delete slide from database
        /// </summary>
        /// <param name="slide">Deleting slide</param>
        public virtual void DeleteSlide(Slide slide)
        {
            var allLanguages = _languageService.GetAllLanguages(true);

            //delete slide localized pictures and values
            foreach (var language in allLanguages)
            {
                var pictureIdLocalizaedValue = _localizedEntityService.GetLocalizedValue(language.Id, slide.Id, "Slide", "PictureId");
                if (!string.IsNullOrEmpty(pictureIdLocalizaedValue) && int.TryParse(pictureIdLocalizaedValue, out int pictureId))
                {
                    //delete localized values
                    _localizedEntityService.SaveLocalizedValue(slide, x => x.PictureId, null, language.Id);
                    _localizedEntityService.SaveLocalizedValue(slide, x => x.HyperlinkAddress, null, language.Id);
                    _localizedEntityService.SaveLocalizedValue(slide, x => x.Description, null, language.Id);


                    var localizedPicture = _pictureService.GetPictureById(pictureId);
                    //go to next picture if current picture aren't exist
                    if (localizedPicture == null)
                    {
                        continue;
                    }

                    _pictureService.DeletePicture(localizedPicture);
                }
            }

            //delete slide base picture
            var picture = _pictureService.GetPictureById(slide.PictureId.GetValueOrDefault(0));

            if (picture != null)
            {
                _pictureService.DeletePicture(picture);
            }

            //publish event
            _eventPublisher.EntityDeleted(slide);
            //delete slide entity
            _slideRepository.Delete(slide);
        }
Пример #3
0
        public virtual Manufacturer UpdateManufacturerModel(Manufacturer manufacturer, ManufacturerModel model)
        {
            string prevPictureId = manufacturer.PictureId;

            manufacturer = model.ToEntity(manufacturer);
            manufacturer.UpdatedOnUtc = DateTime.UtcNow;
            manufacturer.Locales      = model.Locales.ToLocalizedProperty(manufacturer, x => x.Name, _urlRecordService);
            //discounts
            var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true);

            foreach (var discount in allDiscounts)
            {
                if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
                {
                    //new discount
                    if (manufacturer.AppliedDiscounts.Count(d => d == discount.Id) == 0)
                    {
                        manufacturer.AppliedDiscounts.Add(discount.Id);
                    }
                }
                else
                {
                    //remove discount
                    if (manufacturer.AppliedDiscounts.Count(d => d == discount.Id) > 0)
                    {
                        manufacturer.AppliedDiscounts.Remove(discount.Id);
                    }
                }
            }
            model.SeName        = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true);
            manufacturer.SeName = model.SeName;

            _manufacturerService.UpdateManufacturer(manufacturer);
            //search engine name
            _urlRecordService.SaveSlug(manufacturer, model.SeName, "");

            //delete an old picture (if deleted or updated)
            if (!String.IsNullOrEmpty(prevPictureId) && prevPictureId != manufacturer.PictureId)
            {
                var prevPicture = _pictureService.GetPictureById(prevPictureId);
                if (prevPicture != null)
                {
                    _pictureService.DeletePicture(prevPicture);
                }
            }
            //update picture seo file name
            _pictureService.UpdatePictureSeoNames(manufacturer.PictureId, manufacturer.Name);

            //activity log
            _customerActivityService.InsertActivity("EditManufacturer", manufacturer.Id, _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name);
            return(manufacturer);
        }
        public ActionResult Edit(ManufacturerModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var manufacturer = _manufacturerService.GetManufacturerById(model.Id);

            if (manufacturer == null || manufacturer.Deleted)
            {
                //No manufacturer found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                int prevPictureId = manufacturer.PictureId;
                manufacturer = model.ToEntity(manufacturer);
                manufacturer.UpdatedOnUtc = DateTime.UtcNow;
                _manufacturerService.UpdateManufacturer(manufacturer);
                //search engine name
                model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true);
                _urlRecordService.SaveSlug(manufacturer, model.SeName, 0);
                //locales
                UpdateLocales(manufacturer, model);
                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != manufacturer.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }
                //update picture seo file name
                UpdatePictureSeoNames(manufacturer);

                //activity log
                _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated"));
                return(continueEditing ? RedirectToAction("Edit", manufacturer.Id) : RedirectToAction("List"));
            }


            //If we got this far, something failed, redisplay form
            //templates
            PrepareTemplatesModel(model);

            return(View(model));
        }
Пример #5
0
        public IResult UpdateArticle(ArticleForUpdateDto articleForUpdateDto)
        {
            //TO DO: Implement transaction

            Article article = _articleRepository.GetIncluding(x => x.Id == articleForUpdateDto.Id,
                                                              x => x.Pictures);
            var picturesDict = article.Pictures.ToDictionary(x => x.PublicId);

            var toBeDeletedPictures = _mapper.Map <List <PictureForDeleteDto> >(picturesDict.Where(x => !articleForUpdateDto.Pictures
                                                                                                   .Select(y => y.PublicId)
                                                                                                   .Contains(x.Key))
                                                                                .Select(x => x.Value));

            foreach (var toBeDeletedPicture in toBeDeletedPictures)
            {
                _pictureService.DeletePicture(toBeDeletedPicture);
            }

            var picturesToBeCreated = articleForUpdateDto.Pictures.Where(x => x.PublicId == null).Select(x => new PictureForCreationDto
            {
                ArticleId = article.Id,
                IsMain    = x.IsMain,
                File      = x.File
            }).ToList();

            var articleWithTranslationToBeUpdated = _mapper.Map <ArticleTranslation>(articleForUpdateDto);

            if (picturesToBeCreated.Count > 0)
            {
                bool skipMainPicture = picturesToBeCreated.Any(x => x.IsMain) ? false : true;
                var  result          = _pictureService.InsertPicturesForArticle(picturesToBeCreated, skipMainPicture);

                if (result.Success)
                {
                    var imgRegex = new Regex("<img src=\"(?<url>(data:(?<type>.+?);base64),(?<data>[^\"]+))\"");
                    foreach (var picture in result.Data.Where(x => !x.IsMain))
                    {
                        articleWithTranslationToBeUpdated.ContentMain = imgRegex.Replace(articleWithTranslationToBeUpdated.ContentMain,
                                                                                         m => $"<img src=\"{picture.Url}\"", 1);
                    }

                    _articleTranslationRepository.Update(articleWithTranslationToBeUpdated);
                    return(new SuccessResult(string.Format(Messages.SuccessfulUpdate, nameof(Article))));
                }
                else
                {
                    return(new ErrorResult($"Picture couldn't be inserted Error Message {result.Message}"));
                }
            }
            _articleTranslationRepository.Update(articleWithTranslationToBeUpdated);
            return(new SuccessResult(string.Format(Messages.SuccessfulUpdate, nameof(Article))));
        }
Пример #6
0
        public ActionResult Delete(int Id)
        {
            var banner = _bannerService.GetBannerById(Id);

            if (banner != null)
            {
                foreach (var lang in _languageService.GetAllLanguages())
                {
                    int pictureId = banner.GetLocalized(x => x.PictureId, lang.Id, false);
                    if (pictureId != 0)
                    {
                        var picture = _pictureService.GetPictureById(pictureId);
                        if (picture != null)
                        {
                            _pictureService.DeletePicture(picture);
                        }
                    }
                }
                _bannerService.DeleteBannner(banner);
            }
            return(RedirectToAction("List"));
        }
        public virtual IActionResult DeletePicture(int id)
        {
            var picture = _pictureService.GetPictureById(id);

            if (picture != null)
            {
                _pictureService.DeletePicture(picture);

                return(Json(new { success = true }));
            }

            return(Json(new { success = false }));
        }
Пример #8
0
        public Vendor UpdateVendorModel(Vendor vendor, VendorModel model)
        {
            string prevPictureId = vendor.PictureId;

            vendor         = model.ToEntity(vendor);
            vendor.Locales = model.Locales.ToLocalizedProperty(vendor, x => x.Name, _urlRecordService);
            model.SeName   = vendor.ValidateSeName(model.SeName, vendor.Name, true);
            vendor.Address = model.Address.ToEntity(vendor.Address);

            //discounts
            var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToVendors, showHidden: true);

            foreach (var discount in allDiscounts)
            {
                if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
                {
                    //new discount
                    if (vendor.AppliedDiscounts.Count(d => d == discount.Id) == 0)
                    {
                        vendor.AppliedDiscounts.Add(discount.Id);
                    }
                }
                else
                {
                    //remove discount
                    if (vendor.AppliedDiscounts.Count(d => d == discount.Id) > 0)
                    {
                        vendor.AppliedDiscounts.Remove(discount.Id);
                    }
                }
            }

            vendor.SeName = model.SeName;

            _vendorService.UpdateVendor(vendor);
            //search engine name
            _urlRecordService.SaveSlug(vendor, model.SeName, "");

            //delete an old picture (if deleted or updated)
            if (!String.IsNullOrEmpty(prevPictureId) && prevPictureId != vendor.PictureId)
            {
                var prevPicture = _pictureService.GetPictureById(prevPictureId);
                if (prevPicture != null)
                {
                    _pictureService.DeletePicture(prevPicture);
                }
            }
            //update picture seo file name
            _pictureService.UpdatePictureSeoNames(vendor.PictureId, vendor.Name);
            return(vendor);
        }
Пример #9
0
        public void Delete(BannerMiniSite banner)
        {
            if (banner == null)
            {
                throw new ArgumentNullException("BannerMiniSite");
            }
            if (banner.BannerPictureId != 0)
            {
                _pictureService.DeletePicture(_pictureService.GetPictureById(banner.BannerPictureId));
            }
            _repository.Delete(banner);

            _eventPublisher.EntityDeleted(banner);
        }
        /// <summary>
        /// Delete the file
        /// </summary>
        /// <param name="sourcePath">Path to the file</param>
        /// <returns>A task that represents the completion of the operation</returns>
        public override async Task DeleteFileAsync(string sourcePath)
        {
            var filePath = _fileProvider.GetAbsolutePath(sourcePath.Split('/'));
            var picture  = GetPictureByFile(filePath);

            if (picture == null)
            {
                throw new Exception(GetLanguageResource("E_DeletеFile"));
            }

            _pictureService.DeletePicture(picture);

            await base.DeleteFileAsync(sourcePath);
        }
 public override async void ViewDestroy(bool viewFinishing = true)
 {
     base.ViewDestroy(viewFinishing);
     if (_isPosted || !viewFinishing)
     {
         return;
     }
     foreach (var pictureViewModel in _post.PostPictures.Except(_originalPost.PostPictures))
     {
         await ApiRequestHelper.HandleApiResult(() =>
                                                _pictureService.DeletePicture(
                                                    pictureViewModel.PictureUrl.Substring(pictureViewModel.PictureUrl.LastIndexOf("/") + 1)));
     }
 }
Пример #12
0
        public IActionResult DeletePicture(int?tourId, int?id, string userId)
        {
            if (userId != User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                return(Unauthorized());
            }

            var pictureDTO = _pictureService.GetPicture(id);

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

            if (pictureDTO.IsMain)
            {
                return(BadRequest("You can not delete the main photo"));
            }

            if (pictureDTO.PictureId != null)
            {
                var deleteParams = new DeletionParams(pictureDTO.PublicId);

                var result = _cloudinary.Destroy(deleteParams);
                if (result.Result == "ok")
                {
                    _pictureService.DeletePicture(pictureDTO.PictureId);
                }
                return(Ok());
            }
            if (pictureDTO.PublicId == null)
            {
                _pictureService.DeletePicture(pictureDTO.PictureId);
                return(Ok());
            }
            return(BadRequest("Failed to delete the photo"));
        }
Пример #13
0
        public virtual IActionResult Edit(CategoryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermission.ManageCategories))
            {
                return(AccessDeniedView());
            }

            //try to get a category with the specified id
            var category = _categoryService.GetCategoryById(model.Id);

            if (category == null || category.Deleted)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var prevPictureId = category.PictureId;

                category = model.ToEntity(category);
                category.UpdatedOnUtc = DateTime.UtcNow;
                _categoryService.UpdateCategory(category);

                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != category.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }

                _notificationService.SuccessNotification("The category has been updated successfully.");

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                return(RedirectToAction("Edit", new { id = category.Id }));
            }

            //prepare model
            model = _categoryModelFactory.PrepareCategoryModel(model, category, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #14
0
        public virtual IActionResult GaleriPictureDelete(int id)
        {
            //try to get a product picture with the specified id
            PhotoGalleryMapping galeriPicture = _photoGalleryMapRepository.GetById(id)
                                                ?? throw new ArgumentException("No product picture found with the specified id");
            int pictureId = galeriPicture.PictureId;

            _photoGalleryMapRepository.Delete(galeriPicture);
            //try to get a picture with the specified id
            Picture picture = _pictureService.GetPictureById(pictureId)
                              ?? throw new ArgumentException("No picture found with the specified id");

            _pictureService.DeletePicture(picture);
            return(new NullJsonResult());
        }
Пример #15
0
        public override async Task ExecuteAsync(TaskExecutionContext ctx)
        {
            // Delete all media records which are in transient state since at least 3 hours.
            var olderThan          = DateTime.UtcNow.AddHours(-3);
            var pictureAutoCommit  = _pictureRepository.AutoCommitEnabled;
            var downloadAutoCommit = _downloadRepository.AutoCommitEnabled;

            _pictureRepository.AutoCommitEnabled  = false;
            _downloadRepository.AutoCommitEnabled = false;

            try
            {
                using (var scope = new DbContextScope(autoDetectChanges: false, validateOnSave: false, hooksEnabled: false))
                {
                    var pictures = await _pictureRepository.Table.Where(x => x.IsTransient && x.UpdatedOnUtc < olderThan).ToListAsync();

                    foreach (var picture in pictures)
                    {
                        _pictureService.DeletePicture(picture);
                    }

                    await _pictureRepository.Context.SaveChangesAsync();

                    var downloads = await _downloadRepository.Table.Where(x => x.IsTransient && x.UpdatedOnUtc < olderThan).ToListAsync();

                    foreach (var download in downloads)
                    {
                        _downloadService.DeleteDownload(download);
                    }

                    await _downloadRepository.Context.SaveChangesAsync();

                    if (DataSettings.Current.IsSqlServer && (pictures.Any() || downloads.Any()))
                    {
                        try
                        {
                            _pictureRepository.Context.ExecuteSqlCommand("DBCC SHRINKDATABASE(0)", true);
                        }
                        catch { }
                    }
                }
            }
            finally
            {
                _pictureRepository.AutoCommitEnabled  = pictureAutoCommit;
                _downloadRepository.AutoCommitEnabled = downloadAutoCommit;
            }
        }
        private void UpdateProductPictures(Product entityToUpdate, List <ImageMappingDto> setPictures)
        {
            // If no pictures are specified means we don't have to update anything
            if (setPictures == null)
            {
                return;
            }

            // delete unused product pictures
            var unusedProductPictures = entityToUpdate.ProductPictures.Where(x => setPictures.All(y => y.Id != x.Id)).ToList();

            foreach (var unusedProductPicture in unusedProductPictures)
            {
                var picture = _pictureService.GetPictureById(unusedProductPicture.PictureId);
                if (picture == null)
                {
                    throw new ArgumentException("No picture found with the specified id");
                }
                _pictureService.DeletePicture(picture);
            }

            foreach (var imageDto in setPictures)
            {
                if (imageDto.Id > 0)
                {
                    // update existing product picture
                    var productPictureToUpdate = entityToUpdate.ProductPictures.FirstOrDefault(x => x.Id == imageDto.Id);
                    if (productPictureToUpdate != null && imageDto.Position > 0)
                    {
                        productPictureToUpdate.DisplayOrder = imageDto.Position;
                        _productService.UpdateProductPicture(productPictureToUpdate);
                    }
                }
                else
                {
                    // add new product picture
                    Picture newPicture = _pictureService.InsertPicture(imageDto.Binary, imageDto.MimeType, string.Empty);
                    _productService.InsertProductPicture(new ProductPicture()
                    {
                        PictureId    = newPicture.Id,
                        ProductId    = entityToUpdate.Id,
                        DisplayOrder = imageDto.Position
                    });
                }
            }
        }
        public async Task <BrandDto> Handle(UpdateBrandCommand request, CancellationToken cancellationToken)
        {
            var brand = await _brandService.GetBrandById(request.Model.Id);

            var prevPictureId = brand.PictureId;

            brand = request.Model.ToEntity(brand);
            brand.UpdatedOnUtc   = DateTime.UtcNow;
            request.Model.SeName = await brand.ValidateSeName(request.Model.SeName, brand.Name, true, _seoSettings, _slugService, _languageService);

            brand.SeName = request.Model.SeName;
            await _brandService.UpdateBrand(brand);

            //search engine name
            await _slugService.SaveSlug(brand, request.Model.SeName, "");

            await _brandService.UpdateBrand(brand);

            //delete an old picture (if deleted or updated)
            if (!string.IsNullOrEmpty(prevPictureId) && prevPictureId != brand.PictureId)
            {
                var prevPicture = await _pictureService.GetPictureById(prevPictureId);

                if (prevPicture != null)
                {
                    await _pictureService.DeletePicture(prevPicture);
                }
            }
            //update picture seo file name
            if (!string.IsNullOrEmpty(brand.PictureId))
            {
                var picture = await _pictureService.GetPictureById(brand.PictureId);

                if (picture != null)
                {
                    await _pictureService.SetSeoFilename(picture.Id, _pictureService.GetPictureSeName(brand.Name));
                }
            }
            //activity log
            await _customerActivityService.InsertActivity("EditBrand", brand.Id, _translationService.GetResource("ActivityLog.EditBrand"), brand.Name);

            return(brand.ToModel());
        }
Пример #18
0
        public override void Uninstall()
        {
            Picture watermarkPicture = _pictureService.GetPictureById(_settingService.LoadSetting <WatermarkSettings>().PictureId);

            if (watermarkPicture != null)
            {
                _pictureService.DeletePicture(watermarkPicture);
            }

            _settingService.DeleteSetting <WatermarkSettings>();
            DeleteLocaleResources();

            _settingService.ClearCache();

            new ClearCacheTask(EngineContext.Current.Resolve <IStaticCacheManager>()).Execute();
            Utils.ClearThumbsDirectory();

            base.Uninstall();
        }
Пример #19
0
        public ActionResult ArticlePictureDelete(int id)
        {
            var articlePicture = _articleService.GetArticleAlbumById(id);

            if (articlePicture == null)
            {
                throw new ArgumentException("No article picture found with the specified id");
            }

            var articleId = articlePicture.ArticleId;

            _articleService.DeleteArticleAlbum(articlePicture);

            var picture = _pictureService.GetPictureById(articlePicture.PictureId);

            _pictureService.DeletePicture(picture);

            return(Json(new { success = true }));
        }
Пример #20
0
        public async Task <CollectionDto> Handle(UpdateCollectionCommand request, CancellationToken cancellationToken)
        {
            var collection = await _collectionService.GetCollectionById(request.Model.Id);

            var prevPictureId = collection.PictureId;

            collection = request.Model.ToEntity(collection);
            collection.UpdatedOnUtc = DateTime.UtcNow;
            request.Model.SeName    = await collection.ValidateSeName(request.Model.SeName, collection.Name, true, _seoSettings, _slugService, _languageService);

            collection.SeName = request.Model.SeName;
            await _collectionService.UpdateCollection(collection);

            //search engine name
            await _slugService.SaveSlug(collection, request.Model.SeName, "");

            await _collectionService.UpdateCollection(collection);

            //delete an old picture (if deleted or updated)
            if (!string.IsNullOrEmpty(prevPictureId) && prevPictureId != collection.PictureId)
            {
                var prevPicture = await _pictureService.GetPictureById(prevPictureId);

                if (prevPicture != null)
                {
                    await _pictureService.DeletePicture(prevPicture);
                }
            }
            //update picture seo file name
            if (!string.IsNullOrEmpty(collection.PictureId))
            {
                var picture = await _pictureService.GetPictureById(collection.PictureId);

                if (picture != null)
                {
                    await _pictureService.SetSeoFilename(picture.Id, _pictureService.GetPictureSeName(collection.Name));
                }
            }
            //activity log
            await _customerActivityService.InsertActivity("EditCollection", collection.Id, _translationService.GetResource("ActivityLog.EditCollection"), collection.Name);

            return(collection.ToModel());
        }
        public async Task <ManufacturerDto> Handle(UpdateManufacturerCommand request, CancellationToken cancellationToken)
        {
            var manufacturer = await _manufacturerService.GetManufacturerById(request.Model.Id);

            var prevPictureId = manufacturer.PictureId;

            manufacturer = request.Model.ToEntity(manufacturer);
            manufacturer.UpdatedOnUtc = DateTime.UtcNow;
            request.Model.SeName      = await manufacturer.ValidateSeName(request.Model.SeName, manufacturer.Name, true, _seoSettings, _urlRecordService, _languageService);

            manufacturer.SeName = request.Model.SeName;
            await _manufacturerService.UpdateManufacturer(manufacturer);

            //search engine name
            await _urlRecordService.SaveSlug(manufacturer, request.Model.SeName, "");

            await _manufacturerService.UpdateManufacturer(manufacturer);

            //delete an old picture (if deleted or updated)
            if (!string.IsNullOrEmpty(prevPictureId) && prevPictureId != manufacturer.PictureId)
            {
                var prevPicture = await _pictureService.GetPictureById(prevPictureId);

                if (prevPicture != null)
                {
                    await _pictureService.DeletePicture(prevPicture);
                }
            }
            //update picture seo file name
            if (!string.IsNullOrEmpty(manufacturer.PictureId))
            {
                var picture = await _pictureService.GetPictureById(manufacturer.PictureId);

                if (picture != null)
                {
                    await _pictureService.SetSeoFilename(picture.Id, _pictureService.GetPictureSeName(manufacturer.Name));
                }
            }
            //activity log
            await _customerActivityService.InsertActivity("EditManufacturer", manufacturer.Id, _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name);

            return(manufacturer.ToModel());
        }
        public async Task <CategoryDto> Handle(UpdateCategoryCommand request, CancellationToken cancellationToken)
        {
            var category = await _categoryService.GetCategoryById(request.Model.Id);

            string prevPictureId = category.PictureId;

            category = request.Model.ToEntity(category);
            category.UpdatedOnUtc = DateTime.UtcNow;
            request.Model.SeName  = await category.ValidateSeName(request.Model.SeName, category.Name, true, _seoSettings, _urlRecordService, _languageService);

            category.SeName = request.Model.SeName;
            await _categoryService.UpdateCategory(category);

            //search engine name
            await _urlRecordService.SaveSlug(category, request.Model.SeName, "");

            await _categoryService.UpdateCategory(category);

            //delete an old picture (if deleted or updated)
            if (!String.IsNullOrEmpty(prevPictureId) && prevPictureId != category.PictureId)
            {
                var prevPicture = await _pictureService.GetPictureById(prevPictureId);

                if (prevPicture != null)
                {
                    await _pictureService.DeletePicture(prevPicture);
                }
            }
            //update picture seo file name
            if (!string.IsNullOrEmpty(category.PictureId))
            {
                var picture = await _pictureService.GetPictureById(category.PictureId);

                if (picture != null)
                {
                    await _pictureService.SetSeoFilename(picture.Id, _pictureService.GetPictureSeName(category.Name));
                }
            }
            //activity log
            await _customerActivityService.InsertActivity("EditCategory", category.Id, _localizationService.GetResource("ActivityLog.EditCategory"), category.Name);

            return(category.ToModel());
        }
Пример #23
0
        public async Task <Unit> Handle(DeleteAlbumCommand request, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            Guid  userId        = _httpContextAccessor.HttpContext.GetUserId();
            Album albumToDelete = await _dbContext.Albums.FindAsync(request.AlbumId);

            if (albumToDelete.OwnerId == userId)
            {
                foreach (var picture in albumToDelete.Pictures)
                {
                    _pictureService.DeletePicture(picture.Id, picture.Extension);
                }

                _dbContext.Pictures.RemoveRange(albumToDelete.Pictures);
                _dbContext.Albums.Remove(albumToDelete);
                await _dbContext.SaveChangesAsync(cancellationToken);
            }

            return(Unit.Value);
        }
Пример #24
0
        public ActionResult PictureDelete(int id)
        {
            //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            //    return AccessDeniedView();

            var entityPicture = _eventPageService.GetPictureById(id);

            if (entityPicture == null)
            {
                throw new ArgumentException("No picture found with the specified id");
            }

            var pictureId = entityPicture.PictureId;

            _eventPageService.DeletePicture(entityPicture);
            var picture = _pictureService.GetPictureById(pictureId);

            _pictureService.DeletePicture(picture);

            return(new NullJsonResult());
        }
        public void Execute(TaskExecutionContext ctx)
        {
            // delete all media records which are in transient state since at least 3 hours
            var olderThan = DateTime.UtcNow.AddHours(-3);

            // delete Downloads
            _downloadRepository.DeleteAll(x => x.IsTransient && x.UpdatedOnUtc < olderThan);

            // delete Pictures
            var autoCommit = _pictureRepository.AutoCommitEnabled;

            _pictureRepository.AutoCommitEnabled = false;

            try
            {
                using (var scope = new DbContextScope(autoDetectChanges: false, validateOnSave: false, hooksEnabled: false))
                {
                    var pictures = _pictureRepository.Table.Where(x => x.IsTransient && x.UpdatedOnUtc < olderThan).ToList();
                    foreach (var picture in pictures)
                    {
                        _pictureService.DeletePicture(picture);
                    }

                    _pictureRepository.Context.SaveChanges();

                    if (DataSettings.Current.IsSqlServer)
                    {
                        try
                        {
                            _pictureRepository.Context.ExecuteSqlCommand("DBCC SHRINKDATABASE(0)", true);
                        }
                        catch { }
                    }
                }
            }
            finally
            {
                _pictureRepository.AutoCommitEnabled = autoCommit;
            }
        }
Пример #26
0
        public ActionResult Edit(ProductAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var productAttribute = _productAttributeService.GetProductAttributeById(model.Id);

            if (productAttribute == null)
            {
                //No product attribute found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                if (model.PictureId != productAttribute.PictureId && model.PictureId != 0)
                {
                    var picture = _pictureService.GetPictureById(productAttribute.PictureId.GetValueOrDefault());
                    if (picture != null)
                    {
                        _pictureService.DeletePicture(picture);
                    }
                }
                productAttribute = model.ToEntity(productAttribute);
                _productAttributeService.UpdateProductAttribute(productAttribute);

                UpdateLocales(productAttribute, model);

                //activity log
                _customerActivityService.InsertActivity("EditProductAttribute", _localizationService.GetResource("ActivityLog.EditProductAttribute"), productAttribute.Name);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.ProductAttributes.Updated"));
                return(continueEditing ? RedirectToAction("Edit", productAttribute.Id) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        public virtual IActionResult VendorPictureDelete(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            {
                return(AccessDeniedView());
            }

            //try to get a vendor picture with the specified id
            var vendorPicture = this.GetVendorPictureById(id)
                                ?? throw new ArgumentException("No vendor picture found with the specified id");

            var pictureId = vendorPicture.PictureId;

            this.DeleteVendorPicture(vendorPicture);

            //try to get a picture with the specified id
            var picture = _pictureService.GetPictureById(pictureId)
                          ?? throw new ArgumentException("No picture found with the specified id");

            _pictureService.DeletePicture(picture);

            return(new NullJsonResult());
        }
Пример #28
0
        public ActionResult ConversionImageDelete(GridCommand command, int id)
        {
            var conversionImage = _conversionImageService.GetConversionImageById(id);

            if (conversionImage != null)
            {
                int groupId = conversionImage.CategoryAttributeGroupId;
                foreach (var lang in _languageService.GetAllLanguages())
                {
                    int pictureId = conversionImage.GetLocalized(x => x.PictureId, lang.Id, false);
                    if (pictureId != 0)
                    {
                        _pictureService.DeletePicture(_pictureService.GetPictureById(pictureId));
                    }
                }
                _conversionImageService.Delete(conversionImage);
                return(ConversionImagesList(command, groupId));
            }

            var modelStateErrors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);

            return(Content(modelStateErrors.FirstOrDefault()));
        }
Пример #29
0
        public virtual IActionResult CelebrityPictureDelete(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCelebrities))
            {
                return(AccessDeniedView());
            }

            //try to get a celebrity picture with the specified id
            var celebrityPicture = _celebrityService.GetCelebrityPictureById(id)
                                   ?? throw new ArgumentException("No Celebrity picture found with the specified id");

            var pictureId = celebrityPicture.PictureId;

            _celebrityService.DeleteCelebrityPicture(celebrityPicture);

            //try to get a picture with the specified id
            var picture = _pictureService.GetPictureById(pictureId)
                          ?? throw new ArgumentException("No picture found with the specified id");

            _pictureService.DeletePicture(picture);

            return(new NullJsonResult());
        }
Пример #30
0
        private void UpdatePicture(Category categoryEntityToUpdate, ImageDto imageDto)
        {
            // no image specified then do nothing
            if (imageDto == null)
            {
                return;
            }

            Picture updatedPicture         = null;
            Picture currentCategoryPicture = _pictureService.GetPictureById(categoryEntityToUpdate.PictureId);

            // when there is a picture set for the category
            if (currentCategoryPicture != null)
            {
                _pictureService.DeletePicture(currentCategoryPicture);

                // When the image attachment is null or empty.
                if (imageDto.Binary == null)
                {
                    categoryEntityToUpdate.PictureId = 0;
                }
                else
                {
                    updatedPicture = _pictureService.InsertPicture(imageDto.Binary, imageDto.MimeType, string.Empty);
                    categoryEntityToUpdate.PictureId = updatedPicture.Id;
                }
            }
            // when there isn't a picture set for the category
            else
            {
                if (imageDto.Binary != null)
                {
                    updatedPicture = _pictureService.InsertPicture(imageDto.Binary, imageDto.MimeType, string.Empty);
                    categoryEntityToUpdate.PictureId = updatedPicture.Id;
                }
            }
        }