Example #1
0
        public IActionResult Rename(string n)
        {
            var name = _fileService.RetrieveAbsoluteFromSystemPath(n);

            ViewData["path"] = name;
            var rfm = new RenameFileModel
            {
                IsDirectory        = IsDirectory(name),
                OldName            = name,
                AbsoluteParentPath = Directory.GetParent(name).FullName,
                ReturnUrl          = Directory.GetParent(n).Name
            };

            Log.Information("Directory created.");

            return(View(rfm));
        }
Example #2
0
        public IActionResult Rename(RenameFileModel rfm)
        {
            if (!string.IsNullOrEmpty(rfm.NewName))
            {
                var isRenamed = _fileService.Move(Path.Combine(rfm.AbsoluteParentPath, rfm.OldName), Path.Combine(rfm.AbsoluteParentPath, rfm.NewName));
                if (!isRenamed)
                {
                    ReturnMessage = "Couldn't renamed to " + rfm.NewName;
                    return(RedirectToAction(nameof(Browse),
                                            new { path = rfm.ReturnUrl }));
                }
                ReturnMessage = "Successfully renamed to " + rfm.NewName;

                return(RedirectToAction(nameof(Browse),
                                        new { path = rfm.ReturnUrl }));
            }
            ModelState.AddModelError(HttpContext.TraceIdentifier, "New name cannot be empty!");
            return(View(rfm));
        }
Example #3
0
 public IActionResult RenameFile([FromBody] RenameFileModel model, [FromServices] PathService pathService)
 {
     try
     {
         var file = FilesRepo.Files[model.FileName];
         if (file == null)
         {
             throw new Exception("file not found");
         }
         var newPath = Path.Combine(pathService.GetPath(), model.NewName) +
                       Path.GetExtension(model.FileName);
         System.IO.File.Move(file.FilePath, newPath);
         FilesRepo.Files.Remove(file.FilePath, out file);
         file.FilePath            = newPath;
         FilesRepo.Files[newPath] = file;
         return(Ok(new { path = newPath }));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(BadRequest(e.Message));
     }
 }
Example #4
0
 public HttpResponseMessage RenameFile(RenameFileModel model)
 {
     return(fileService.Rename(model, Request));
 }
Example #5
0
 public HttpResponseMessage Rename(RenameFileModel model, HttpRequestMessage request)
 {
     fileManager.Rename(model.Path, model.OldName, model.NewName);
     return(request.CreateResponse(HttpStatusCode.OK, string.Format(Resources.FileHasBeenRenamed, model.OldName, model.NewName)));
 }