public virtual ActionResult Add(MediaCategory doc)
 {
     _documentService.AddDocument(doc);
     _fileAdminService.CreateFolder(doc);
     TempData.SuccessMessages().Add(string.Format("{0} successfully added", doc.Name));
     return RedirectToAction("Show", new { id = doc.Id });
 }
Beispiel #2
0
        public string ImportPictures(NopCommerceDataReader dataReader, NopImportContext nopImportContext)
        {
            var pictureData = dataReader.GetPictureData();

            var mediaCategory = _documentService.GetDocumentByUrl<MediaCategory>(NopProductImages);
            if (mediaCategory == null)
            {
                mediaCategory = new MediaCategory
                {
                    Name = "Nop Product Images",
                    UrlSegment = NopProductImages,
                    IsGallery = false,
                    HideInAdminNav = false
                };
                _documentService.AddDocument(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);
        }
Beispiel #3
0
        public void Setup()
        {
            _session.Transact(session =>
            {
                var defaultMediaCategory = new MediaCategory
                {
                    Name = "Default",
                    UrlSegment = "default",
                };
                session.Save(defaultMediaCategory);
                var mediaSettings = _configurationProvider.GetSiteSettings<MediaSettings>();
                _configurationProvider.SaveSettings(mediaSettings);

                string logoPath = HttpContext.Current.Server.MapPath("/Apps/Core/Content/images/mrcms-logo.png");
                var fileStream = new FileStream(logoPath, FileMode.Open);
                MediaFile dbFile = _fileService.AddFile(fileStream, Path.GetFileName(logoPath), "image/png",
                    fileStream.Length,
                    defaultMediaCategory);

                string logoPath1 = HttpContext.Current.Server.MapPath("/Apps/Core/Content/Images/mrcms-hat.gif");
                var fileStream1 = new FileStream(logoPath1, FileMode.Open);
                MediaFile dbFile1 = _fileService.AddFile(fileStream1, Path.GetFileName(logoPath1), "image/gif",
                    fileStream1.Length,
                    defaultMediaCategory);
            });
        }
        /// <summary>
        /// Add image to Product Gallery
        /// </summary>
        /// <param name="fileLocation"></param>
        /// <param name="mediaCategory"></param>
        public bool ImportImageToGallery(string fileLocation, MediaCategory mediaCategory)
        {
            // rather than using webclient, this has been refactored to use HttpWebRequest/Response 
            // so that we can get the content type from the response, rather than assuming it
            try
            {
                var httpWebRequest = HttpWebRequest.Create(fileLocation) as HttpWebRequest;

                var httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
                using (var responseStream = httpWebResponse.GetResponseStream())
                {
                    var memoryStream = new MemoryStream();
                    responseStream.CopyTo(memoryStream);
                    memoryStream.Position = 0;

                    var fileName = Path.GetFileName(fileLocation);
                    _fileService.AddFile(memoryStream, fileName, httpWebResponse.ContentType,
                                         (int)memoryStream.Length, mediaCategory);
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public void MediaCategoryController_EditGet_ShouldReturnLayoutAsViewModel()
        {
            var mediaCategory = new MediaCategory {Id = 1};

            var result = _mediaCategoryController.Edit_Get(mediaCategory) as ViewResult;

            result.Model.Should().Be(mediaCategory);
        }
        public void MediaCategoryController_AddPost_ShouldCallSaveDocument()
        {
            var mediaCategory = new MediaCategory();

            _mediaCategoryController.Add(mediaCategory);

            A.CallTo(() => _documentService.AddDocument(mediaCategory)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public void MediaCategoryController_AddPost_ShouldRedirectToShow()
        {
            var mediaCategory = new MediaCategory {Id = 1};

            var result = _mediaCategoryController.Add(mediaCategory) as RedirectToRouteResult;

            result.RouteValues["action"].Should().Be("Show");
            result.RouteValues["id"].Should().Be(1);
        }
        public void MediaCategoryController_AddGet_ShouldSetParentOfModelToModelInMethod()
        {
            var mediaCategory = new MediaCategory {Id = 1};
            A.CallTo(() => _documentService.GetDocument<MediaCategory>(1)).Returns(mediaCategory);

            var actionResult = _mediaCategoryController.Add_Get(1) as ViewResult;

            actionResult.Model.As<MediaCategory>().Parent.Should().Be(mediaCategory);
        }
        public ActionResult Add_Get(int? id)
        {
            //Build list 
            var model = new MediaCategory
            {
                Parent = id.HasValue ? _documentService.GetDocument<MediaCategory>(id.Value) : null
            };

            return View(model);
        }
Beispiel #10
0
        public MediaFile AddFile(Stream stream, string fileName, string contentType, long contentLength, MediaCategory mediaCategory = null)
        {
            fileName = Path.GetFileName(fileName);

            fileName = fileName.GetTidyFileName();

            var mediaFile = new MediaFile
            {
                FileName = fileName,
                ContentType = contentType,
                ContentLength = contentLength,
                FileExtension = Path.GetExtension(fileName),
            };
            if (mediaCategory != null)
            {
                mediaFile.MediaCategory = mediaCategory;
                int? max = _session.Query<MediaFile>().Where(x => x.MediaCategory.Id == mediaFile.MediaCategory.Id).Max(x => (int?)x.DisplayOrder);
                mediaFile.DisplayOrder = (max.HasValue ? (int)max + 1 : 1);
            }

            if (mediaFile.IsImage())
            {
                if (mediaFile.IsJpeg())
                {
                    _imageProcessor.EnforceMaxSize(ref stream, mediaFile, _mediaSettings);
                }
                _imageProcessor.SetFileDimensions(mediaFile, stream);
            }

            var fileLocation = GetFileLocation(fileName, mediaCategory);

            mediaFile.FileUrl = _fileSystem.SaveFile(stream, fileLocation, contentType);

            _session.Transact(session =>
            {
                session.Save(mediaFile);
                if (mediaCategory != null)
                {
                    mediaCategory.Files.Add(mediaFile);
                    session.SaveOrUpdate(mediaCategory);
                }
            });

            stream.Dispose();
            return mediaFile;
        }
Beispiel #11
0
        public List<ImageSortItem> GetFilesToSort(MediaCategory category = null)
        {
            IQueryOver<MediaFile, MediaFile> query = _session.QueryOver<MediaFile>();
            query = category != null
                ? query.Where(file => file.MediaCategory.Id == category.Id)
                : query.Where(file => file.MediaCategory == null);
            query = query.OrderBy(x => x.DisplayOrder).Asc;

            ImageSortItem item = null;
            return query.SelectList(builder =>
            {
                builder.Select(file => file.FileName).WithAlias(() => item.Name);
                builder.Select(file => file.Id).WithAlias(() => item.Id);
                builder.Select(file => file.DisplayOrder).WithAlias(() => item.Order);
                builder.Select(file => file.FileExtension).WithAlias(() => item.FileExtension);
                builder.Select(file => file.FileUrl).WithAlias(() => item.ImageUrl);
                return builder;
            }).TransformUsing(Transformers.AliasToBean<ImageSortItem>())
                .List<ImageSortItem>().ToList();
        }
Beispiel #12
0
 private IEnumerable<MediaCategory> GetMediaCategoryCopies(Site @from, Site to, SiteCloneContext siteCloneContext, MediaCategory fromParent = null, MediaCategory toParent = null)
 {
     IQueryOver<MediaCategory, MediaCategory> queryOver =
         _session.QueryOver<MediaCategory>().Where(layout => layout.Site.Id == @from.Id);
     queryOver = fromParent == null
         ? queryOver.Where(layout => layout.Parent == null)
         : queryOver.Where(layout => layout.Parent.Id == fromParent.Id);
     IList<MediaCategory> categories = queryOver.List();
     foreach (MediaCategory category in categories)
     {
         MediaCategory copy = category.GetCopyForSite(to);
         siteCloneContext.AddEntry(category, copy);
         copy.Parent = toParent;
         yield return copy;
         foreach (MediaCategory child in GetMediaCategoryCopies(@from, to, siteCloneContext, fromParent: category, toParent: copy))
         {
             yield return child;
         }
     }
 }
        /// <summary>
        /// Add Product Images
        /// </summary>
        /// <param name="dataTransferObject"></param>
        /// <param name="product"></param>
        public IEnumerable<MediaFile> ImportProductImages(List<string> images, MediaCategory mediaCategory)
        {
            // We want to always look at all of the urls in the file, and only not import when it is set to update = no
            foreach (var imageUrl in images)
            {
                Uri result;
                if (Uri.TryCreate(imageUrl, UriKind.Absolute, out result))
                {
                    // substring(1) should remove the leading ? 
                    if (!String.IsNullOrWhiteSpace(result.Query))
                    {
                        if (result.Query.Contains("update=no"))
                        {
                            continue;
                        }
                    }
                    var resultWithOutQuery = !string.IsNullOrEmpty(result.Query) ? result.ToString().Replace(result.Query, "") : result.ToString();
                    ImportImageToGallery(resultWithOutQuery, mediaCategory);
                }
            }

            return mediaCategory.Files;
        }
Beispiel #14
0
 public void MoveFiles(IEnumerable<MediaFile> files, MediaCategory parent = null)
 {
     if (files != null)
     {
         _session.Transact(session => files.ForEach(item =>
         {
             var mediaFile = session.Get<MediaFile>(item.Id);
             mediaFile.MediaCategory = parent;
             session.Update(mediaFile);
         }));
     }
 }
Beispiel #15
0
 public string MoveFolders(IEnumerable<MediaCategory> folders, MediaCategory parent = null)
 {
     string message = string.Empty;
     if (folders != null)
     {
         _session.Transact(s => folders.ForEach(item =>
         {
             var mediaFolder = s.Get<MediaCategory>(item.Id);
             if (parent != null && mediaFolder.Id != parent.Id)
             {
                 mediaFolder.Parent = parent;
                 s.Update(mediaFolder);
             }
             else if (parent == null)
             {
                 mediaFolder.Parent = null;
                 s.Update(mediaFolder);
             }
             else
             {
                 message = _stringResourceProvider.GetValue("Cannot move folder to the same folder");
             }
         }));
     }
     return message;
 }
Beispiel #16
0
 public void CreateFolder(MediaCategory category)
 {
     _fileService.CreateFolder(category);
 }
Beispiel #17
0
 public virtual ActionResult Delete(MediaCategory document)
 {
     _documentService.DeleteDocument(document);
     TempData.InfoMessages().Add(string.Format("{0} deleted", document.Name));
     return RedirectToAction("Index");
 }
Beispiel #18
0
 public virtual ActionResult Delete_Get(MediaCategory document)
 {
     return PartialView(document);
 }
Beispiel #19
0
 public virtual ActionResult Edit(MediaCategory doc)
 {
     _documentService.SaveDocument(doc);
     TempData.SuccessMessages().Add(string.Format("{0} successfully saved", doc.Name));
     return RedirectToAction("Show", new { id = doc.Id });
 }
        public void MediaCategoryController_EditPost_ShouldRedirectToEdit()
        {
            var mediaCategory = new MediaCategory {Id = 1};

            ActionResult actionResult = _mediaCategoryController.Edit(mediaCategory);

            actionResult.Should().BeOfType<RedirectToRouteResult>();
            (actionResult as RedirectToRouteResult).RouteValues["action"].Should().Be("Show");
            (actionResult as RedirectToRouteResult).RouteValues["id"].Should().Be(1);
        }
        private MediaCategory GetProductGallery()
        {
            var gallery = new MediaCategory()
                {
                    Id = 1,
                    Name = "Product Gallery"
                };
            var mediaFile = new MediaFile
            {
                FileUrl = "http://www.thought.co.uk/Content/images/logo-white.png",
                FileName = "logo-white.png",
                ContentType = "image/png",
                MediaCategory = gallery,
                FileExtension = Path.GetExtension("logo-white.png")
            };
            gallery.Files.Add(mediaFile);

            return gallery;
        }
Beispiel #22
0
 public ActionResult SortFiles(MediaCategory parent, List<SortItem> items)
 {
     _fileAdminService.SetOrders(items);
     return RedirectToAction("SortFiles", new { id = parent.Id });
 }
        public void ImportProductsService_ImportProduct_ShouldSetProductPrimaryProperties()
        {
            var product = new ProductImportDataTransferObject
            {
                UrlSegment = "test-url",
                Name = "Test Product",
                Abstract = "Test Abstract",
                Description = "Test Description",
                SEODescription = "Test SEO Description",
                SEOKeywords = "Test, Thought",
                SEOTitle = "Test SEO Title"
            };

            ProductContainer container = new ProductContainer().PersistTo(Session);
            A.CallTo(() => _uniquePageService.GetUniquePage<ProductContainer>()).Returns(container);
            MediaCategory category = new MediaCategory().PersistTo(Session);
            A.CallTo(() => _documentService.GetDocumentByUrl<MediaCategory>("product-galleries")).Returns(category);

            Product result = _importProductsService.ImportProduct(product);

            result.UrlSegment.ShouldBeEquivalentTo("test-url");
            result.Name.ShouldBeEquivalentTo("Test Product");
            result.ProductAbstract.ShouldBeEquivalentTo("Test Abstract");
            result.BodyContent.ShouldBeEquivalentTo("Test Description");
            result.MetaDescription.ShouldBeEquivalentTo("Test SEO Description");
            result.MetaKeywords.ShouldBeEquivalentTo("Test, Thought");
            result.MetaTitle.ShouldBeEquivalentTo("Test SEO Title");
        }
        /// <summary>
        ///     Import from DTOs
        /// </summary>
        /// <param name="dataTransferObject"></param>
        public Product ImportProduct(ProductImportDataTransferObject dataTransferObject)
        {
            var uniquePage = _uniquePageService.GetUniquePage<ProductContainer>();
            var productGalleriesCategory = _documentService.GetDocumentByUrl<MediaCategory>("product-galleries");
            if (productGalleriesCategory == null)
            {
                productGalleriesCategory = new MediaCategory
                {
                    Name = "Product Galleries",
                    UrlSegment = "product-galleries",
                    IsGallery = true,
                    HideInAdminNav = true
                };
                _documentService.AddDocument(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.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;
        }
Beispiel #25
0
 public ViewDataUploadFilesResult AddFile(Stream stream, string fileName, string contentType, long contentLength,
     MediaCategory mediaCategory)
 {
     MediaFile mediaFile = _fileService.AddFile(stream, fileName, contentType, contentLength, mediaCategory);
     return mediaFile.GetUploadFilesResult();
 }
Beispiel #26
0
 public virtual ActionResult Edit_Get(MediaCategory doc)
 {
     return View(doc);
 }
Beispiel #27
0
 public ActionResult ShowFilesSimple(MediaCategory category)
 {
     return PartialView(category);
 }
Beispiel #28
0
 private MediaCategory CreateFileUploadMediaCategory()
 {
     var mediaCategory = new MediaCategory { UrlSegment = "file-uploads", Name = "File Uploads" };
     _documentService.AddDocument(mediaCategory);
     return mediaCategory;
 }
Beispiel #29
0
        public void FileController_FilesPost_CallsAddFileForTheUploadedFileIfIsValidFile()
        {
            FileController fileController = GetFileController();
            var httpRequestBase = A.Fake<HttpRequestBase>();
            var memoryStream = new MemoryStream();
            string fileName = "test.txt";
            string contentType = "text/plain";
            int contentLength = 0;
            var httpFileCollectionWrapper =
                new FakeHttpFileCollectionBase(new Dictionary<string, HttpPostedFileBase>
                                                   {
                                                       {
                                                           "test",
                                                           new FakeHttpPostedFileBase(memoryStream, fileName,
                                                                                      contentType, contentLength)
                                                       }
                                                   });
            A.CallTo(() => httpRequestBase.Files).Returns(httpFileCollectionWrapper);
            A.CallTo(() => fileAdminService.IsValidFileType("test.txt")).Returns(true);
            fileController.RequestMock = httpRequestBase;

            var mediaCategory = new MediaCategory();
            fileController.Files_Post(mediaCategory);

            A.CallTo(() => fileAdminService.AddFile(memoryStream, fileName, contentType, contentLength, mediaCategory))
             .MustHaveHappened();
        }
Beispiel #30
0
        public ActionResult SortFiles(MediaCategory parent)
        {
            ViewData["categoryId"] = parent.Id;
            List<ImageSortItem> sortItems = _fileAdminService.GetFilesToSort(parent);

            return View(sortItems);
        }