Ejemplo n.º 1
0
        public ActionResult Browse(string location)
        {
            // lookup data in the system to collect physical entry
            var vm = new DocumentsSelectionViewModel();

            if (string.IsNullOrEmpty(location) || location.Equals(_home))
            {
                vm.CurrLocation = _home;
                // parent is null
                vm.Documents = new List<DocumentViewModel>();
                var docs = _uow.Documents.AllIncluding(o => o.Owner).Where(d => d.Parent == null && d.Owner.Id == _user.User.Id).OrderByDescending(o => o.IsFolder).ThenBy(o => o.Name);

                foreach (var item in docs)
                {
                    vm.Documents.Add(AutoMapper.Mapper.Map<Doc, DocumentViewModel>(item));
                }
            }
            else
            {
                vm.CurrLocation = Request.RequestContext.RouteData.Values["location"].ToString();
                vm.Documents = new List<DocumentViewModel>();
                var docs = _uow.Documents.AllIncluding(o => o.Owner).Where(d => d.Location == location && d.Owner.Id == _user.User.Id).OrderByDescending(o => o.IsFolder).ThenBy(o => o.Name);

                foreach (var item in docs)
                {
                    vm.Documents.Add(AutoMapper.Mapper.Map<Doc, DocumentViewModel>(item));
                }
            }

            //var _name = location.Substring(location.LastIndexOf('/') + 1);
            //var _location = location.Substring(0, location.LastIndexOf('/') + 1);

            //var items = new List<BreadItemViewModel>();
            //var current = _uow.Documents.FilterBy(d => d.Location == _location && d.Name == _name).FirstOrDefault();
            //ViewData["breadcums"] = current.GetHierachy().Select(d => new FolderViewModel
            //{
            //    Name = d.Name,
            //    Location = d.Location
            //});

            return View(vm);
        }
Ejemplo n.º 2
0
        public async Task<ActionResult> Browse(DocumentsSelectionViewModel model)
        {
            //var selectedIds = model.GetSelectedIds();
            //var files = new List<string>();
            //foreach (var id in selectedIds)
            //{
            //    var doc = await _uow.Documents.FindAsyncById(id);
            //    files.Add(doc.Path);
            //}
            //return new ZipActionResult(files);

            var selectedIds = model.GetSelectedIds();
            foreach (var id in selectedIds)
            {
                var doc = await _uow.Documents.FindAsyncById(id);
                if (!doc.IsFolder)
                {
                    System.IO.File.Delete(doc.Path);
                    _uow.Documents.Remove(doc);
                    await _uow.SaveAsync();
                }
                else
                    await DeleteFolder(id);
            }
            return RedirectToAction<DocumentController>(d => d.Browse(_home));
        }