コード例 #1
0
ファイル: PathsController.cs プロジェクト: daodao10/Fa
        public ActionResult Create(PathModel model)
        {
            if (!ModelState.IsValid)
                return View();

            string name = model.Name;

            string new_path = PathModel.path + '\\' + name;
            if (_entities.Paths.FirstOrDefault(m => m.Name == new_path) != null)
            {
                PathManager filesTree = new PathManager(PathModel.path);
                return View("Index", filesTree);
            }

            try
            {
                System.IO.Directory.CreateDirectory(new_path);
                // TODO: Add insert logic here
                Paths p = new Paths();
                p.Name = new_path;
                string n = System.Web.HttpContext.Current.User.Identity.Name;
                p.Creator_Id = _entities.Users.FirstOrDefault(m => m.Name == n).Id;
                p.Create_Date = DateTime.Now;
                _entities.AddToPaths(p);
                _entities.SaveChanges();

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

                PathManager filesTree = new PathManager(PathModel.path);
                return View("Index", filesTree);
            }
            catch
            {
                PathManager filesTree = new PathManager(PathModel.path);
                return View("Index", filesTree);
            }
        }
コード例 #2
0
ファイル: UserActionController.cs プロジェクト: daodao10/Fa
        public ActionResult Create(PathModel model)
        {
            if (!ModelState.IsValid)
                return View();

            string name = model.Name;

            string new_path = PathModel.path + '\\' + name;
            if (_entities.Paths.FirstOrDefault(m => m.Name == new_path) != null)
            {
                PathManager filesTree = new PathManager(PathModel.path);
                return View("Index", filesTree);
            }

            try
            {
                System.IO.Directory.CreateDirectory(new_path);
                // Add insert logic
                Paths p = new Paths();
                p.Name = new_path;
                string n = System.Web.HttpContext.Current.User.Identity.Name;
                int User_Id = _entities.Users.FirstOrDefault(m => m.Name == n).Id;
                p.Creator_Id = User_Id;
                p.Create_Date = DateTime.Now;
                _entities.AddToPaths(p);
                _entities.SaveChanges();

                //add log
                _logRespository = new AddFolderOrFileLog();
                _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name,
                        new_path,
                        0);

                //auto inheritant rights
                RightType rt = 0;
                int Parent_Path_Id = _entities.Paths.FirstOrDefault(m => m.Name == PathModel.path).Id;
                int Path_Id = _entities.Paths.FirstOrDefault(m => m.Name == new_path).Id;
                Rights parent = _entities.Rights.FirstOrDefault(r => r.User_Id == User_Id
                    && r.Path_Id == Parent_Path_Id);
                if(parent.Create_right)
                    rt |= RightType.Create;
                if (parent.Upload_right)
                    rt |= RightType.Upload;
                if (parent.Download_right)
                    rt |= RightType.Download;
                if (parent.Delete_right)
                    rt |= RightType.Delete;
                if (parent.Read_right)
                    rt |= RightType.Read;

                Rights right = new Rights();

                right.User_Id = User_Id;
                right.Path_Id = Path_Id;
                right.Create_right = parent.Create_right;
                right.Upload_right = parent.Upload_right;
                right.Download_right = parent.Download_right;
                right.Delete_right = parent.Delete_right;
                right.Read_right = parent.Read_right;

                _entities.AddToRights(right);
                _entities.SaveChanges();

                //log
                _logRespository = new GrantRightLog();
                _logRespository.AddLog(
                    _entities.Users.FirstOrDefault(x => x.Id == User_Id).Name,
                    _entities.Paths.FirstOrDefault(x => x.Id == Path_Id).Name,
                    (int)rt);

                PathManager filesTree = new PathManager(PathModel.path);
                return View("Index", filesTree);
            }
            catch
            {
                PathManager filesTree = new PathManager(PathModel.path);
                return View("Index", filesTree);
            }
        }