public virtual async Task <Page> InsertPageModel(PageModel model) { if (!model.IsPasswordProtected) { model.Password = null; } var page = model.ToEntity(_dateTimeService); await _pageService.InsertPage(page); //search engine name model.SeName = await page.ValidateSeName(model.SeName, page.Title ?? page.SystemName, true, _seoSettings, _slugService, _languageService); page.Locales = await model.Locales.ToTranslationProperty(page, x => x.Title, _seoSettings, _slugService, _languageService); page.SeName = model.SeName; await _pageService.UpdatePage(page); await _slugService.SaveSlug(page, model.SeName, ""); //activity log await _customerActivityService.InsertActivity("AddNewPage", page.Id, _translationService.GetResource("ActivityLog.AddNewPage"), page.Title ?? page.SystemName); return(page); }
public virtual async Task <Course> InsertCourseModel(CourseModel model) { var course = model.ToEntity(); course.CreatedOnUtc = DateTime.UtcNow; course.UpdatedOnUtc = DateTime.UtcNow; await _courseService.Insert(course); //locales model.SeName = await course.ValidateSeName(model.SeName, course.Name, true, _seoSettings, _slugService, _languageService); course.SeName = model.SeName; await _courseService.Update(course); await _slugService.SaveSlug(course, model.SeName, ""); //update picture seo file name await _pictureService.UpdatePictureSeoNames(course.PictureId, course.Name); //course on the product if (!string.IsNullOrEmpty(course.ProductId)) { await _productCourseService.UpdateCourseOnProduct(course.ProductId, course.Id); } //activity log await _customerActivityService.InsertActivity("AddNewCourse", course.Id, _translationService.GetResource("ActivityLog.AddNewCourse"), course.Name); return(course); }
public virtual async Task <Vendor> InsertVendorModel(VendorModel model) { var vendor = model.ToEntity(); vendor.Address = model.Address.ToEntity(); vendor.Address.CreatedOnUtc = DateTime.UtcNow; await _vendorService.InsertVendor(vendor); //discounts var allDiscounts = await _discountService.GetAllDiscounts(DiscountType.AssignedToVendors, showHidden : true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { vendor.AppliedDiscounts.Add(discount.Id); } } //search engine name model.SeName = await vendor.ValidateSeName(model.SeName, vendor.Name, true, _seoSettings, _slugService, _languageService); vendor.Locales = await model.Locales.ToTranslationProperty(vendor, x => x.Name, _seoSettings, _slugService, _languageService); vendor.SeName = model.SeName; await _vendorService.UpdateVendor(vendor); //update picture seo file name await _pictureService.UpdatePictureSeoNames(vendor.PictureId, vendor.Name); await _slugService.SaveSlug(vendor, model.SeName, ""); return(vendor); }
public async Task <Category> InsertCategoryModel(CategoryModel model) { var category = model.ToEntity(); category.CreatedOnUtc = DateTime.UtcNow; category.UpdatedOnUtc = DateTime.UtcNow; var allDiscounts = await _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, showHidden : true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { category.AppliedDiscounts.Add(discount.Id); } } await _categoryService.InsertCategory(category); //locales category.Locales = await model.Locales.ToTranslationProperty(category, x => x.Name, _seoSettings, _slugService, _languageService); model.SeName = await category.ValidateSeName(model.SeName, category.Name, true, _seoSettings, _slugService, _languageService); category.SeName = model.SeName; await _categoryService.UpdateCategory(category); await _slugService.SaveSlug(category, model.SeName, ""); //update picture seo file name await _pictureService.UpdatePictureSeoNames(category.PictureId, category.Name); //activity log await _customerActivityService.InsertActivity("AddNewCategory", category.Id, _translationService.GetResource("ActivityLog.AddNewCategory"), category.Name); return(category); }
public virtual async Task <KnowledgebaseCategory> InsertKnowledgebaseCategoryModel(KnowledgebaseCategoryModel model) { var knowledgebaseCategory = model.ToEntity(); knowledgebaseCategory.CreatedOnUtc = DateTime.UtcNow; knowledgebaseCategory.UpdatedOnUtc = DateTime.UtcNow; knowledgebaseCategory.Locales = await model.Locales.ToTranslationProperty(knowledgebaseCategory, x => x.Name, _seoSettings, _slugService, _languageService); model.SeName = await knowledgebaseCategory.ValidateSeName(model.SeName, knowledgebaseCategory.Name, true, _seoSettings, _slugService, _languageService); knowledgebaseCategory.SeName = model.SeName; await _knowledgebaseService.InsertKnowledgebaseCategory(knowledgebaseCategory); await _slugService.SaveSlug(knowledgebaseCategory, model.SeName, ""); await _customerActivityService.InsertActivity("CreateKnowledgebaseCategory", knowledgebaseCategory.Id, _translationService.GetResource("ActivityLog.CreateKnowledgebaseCategory"), knowledgebaseCategory.Name); return(knowledgebaseCategory); }
public virtual async Task <BlogPost> InsertBlogPostModel(BlogPostModel model) { var blogPost = model.ToEntity(_dateTimeService); blogPost.CreatedOnUtc = DateTime.UtcNow; await _blogService.InsertBlogPost(blogPost); //search engine name var seName = await blogPost.ValidateSeName(model.SeName, model.Title, true, _seoSettings, _slugService, _languageService); blogPost.SeName = seName; blogPost.Locales = await model.Locales.ToTranslationProperty(blogPost, x => x.Title, _seoSettings, _slugService, _languageService); await _blogService.UpdateBlogPost(blogPost); await _slugService.SaveSlug(blogPost, seName, ""); //update picture seo file name await _pictureService.UpdatePictureSeoNames(blogPost.PictureId, blogPost.Title); return(blogPost); }
public virtual async Task <NewsItem> InsertNewsItemModel(NewsItemModel model) { var datetimeService = _serviceProvider.GetRequiredService <IDateTimeService>(); var newsItem = model.ToEntity(datetimeService); newsItem.CreatedOnUtc = DateTime.UtcNow; await _newsService.InsertNews(newsItem); var seName = await newsItem.ValidateSeName(model.SeName, model.Title, true, _serviceProvider.GetRequiredService <SeoSettings>(), _slugService, _serviceProvider.GetRequiredService <ILanguageService>()); newsItem.SeName = seName; newsItem.Locales = await model.Locales.ToTranslationProperty(newsItem, x => x.Title, _serviceProvider.GetRequiredService <SeoSettings>(), _slugService, _serviceProvider.GetRequiredService <ILanguageService>()); await _newsService.UpdateNews(newsItem); //search engine name await _slugService.SaveSlug(newsItem, seName, ""); //update picture seo file name await _pictureService.UpdatePictureSeoNames(newsItem.PictureId, newsItem.Title); return(newsItem); }
public virtual async Task <Brand> InsertBrandModel(BrandModel model) { var brand = model.ToEntity(); brand.CreatedOnUtc = DateTime.UtcNow; brand.UpdatedOnUtc = DateTime.UtcNow; //discounts var allDiscounts = await _discountService.GetAllDiscounts(DiscountType.AssignedToBrands, showHidden : true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { brand.AppliedDiscounts.Add(discount.Id); } } await _brandService.InsertBrand(brand); //search engine name brand.Locales = await model.Locales.ToTranslationProperty(brand, x => x.Name, _seoSettings, _slugService, _languageService); model.SeName = await brand.ValidateSeName(model.SeName, brand.Name, true, _seoSettings, _slugService, _languageService); brand.SeName = model.SeName; await _brandService.UpdateBrand(brand); await _slugService.SaveSlug(brand, model.SeName, ""); //update picture seo file name await _pictureService.UpdatePictureSeoNames(brand.PictureId, brand.Name); //activity log await _customerActivityService.InsertActivity("AddNewBrand", brand.Id, _translationService.GetResource("ActivityLog.AddNewBrand"), brand.Name); return(brand); }
public virtual async Task <Collection> InsertCollectionModel(CollectionModel model) { var collection = model.ToEntity(); collection.CreatedOnUtc = DateTime.UtcNow; collection.UpdatedOnUtc = DateTime.UtcNow; //discounts var allDiscounts = await _discountService.GetAllDiscounts(DiscountType.AssignedToCollections, showHidden : true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { collection.AppliedDiscounts.Add(discount.Id); } } await _collectionService.InsertCollection(collection); //search engine name collection.Locales = await model.Locales.ToTranslationProperty(collection, x => x.Name, _seoSettings, _slugService, _languageService); model.SeName = await collection.ValidateSeName(model.SeName, collection.Name, true, _seoSettings, _slugService, _languageService); collection.SeName = model.SeName; await _collectionService.UpdateCollection(collection); await _slugService.SaveSlug(collection, model.SeName, ""); //update picture seo file name await _pictureService.UpdatePictureSeoNames(collection.PictureId, collection.Name); //activity log await _customerActivityService.InsertActivity("AddNewCollection", collection.Id, _translationService.GetResource("ActivityLog.AddNewCollection"), collection.Name); return(collection); }
public async Task <ProductDto> Handle(UpdateProductCommand request, CancellationToken cancellationToken) { //product var product = await _productService.GetProductById(request.Model.Id); var prevStockQuantity = product.StockQuantity; var prevPublished = product.Published; product = request.Model.ToEntity(product); product.UpdatedOnUtc = DateTime.UtcNow; request.Model.SeName = await product.ValidateSeName(request.Model.SeName, product.Name, true, _seoSettings, _slugService, _languageService); product.SeName = request.Model.SeName; //search engine name await _slugService.SaveSlug(product, request.Model.SeName, ""); //update product await _productService.UpdateProduct(product); if (product.ManageInventoryMethodId == ManageInventoryMethod.ManageStock && product.BackorderModeId == BackorderMode.NoBackorders && product.AllowOutOfStockSubscriptions && _stockQuantityService.GetTotalStockQuantity(product) > 0 && prevStockQuantity <= 0 && product.Published) { await _outOfStockSubscriptionService.SendNotificationsToSubscribers(product, ""); } //activity log await _customerActivityService.InsertActivity("EditProduct", product.Id, _translationService.GetResource("ActivityLog.EditProduct"), product.Name); //raise event if (!prevPublished && product.Published) { await _mediator.Publish(new ProductPublishEvent(product)); } if (prevPublished && !product.Published) { await _mediator.Publish(new ProductUnPublishEvent(product)); } return(product.ToModel()); }
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()); }
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, _slugService, _languageService); category.SeName = request.Model.SeName; await _categoryService.UpdateCategory(category); //search engine name await _slugService.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, _translationService.GetResource("ActivityLog.EditCategory"), category.Name); return(category.ToModel()); }
public async Task <CollectionDto> Handle(AddCollectionCommand request, CancellationToken cancellationToken) { var collection = request.Model.ToEntity(); collection.CreatedOnUtc = DateTime.UtcNow; collection.UpdatedOnUtc = DateTime.UtcNow; await _collectionService.InsertCollection(collection); request.Model.SeName = await collection.ValidateSeName(request.Model.SeName, collection.Name, true, _seoSettings, _slugService, _languageService); collection.SeName = request.Model.SeName; await _collectionService.UpdateCollection(collection); await _slugService.SaveSlug(collection, request.Model.SeName, ""); //activity log await _customerActivityService.InsertActivity("AddNewCollection", collection.Id, _translationService.GetResource("ActivityLog.AddNewCollection"), collection.Name); return(collection.ToModel()); }
public async Task <BrandDto> Handle(AddBrandCommand request, CancellationToken cancellationToken) { var brand = request.Model.ToEntity(); brand.CreatedOnUtc = DateTime.UtcNow; brand.UpdatedOnUtc = DateTime.UtcNow; await _brandService.InsertBrand(brand); request.Model.SeName = await brand.ValidateSeName(request.Model.SeName, brand.Name, true, _seoSettings, _slugService, _languageService); brand.SeName = request.Model.SeName; await _brandService.UpdateBrand(brand); await _slugService.SaveSlug(brand, request.Model.SeName, ""); //activity log await _customerActivityService.InsertActivity("AddNewBrand", brand.Id, _translationService.GetResource("ActivityLog.AddNewBrand"), brand.Name); return(brand.ToModel()); }
public async Task <ProductDto> Handle(AddProductCommand request, CancellationToken cancellationToken) { var product = request.Model.ToEntity(); product.CreatedOnUtc = DateTime.UtcNow; product.UpdatedOnUtc = DateTime.UtcNow; await _productService.InsertProduct(product); request.Model.SeName = await product.ValidateSeName(request.Model.SeName, product.Name, true, _seoSettings, _slugService, _languageService); product.SeName = request.Model.SeName; //search engine name await _slugService.SaveSlug(product, request.Model.SeName, ""); await _productService.UpdateProduct(product); //activity log await _customerActivityService.InsertActivity("AddNewProduct", product.Id, _translationService.GetResource("ActivityLog.AddNewProduct"), product.Name); return(product.ToModel()); }
public async Task <CategoryDto> Handle(AddCategoryCommand request, CancellationToken cancellationToken) { var category = request.Model.ToEntity(); category.CreatedOnUtc = DateTime.UtcNow; category.UpdatedOnUtc = DateTime.UtcNow; await _categoryService.InsertCategory(category); request.Model.SeName = await category.ValidateSeName(request.Model.SeName, category.Name, true, _seoSettings, _slugService, _languageService); category.SeName = request.Model.SeName; await _categoryService.UpdateCategory(category); await _slugService.SaveSlug(category, request.Model.SeName, ""); //activity log await _customerActivityService.InsertActivity("AddNewCategory", category.Id, _translationService.GetResource("ActivityLog.AddNewCategory"), category.Name); return(category.ToModel()); }
/// <summary> /// Create a copy of product with all depended data /// </summary> /// <param name="product">The product to copy</param> /// <param name="newName">The name of product duplicate</param> /// <param name="isPublished">A value indicating whether the product duplicate should be published</param> /// <param name="copyImages">A value indicating whether the product images should be copied</param> /// <param name="copyAssociatedProducts">A value indicating whether the copy associated products</param> /// <returns>Product copy</returns> public virtual async Task <Product> CopyProduct(Product product, string newName, bool isPublished = true, bool copyImages = true, bool copyAssociatedProducts = true) { if (product == null) { throw new ArgumentNullException(nameof(product)); } if (String.IsNullOrEmpty(newName)) { newName = $"{product.Name} - CopyProduct"; } //product download & sample download string downloadId = product.DownloadId; string sampleDownloadId = product.SampleDownloadId; if (product.IsDownload) { var download = await _downloadService.GetDownloadById(product.DownloadId); if (download != null) { var downloadCopy = new Download { DownloadGuid = Guid.NewGuid(), UseDownloadUrl = download.UseDownloadUrl, DownloadUrl = download.DownloadUrl, DownloadBinary = download.DownloadBinary, ContentType = download.ContentType, Filename = download.Filename, Extension = download.Extension, IsNew = download.IsNew, }; await _downloadService.InsertDownload(downloadCopy); downloadId = downloadCopy.Id; } if (product.HasSampleDownload) { var sampleDownload = await _downloadService.GetDownloadById(product.SampleDownloadId); if (sampleDownload != null) { var sampleDownloadCopy = new Download { DownloadGuid = Guid.NewGuid(), UseDownloadUrl = sampleDownload.UseDownloadUrl, DownloadUrl = sampleDownload.DownloadUrl, DownloadBinary = sampleDownload.DownloadBinary, ContentType = sampleDownload.ContentType, Filename = sampleDownload.Filename, Extension = sampleDownload.Extension, IsNew = sampleDownload.IsNew }; await _downloadService.InsertDownload(sampleDownloadCopy); sampleDownloadId = sampleDownloadCopy.Id; } } } // product var productCopy = new Product { ProductTypeId = product.ProductTypeId, ParentGroupedProductId = product.ParentGroupedProductId, VisibleIndividually = product.VisibleIndividually, Name = newName, ShortDescription = product.ShortDescription, FullDescription = product.FullDescription, Flag = product.Flag, BrandId = product.BrandId, VendorId = product.VendorId, ProductLayoutId = product.ProductLayoutId, AdminComment = product.AdminComment, ShowOnHomePage = product.ShowOnHomePage, MetaKeywords = product.MetaKeywords, MetaDescription = product.MetaDescription, MetaTitle = product.MetaTitle, AllowCustomerReviews = product.AllowCustomerReviews, LimitedToStores = product.LimitedToStores, Sku = product.Sku, Mpn = product.Mpn, Gtin = product.Gtin, IsGiftVoucher = product.IsGiftVoucher, GiftVoucherTypeId = product.GiftVoucherTypeId, OverGiftAmount = product.OverGiftAmount, RequireOtherProducts = product.RequireOtherProducts, RequiredProductIds = product.RequiredProductIds, AutoAddRequiredProducts = product.AutoAddRequiredProducts, IsDownload = product.IsDownload, DownloadId = downloadId, UnlimitedDownloads = product.UnlimitedDownloads, MaxNumberOfDownloads = product.MaxNumberOfDownloads, DownloadExpirationDays = product.DownloadExpirationDays, DownloadActivationTypeId = product.DownloadActivationTypeId, HasSampleDownload = product.HasSampleDownload, SampleDownloadId = sampleDownloadId, HasUserAgreement = product.HasUserAgreement, UserAgreementText = product.UserAgreementText, IsRecurring = product.IsRecurring, RecurringCycleLength = product.RecurringCycleLength, RecurringCyclePeriodId = product.RecurringCyclePeriodId, RecurringTotalCycles = product.RecurringTotalCycles, IsShipEnabled = product.IsShipEnabled, IsFreeShipping = product.IsFreeShipping, ShipSeparately = product.ShipSeparately, AdditionalShippingCharge = product.AdditionalShippingCharge, DeliveryDateId = product.DeliveryDateId, IsTaxExempt = product.IsTaxExempt, TaxCategoryId = product.TaxCategoryId, IsTele = product.IsTele, ManageInventoryMethodId = product.ManageInventoryMethodId, UseMultipleWarehouses = product.UseMultipleWarehouses, WarehouseId = product.WarehouseId, StockQuantity = product.StockQuantity, StockAvailability = product.StockAvailability, DisplayStockQuantity = product.DisplayStockQuantity, MinStockQuantity = product.MinStockQuantity, LowStock = product.MinStockQuantity > 0 && product.MinStockQuantity >= product.StockQuantity, LowStockActivityId = product.LowStockActivityId, NotifyAdminForQuantityBelow = product.NotifyAdminForQuantityBelow, BackorderModeId = product.BackorderModeId, AllowOutOfStockSubscriptions = product.AllowOutOfStockSubscriptions, OrderMinimumQuantity = product.OrderMinimumQuantity, OrderMaximumQuantity = product.OrderMaximumQuantity, AllowedQuantities = product.AllowedQuantities, DisableBuyButton = product.DisableBuyButton, DisableWishlistButton = product.DisableWishlistButton, AvailableForPreOrder = product.AvailableForPreOrder, PreOrderDateTimeUtc = product.PreOrderDateTimeUtc, CallForPrice = product.CallForPrice, Price = product.Price, OldPrice = product.OldPrice, CatalogPrice = product.CatalogPrice, StartPrice = product.StartPrice, ProductCost = product.ProductCost, EnteredPrice = product.EnteredPrice, MinEnteredPrice = product.MinEnteredPrice, MaxEnteredPrice = product.MaxEnteredPrice, BasepriceEnabled = product.BasepriceEnabled, BasepriceAmount = product.BasepriceAmount, BasepriceUnitId = product.BasepriceUnitId, BasepriceBaseAmount = product.BasepriceBaseAmount, BasepriceBaseUnitId = product.BasepriceBaseUnitId, MarkAsNew = product.MarkAsNew, MarkAsNewStartDateTimeUtc = product.MarkAsNewStartDateTimeUtc, MarkAsNewEndDateTimeUtc = product.MarkAsNewEndDateTimeUtc, Weight = product.Weight, Length = product.Length, Width = product.Width, Height = product.Height, AvailableStartDateTimeUtc = product.AvailableStartDateTimeUtc, AvailableEndDateTimeUtc = product.AvailableEndDateTimeUtc, DisplayOrder = product.DisplayOrder, Published = isPublished, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow, Locales = product.Locales, CustomerGroups = product.CustomerGroups, Stores = product.Stores }; // product <-> warehouses mappings foreach (var pwi in product.ProductWarehouseInventory) { productCopy.ProductWarehouseInventory.Add(pwi); } // product <-> categories mappings foreach (var productCategory in product.ProductCategories) { productCopy.ProductCategories.Add(productCategory); } // product <-> collections mappings foreach (var productCollections in product.ProductCollections) { productCopy.ProductCollections.Add(productCollections); } // product <-> releated products mappings foreach (var relatedProduct in product.RelatedProducts) { productCopy.RelatedProducts.Add(relatedProduct); } //product tags foreach (var productTag in product.ProductTags) { productCopy.ProductTags.Add(productTag); } // product <-> attributes mappings foreach (var productAttributeMapping in product.ProductAttributeMappings) { productCopy.ProductAttributeMappings.Add(productAttributeMapping); } //attribute combinations foreach (var combination in product.ProductAttributeCombinations) { productCopy.ProductAttributeCombinations.Add(combination); } foreach (var csProduct in product.CrossSellProduct) { productCopy.CrossSellProduct.Add(csProduct); } // product specifications foreach (var productSpecificationAttribute in product.ProductSpecificationAttributes) { productCopy.ProductSpecificationAttributes.Add(productSpecificationAttribute); } //tier prices foreach (var tierPrice in product.TierPrices) { productCopy.TierPrices.Add(tierPrice); } // product <-> discounts mapping foreach (var discount in product.AppliedDiscounts) { productCopy.AppliedDiscounts.Add(discount); } //validate search engine name await _productService.InsertProduct(productCopy); //search engine name string seName = await productCopy.ValidateSeName("", productCopy.Name, true, _seoSettings, _slugService, _languageService); productCopy.SeName = seName; await _productService.UpdateProduct(productCopy); await _slugService.SaveSlug(productCopy, seName, ""); var languages = await _languageService.GetAllLanguages(true); //product pictures //variable to store original and new picture identifiers int id = 1; var originalNewPictureIdentifiers = new Dictionary <string, string>(); if (copyImages) { foreach (var productPicture in product.ProductPictures) { var picture = await _pictureService.GetPictureById(productPicture.PictureId); var pictureCopy = await _pictureService.InsertPicture( await _pictureService.LoadPictureBinary(picture), picture.MimeType, _pictureService.GetPictureSeName(newName), picture.AltAttribute, picture.TitleAttribute, false, Domain.Common.Reference.Product, productCopy.Id); await _productService.InsertProductPicture(new ProductPicture { PictureId = pictureCopy.Id, DisplayOrder = productPicture.DisplayOrder }, productCopy.Id); id++; originalNewPictureIdentifiers.Add(picture.Id, pictureCopy.Id); } } return(productCopy); }
public static async Task <List <TranslationEntity> > ToTranslationProperty <T, E>(this IList <T> list, E entity, Expression <Func <T, string> > keySelector, SeoSettings _seoSettings, ISlugService _slugService, ILanguageService _languageService) where T : ILocalizedModelLocal where E : BaseEntity, ISlugEntity { var local = new List <TranslationEntity>(); foreach (var item in list) { Type[] interfaces = item.GetType().GetInterfaces(); PropertyInfo[] props = item.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy); foreach (var prop in props) { bool insert = true; foreach (var i in interfaces) { if (i.HasProperty(prop.Name) && typeof(ILocalizedModelLocal).IsAssignableFrom(i)) { insert = false; } if (i.HasProperty(prop.Name) && typeof(ISlugModelLocal).IsAssignableFrom(i)) { var member = keySelector.Body as MemberExpression; if (member == null) { throw new ArgumentException($"Expression '{keySelector}' refers to a method, not a property."); } var propInfo = member.Member as PropertyInfo; if (propInfo == null) { throw new ArgumentException($"Expression '{keySelector}' refers to a field, not a property."); } var value = item.GetType().GetProperty(propInfo.Name).GetValue(item, null); if (value != null) { var name = value.ToString(); var itemvalue = prop.GetValue(item) ?? ""; var seName = await entity.ValidateSeName(itemvalue.ToString(), name, false, _seoSettings, _slugService, _languageService); prop.SetValue(item, seName); await _slugService.SaveSlug(entity, seName, item.LanguageId); } else { var itemvalue = prop.GetValue(item) ?? ""; if (itemvalue != null && !string.IsNullOrEmpty(itemvalue.ToString())) { var seName = await entity.ValidateSeName(itemvalue.ToString(), "", false, _seoSettings, _slugService, _languageService); prop.SetValue(item, seName); await _slugService.SaveSlug(entity, seName, item.LanguageId); } else { insert = false; } } } } if (insert && prop.GetValue(item) != null) { local.Add(new TranslationEntity() { LanguageId = item.LanguageId, LocaleKey = prop.Name, LocaleValue = prop.GetValue(item).ToString(), }); } } } return(local); }
public virtual async Task <IActionResult> ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid, IFormFile uploadedFile) { if (!_vendorSettings.AllowCustomersToApplyForVendorAccount) { return(RedirectToRoute("HomePage")); } if (!await _groupService.IsRegistered(_workContext.CurrentCustomer)) { return(Challenge()); } //validate CAPTCHA if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid) { ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_translationService)); } string pictureId = string.Empty; string contentType = string.Empty; byte[] vendorPictureBinary = null; if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName)) { try { contentType = uploadedFile.ContentType; if (string.IsNullOrEmpty(contentType)) { ModelState.AddModelError("", "Empty content type"); } else if (!contentType.StartsWith("image")) { ModelState.AddModelError("", "Only image content type is allowed"); } vendorPictureBinary = uploadedFile.GetPictureBits(); } catch (Exception) { ModelState.AddModelError("", _translationService.GetResource("Vendors.ApplyAccount.Picture.ErrorMessage")); } } if (ModelState.IsValid) { var description = FormatText.ConvertText(model.Description); var address = new Address(); //disabled by default var vendor = new Vendor { Name = model.Name, Email = model.Email, Description = description, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = _vendorSettings.DefaultVendorPageSizeOptions, AllowCustomerReviews = _vendorSettings.DefaultAllowCustomerReview, }; model.Address.ToEntity(vendor.Address, true); if (vendorPictureBinary != null && !string.IsNullOrEmpty(contentType)) { var picture = await _pictureService.InsertPicture(vendorPictureBinary, contentType, null, reference : Reference.Vendor, objectId : vendor.Id); if (picture != null) { vendor.PictureId = picture.Id; } } await _vendorService.InsertVendor(vendor); //search engine name (the same as vendor name) var seName = await vendor.ValidateSeName(vendor.Name, vendor.Name, true, HttpContext.RequestServices.GetRequiredService <SeoSettings>(), HttpContext.RequestServices.GetRequiredService <ISlugService>(), HttpContext.RequestServices.GetRequiredService <ILanguageService>()); await _slugService.SaveSlug(vendor, seName, ""); vendor.SeName = seName; await _vendorService.UpdateVendor(vendor); //associate to the current customer //but a store owner will have to manually acivate this vendor //if he wants to grant access to admin area _workContext.CurrentCustomer.VendorId = vendor.Id; await _customerService.UpdateCustomerField(_workContext.CurrentCustomer.Id, x => x.VendorId, _workContext.CurrentCustomer.VendorId); //notify store owner here (email) await _messageProviderService.SendNewVendorAccountApplyStoreOwnerMessage(_workContext.CurrentCustomer, vendor, _workContext.CurrentStore, _languageSettings.DefaultAdminLanguageId); model.DisableFormInput = true; model.Result = _translationService.GetResource("Vendors.ApplyAccount.Submitted"); return(View(model)); } //If we got this far, something failed, redisplay form model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage; model.TermsOfServiceEnabled = _vendorSettings.TermsOfServiceEnabled; model.TermsOfServicePopup = _commonSettings.PopupForTermsOfServiceLinks; var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id, _workContext.CurrentStore.Id); model.Address = await _mediator.Send(new GetVendorAddress() { Language = _workContext.WorkingLanguage, Address = null, Model = model.Address, ExcludeProperties = false, PrePopulateWithCustomerFields = true, Customer = _workContext.CurrentCustomer, LoadCountries = () => countries, }); return(View(model)); }