Example #1
0
        public ActionResult Edit(long id)
        {
            var folder = folderRepository.Load(id);
            var model  = new FolderEditViewModel
            {
                CurrentFolder = folder,
                Name          = folder.Name
            };

            return(PartialView(model));
        }
        public async Task <ActionResult> EditFolder(FolderEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ModelState.ToDictionary()));
            }

            var editedFolder = await _folderManager.Edit(model, User.Identity.GetUserId());

            return(Json(editedFolder));
        }
Example #3
0
        public ActionResult Create(FolderEditViewModel model)
        {
            var parent = model.ParentFolder != null && model.ParentFolder.FolderID > 0 ?
                         folderRepository.Load(model.ParentFolder.FolderID) :
                         null;
            var folder = new Folder
            {
                Foldername   = model.Name,
                ParentFolder = parent
            };

            folderRepository.Save(folder);
            return(RedirectToAction("Index", new { id = parent != null ? parent.FolderID : folder.FolderID }));
        }
 public IActionResult EditFolder(FolderEditViewModel model)
 {
     if (ModelState.IsValid)
     {
         FolderDTO folder = new FolderDTO {
             Id       = model.Id,
             Name     = model.Name,
             FolderId = model.FolderId
         };
         try {
             folderService.EditFolder(folder);
         } catch (UnauthorizedAccessException) {
             return(StatusCode(StatusCodes.Status403Forbidden));
         }
         return(RedirectToAction(nameof(Drive), new { id = folder.FolderId }));
     }
     return(View(model));
 }
        public IActionResult EditFolder(int id)
        {
            FolderDTO folder;

            try {
                folder = folderService.GetFolder(id);
            } catch (UnauthorizedAccessException) {
                return(StatusCode(StatusCodes.Status403Forbidden));
            }
            if (folder != null)
            {
                FolderEditViewModel model = new FolderEditViewModel {
                    Id           = folder.Id,
                    Name         = folder.Name,
                    FilesCount   = folder.Elements.OfType <FileDTO>().Count(),
                    FoldersCount = folder.Elements.OfType <FolderDTO>().Count(),
                    Size         = folder.Size,
                    FolderId     = folder.FolderId ?? 0
                };
                return(View(model));
            }
            return(NotFound($"Folder with id {id} doesn't exists"));
        }
Example #6
0
        public async Task <FolderListViewModel> Edit(FolderEditViewModel model, string agentId)
        {
            if (string.IsNullOrEmpty(agentId))
            {
                throw new NotAuthorizedUserException("Само потребители могат да редактират папки!");
            }

            if (!await _userManager.IsInRoleAsync(agentId, Enum.GetName(typeof(Role), Role.Administrator)) &&
                !await _userManager.IsInRoleAsync(agentId, Enum.GetName(typeof(Role), Role.Agent)) &&
                !await _userManager.IsInRoleAsync(agentId, Enum.GetName(typeof(Role), Role.Maintenance)))
            {
                throw new NotAuthorizedUserException("Нямате право да извършвате това действие!");
            }

            if (!await Exist(folderId: model.Id))
            {
                throw new ArgumentException("Не съществува папка с това име в системата!");
            }


            var folderToEdit = await _dbContext.Folders.FirstOrDefaultAsync(f => f.Id == model.Id)
                               ?? throw new ContentNotFoundException("Не е намерена папката, която искате да редактирате!");

            if (folderToEdit.AgentId != agentId && !await _userManager.IsInRoleAsync(agentId, Enum.GetName(typeof(Role), Role.Administrator)))
            {
                throw new NotAuthorizedUserException("Трябва да сте собственик на папката или админ за да я редактирате!");
            }

            if (await Exist(folderName: model.Name, parentId: folderToEdit.ParentId))
            {
                throw new ArgumentException("Съществува папка с това име в папка!");
            }

            if (folderToEdit.Name != model.Name)
            {
                var newFolderName         = model.Name;
                var parentDirOfCurrentDir = Path.GetDirectoryName(folderToEdit.RelativePath);

                var newRelativePath = Path.Combine(parentDirOfCurrentDir ?? _baseMaterialsPath, newFolderName);
                var oldRelativePath = folderToEdit.RelativePath;

                await MoveAllChildren(oldRelativePath, newRelativePath);

                // change name in DB
                _dbContext.Folders.Attach(folderToEdit);
                folderToEdit.Name         = newFolderName;
                folderToEdit.RelativePath = newRelativePath;
                await _dbContext.SaveChangesAsync();



                var systemRoot = HttpRuntime.AppDomainAppPath;

                var newPhysicalPath = Path.Combine(systemRoot.TrimEnd('\\', '/'), newRelativePath.TrimStart('\\', '/'));
                var oldPhysicalPath = Path.Combine(systemRoot.TrimEnd('\\', '/'), oldRelativePath.TrimStart('\\', '/'));

                //Change the name in the file system
                Directory.Move(oldPhysicalPath, newPhysicalPath);
            }

            return(await Get(model.Id, agentId));
        }