public ActionResult Delete(int fileId , int isDirectory) { string userEmail = (string)Session["email"]; string userPassword = (string)Session["password"]; if (userEmail == null || userPassword == null) return RedirectToRoute("Logout"); FileSystemClient serverFileSystem = new FileSystemClient(); MyFile fileInfo; if(isDirectory==1) { fileInfo = serverFileSystem.GetDirectory(fileId, userEmail, userPassword); serverFileSystem.DeleteDirectory(fileId, userEmail, userPassword); } else { fileInfo = serverFileSystem.GetFile(fileId, userEmail, userPassword); serverFileSystem.DeleteFile(fileId, userEmail, userPassword); } return RedirectToRoute("ShowFolder", new { id = fileInfo.ParentDirectoryId }); }
public ActionResult Rename(int fileId , int isDirectory , string name="") { string userEmail = (string)Session["email"]; string userPassword = (string)Session["password"]; if (userEmail == null || userPassword == null) return RedirectToRoute("Logout"); FileSystemClient serverFileSystem = new FileSystemClient(); MyFile fileInfo; if (isDirectory == 1) fileInfo = serverFileSystem.GetDirectory(fileId, userEmail, userPassword); else fileInfo = serverFileSystem.GetFile(fileId, userEmail, userPassword); if (Request.HttpMethod == "POST") { try { serverFileSystem.Rename(fileId, name, isDirectory, userEmail, userPassword); return Json(new { error = "", success = true, id = fileInfo.ParentDirectoryId }); } catch (Exception ex) { switch (ex.Message) { case "FileNotSelected": return Json(new { error = isDirectory == 1 ? "Выберите директорию для переименования!" : "Выберите файл для переименования", success = false }); case "EmptyNewName": return Json(new { error = isDirectory == 1 ? "Введите новое имя директории!" : "Введите новое имя файла", success = false }); case "FileNotExist": return Json(new { error = isDirectory == 1 ? "Такой директории не существует!" : "Такой файл не существует!", success = false }); case "NameIsBusy": return Json(new { error = isDirectory == 1 ? "Директория с таким именем уже существует!" : "Файл с таким именем уже существует!!", success = false }); default: return Json(new { error = ex.Message, success = false }); } } } ViewData["fileId"] = fileId; ViewData["name"] = fileInfo.Name; ViewData["isDirectory"] = isDirectory; return View(); }