public string ImportPictures(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { var pictureData = dataReader.GetPictureData(); var mediaCategory = _getByUrl.GetByUrl(NopProductImages); if (mediaCategory == null) { mediaCategory = new MediaCategory { Name = "Nop Product Images", UrlSegment = NopProductImages, IsGallery = false, HideInAdminNav = false }; _mediaCategoryAdminService.Add(mediaCategory); } foreach (var data in pictureData) { using (var fileData = data.GetData()) { var memoryStream = new MemoryStream(); fileData.CopyTo(memoryStream); memoryStream.Position = 0; var mediaFile = _fileService.AddFile(memoryStream, data.FileName, data.ContentType, memoryStream.Length, mediaCategory); nopImportContext.AddEntry(data.Id, mediaFile); } } return(string.Format("{0} pictures imported", pictureData.Count)); }
public void MediaCategoryController_AddPost_ShouldCallSaveDocument() { var mediaCategory = new MediaCategory(); _mediaCategoryController.Add(mediaCategory); A.CallTo(() => _mediaCategoryAdminService.Add(mediaCategory)).MustHaveHappened(Repeated.Exactly.Once); }
public void Execute(OnAddingArgs <Product> args) { var product = args.Item; if (!product.Variants.Any()) { var productVariant = new ProductVariant { Name = product.Name, TrackingPolicy = TrackingPolicy.DontTrack, }; product.Variants.Add(productVariant); productVariant.Product = product; _session.Transact(s => s.Save(productVariant)); } var mediaCategory = _mediaCategoryByUrl.GetByUrl("product-galleries"); if (mediaCategory == null) { mediaCategory = new MediaCategory { Name = "Product Galleries", UrlSegment = "product-galleries", IsGallery = true, HideInAdminNav = true }; _mediaCategoryAdminService.Add(mediaCategory); } var productGallery = new MediaCategory { Name = product.Name, UrlSegment = "product-galleries/" + product.UrlSegment, IsGallery = true, Parent = mediaCategory, HideInAdminNav = true }; product.Gallery = productGallery; _mediaCategoryAdminService.Add(productGallery); }
public ActionResult Add(MediaCategory doc) { _mediaCategoryAdminService.Add(doc); TempData.SuccessMessages().Add(string.Format("{0} successfully added", doc.Name)); return(RedirectToAction("Show", new { id = doc.Id })); }
/// <summary> /// Import from DTOs /// </summary> /// <param name="dataTransferObject"></param> public Product ImportProduct(ProductImportDataTransferObject dataTransferObject) { var uniquePage = _uniquePageService.GetUniquePage <ProductContainer>(); var productGalleriesCategory = _getByUrl.GetByUrl("product-galleries"); if (productGalleriesCategory == null) { productGalleriesCategory = new MediaCategory { Name = "Product Galleries", UrlSegment = "product-galleries", IsGallery = true, HideInAdminNav = true }; _mediaCategoryAdminService.Add(productGalleriesCategory); } Product product = _session.Query <Product>() .SingleOrDefault(x => x.UrlSegment == dataTransferObject.UrlSegment) ?? new Product(); product.Parent = uniquePage; product.UrlSegment = dataTransferObject.UrlSegment; product.Name = dataTransferObject.Name; product.BodyContent = dataTransferObject.Description; product.MetaTitle = dataTransferObject.SEOTitle; product.MetaDescription = dataTransferObject.SEODescription; product.MetaKeywords = dataTransferObject.SEOKeywords; product.ProductAbstract = dataTransferObject.Abstract; product.SearchResultAbstract = dataTransferObject.SearchResultAbstract; product.PublishOn = dataTransferObject.PublishDate; bool isNew = false; MediaCategory productGallery = product.Gallery ?? new MediaCategory(); if (product.Id == 0) { isNew = true; product.DisplayOrder = GetParentQuery(uniquePage).Any() ? GetParentQuery(uniquePage) .Select(Projections.Max <Webpage>(webpage => webpage.DisplayOrder)) .SingleOrDefault <int>() : 0; productGallery.Name = product.Name; productGallery.UrlSegment = "product-galleries/" + product.UrlSegment; productGallery.IsGallery = true; productGallery.Parent = productGalleriesCategory; productGallery.HideInAdminNav = true; product.Gallery = productGallery; } SetBrand(dataTransferObject, product); SetCategories(dataTransferObject, product); SetOptions(dataTransferObject, product); ////Url History _importUrlHistoryService.ImportUrlHistory(dataTransferObject, product); ////Specifications _importSpecificationsService.ImportSpecifications(dataTransferObject, product); ////Variants _importProductVariantsService.ImportVariants(dataTransferObject, product); if (isNew) { _session.Transact(session => session.Save(product)); _session.Transact(session => session.Save(productGallery)); } else { _session.Transact(session => session.Update(product)); _session.Transact(session => session.Update(productGallery)); } _importProductImagesService.ImportProductImages(dataTransferObject.Images, product.Gallery); return(product); }