public ActionResult Index(string id)
        {
            ImagePickerViewModel viewModel = GetFilesInternal(id, "/upload");

            SortImages(SortOrder.DateDesc, viewModel);
            return(View(viewModel));
        }
        public JsonResult GetFiles(string id, FormCollection collection)
        {
            string virtualPath             = collection["path"];
            ImagePickerViewModel viewModel = GetFilesInternal(id, virtualPath);

            SortImages(GetSortOrder(collection), viewModel);
            return(Json(viewModel));
        }
Exemplo n.º 3
0
        public ImagePickerWindow(Action <string> select)
        {
            InitializeComponent();
            this.select = select;
            var picker = new ImagePickerViewModel(Select);

            picker.Update(false);
            view.DataContext = picker;
        }
        public ActionResult UploadFile(HttpPostedFileBase file)
        {
            string virtualPath = HttpContext.Request.Form["virtualPath"];
            string filePath    = virtualPath.TrimEnd('/') + "/" + file.FileName;

            N2.Context.Current.Resolve <IFileSystem>().WriteFile(filePath, file.InputStream);
            ImagePickerViewModel viewModel = GetFilesInternal("0", virtualPath);

            SortImages(SortOrder.DateDesc, viewModel);
            return(View("Index", viewModel));
        }
        public JsonResult Search(string id, FormCollection collection)
        {
            string virtualPath    = collection["virtualPath"];
            string searchCriteria = collection["searchCriteria"];

            searchCriteria = searchCriteria.ToLower(Thread.CurrentThread.CurrentCulture);
            var viewModel = new ImagePickerViewModel(id, virtualPath);

            RecursiveSearch(N2.Context.Current.Resolve <IFileSystem>(), searchCriteria, virtualPath, viewModel);
            SortImages(GetSortOrder(collection), viewModel);
            return(Json(viewModel));
        }
        private void SortImages(SortOrder so, ImagePickerViewModel viewModel)
        {
            switch (so)
            {
            case SortOrder.DateAsc:
                viewModel.Images.Sort(new DateAscComparer());
                break;

            case SortOrder.DateDesc:
                viewModel.Images.Sort(new DateDescComparer());
                break;
            }
        }
        private ImagePickerViewModel GetFilesInternal(string id, string virtualPath)
        {
            var viewModel = new ImagePickerViewModel(id, virtualPath);
            var fs        = N2.Context.Current.Resolve <IFileSystem>();

            foreach (DirectoryData directory in fs.GetDirectories(virtualPath))
            {
                viewModel.Images.Add(DirectoryToImageViewModel(directory));
            }
            foreach (FileData file in fs.GetFiles(virtualPath))
            {
                viewModel.Images.Add(FileToImageViewModel(file));
            }
            return(viewModel);
        }
 private void RecursiveSearch(IFileSystem fs, string searchCriteria, string virtualPath, ImagePickerViewModel viewModel)
 {
     foreach (var file in fs.GetFiles(virtualPath))
     {
         if (file.Name.ToLower(Thread.CurrentThread.CurrentCulture).Contains(searchCriteria))
         {
             viewModel.Images.Add(FileToImageViewModel(file));
         }
     }
     foreach (var dir in fs.GetDirectories(virtualPath))
     {
         if (dir.VirtualPath != virtualPath)
         {
             RecursiveSearch(fs, searchCriteria, dir.VirtualPath, viewModel);
         }
     }
 }