コード例 #1
0
ファイル: UserActionController.cs プロジェクト: daodao10/Fa
        public ActionResult DeleteFile(string path)
        {
            string dir = path.Substring(0, path.LastIndexOf("\\"));

            if (!dir.Equals(PathModel.root))
            {
                //判断该用户对该路径是否用delete权限
                int User_Id = _entities.Users.FirstOrDefault(x => x.Name == System.Web.HttpContext.Current.User.Identity.Name).Id;
                int Path_Id = _entities.Paths.FirstOrDefault(x => x.Name == dir).Id;
                var right = _entities.Rights.FirstOrDefault(x => x.User_Id == User_Id && x.Path_Id == Path_Id);
                if (right != null && right.Delete_right)
                {

                    Paths p = _entities.Paths.FirstOrDefault(x => x.Name == dir);
                    if (p != null)
                    {
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);

                            //log
                            _logRespository = new DeleteFolderOrFileLog();
                            _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name,
                                path,
                                0);

                        }
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = "Make sure you have delete right on this folder";

                }
            }

            PathManager filesTree = new PathManager(dir);
            return View("Index", filesTree);
        }
コード例 #2
0
ファイル: PathsController.cs プロジェクト: daodao10/Fa
        public ActionResult Delete(string path)
        {
            //if ((path.IndexOf("root") + 4) != path.Length)
            if (!path.Equals(PathModel.root))
            {

                Paths p = _entities.Paths.FirstOrDefault(x => x.Name == path);
                if (p != null)
                {
                    var sub_paths = from c in _entities.Paths
                                    where c.Name.Contains(path + "\\")
                                    select c;
                    List<Paths> sub_path_list = sub_paths.ToList();

                    //log
                    _logRespository = new DeleteFolderOrFileLog();
                    _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name,
                        path,
                        0);
                    string[] filePaths = System.IO.Directory.GetFiles(path);
                    if (filePaths != null)
                    {
                        foreach (string filepath in filePaths)
                        {
                            _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name,
                                filepath,
                                0);
                        }
                    }

                    foreach (var item in sub_path_list)
                    {
                        _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name,
                            item.Name,
                            0);
                        string[] filePaths2 = System.IO.Directory.GetFiles(item.Name);
                        if (filePaths != null)
                        {
                            foreach (string filepath in filePaths2)
                            {
                                _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name,
                                    filepath,
                                    0);
                            }
                        }
                    }

                    System.IO.Directory.Delete(path, true);
                    _entities.ExecuteStoreCommand("delete from Paths where Name = '" + path + "'");//.DeleteObject(p);
                    _entities.ExecuteStoreCommand("delete from Paths where Name like '" + path + "\\" + "%'");
                    _entities.SaveChanges();

                }

                int length = path.LastIndexOf('\\');
                string parent = path.Substring(0, length);
                PathManager filesTree = new PathManager(parent);
                PathModel.path = parent;
                return View("Index", filesTree);
            }
            else
            {
                PathManager filesTree = new PathManager(path);
                return View("Index", filesTree);
            }
        }
コード例 #3
0
ファイル: UserActionController.cs プロジェクト: daodao10/Fa
        public ActionResult Delete(string path)
        {
            PathManager filesTree;
            if (!path.Equals(PathModel.root))
            {
                //判断该用户对该路径是否用delete权限
                int User_Id = _entities.Users.FirstOrDefault(x => x.Name == System.Web.HttpContext.Current.User.Identity.Name).Id;
                int Path_Id = _entities.Paths.FirstOrDefault(x => x.Name == path).Id;
                var right = _entities.Rights.FirstOrDefault(x => x.User_Id == User_Id && x.Path_Id == Path_Id);
                if (right != null && right.Delete_right)
                {

                    Paths p = _entities.Paths.FirstOrDefault(x => x.Name == path);
                    if (p != null)
                    {
                        var sub_paths = from c in _entities.Paths
                                   where c.Name.Contains(path+ "\\")
                                   select c;
                        List<Paths> sub_path_list = sub_paths.ToList();

                        //
                        int sub_Path_Id;
                        foreach (var item in sub_path_list)
                        {
                            sub_Path_Id = _entities.Paths.FirstOrDefault(x => x.Name == item.Name).Id;
                            var sub_Path_right=_entities.Rights.FirstOrDefault(r=>r.User_Id==User_Id&&r.Path_Id==sub_Path_Id);
                            if (sub_Path_right == null || !sub_Path_right.Delete_right)
                            {
                                ViewBag.ErrorMessage = "Make sure you have delete right on all sub folders!";
                                filesTree = new PathManager(path);
                                return View("Index", filesTree);
                            }
                        }
                        //log
                        _logRespository = new DeleteFolderOrFileLog();
                        _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name,
                                path,
                                0);
                        string[] filePaths = System.IO.Directory.GetFiles(path);
                        if (filePaths != null)
                        {
                            foreach (string filepath in filePaths)
                            {
                                _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name,
                                    filepath,
                                    0);
                            }
                        }

                        foreach (var item in sub_path_list)
                        {
                            _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name,
                                item.Name,
                                0);
                            string[] filePaths2 = System.IO.Directory.GetFiles(item.Name);
                            if (filePaths != null)
                            {
                                foreach (string filepath in filePaths2)
                                {
                                    _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name,
                                        filepath,
                                        0);
                                }
                            }
                        }

                        System.IO.Directory.Delete(path, true);
                        _entities.ExecuteStoreCommand("delete from Paths where Name = '" + path + "'");//.DeleteObject(p);
                        _entities.ExecuteStoreCommand("delete from Paths where Name like '" + path + "\\" + "%'");
                        _entities.SaveChanges();

                    }

                    int length = path.LastIndexOf('\\');
                    string parent = path.Substring(0, length);
                    filesTree = new PathManager(parent);
                    PathModel.path = parent;
                    return View("Index", filesTree);
                }
                else
                {
                    ViewBag.ErrorMessage = "Make sure you have delete right on this folder";
                    filesTree = new PathManager(path);
                    return View("Index", filesTree);
                }
            }
            else
            {
                ViewBag.ErrorMessage = "You can not delete root!";
                filesTree = new PathManager(path);
                return View("Index", filesTree);
            }
        }