示例#1
0
        public IActionResult Delete(int id)
        {
            var file = _filesService.GetFile(id);

            if (file == null)
            {
                return(NotFound());
            }

            if (file.IsFolder)
            {
                var filesDeleted = _filesService.DeleteFolder(id);
                _logger.LogInformation("{n} files deleted.", filesDeleted);
            }
            else
            {
                var versionsDeleted = _filesService.DeleteFile(id);
                _logger.LogInformation("{n} versions of {file} deleted.", versionsDeleted, id);
            }

            if (file.ParentId != null)
            {
                return(RedirectToAction("View", "Folders", new { id = file.ParentId }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
示例#2
0
        public void DeleteFileShouldDeleteSuccessfullyExistingFileInTheSystem()
        {
            var    service = new FilesService();
            string path    = Directory.GetCurrentDirectory();

            service.DeleteFile(path, "test", ".txt");

            FileInfo fileInfo = new($"{path}/test.txt");

            Assert.False(fileInfo.Exists);
        }
 public ActionResult DeleteFile(FileModel file)
 {
     if (ModelState.IsValid)
     {
         _fileservice.DeleteFile(file.FileId);
         return Json(file, JsonRequestBehavior.AllowGet);
     }
     else
     {
         Response.StatusCode = 400;
         var error = new ErrorModel();
         error.ErrorID = 1;
         error.Message = "Delete Failed";
         return Json(error, JsonRequestBehavior.AllowGet);
     }
 }