Exemple #1
0
        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);
            }
        }
Exemple #2
0
 /// <summary>
 /// Create a new Paths object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="creator_Id">Initial value of the Creator_Id property.</param>
 /// <param name="create_Date">Initial value of the Create_Date property.</param>
 public static Paths CreatePaths(global::System.Int32 id, global::System.String name, global::System.Int32 creator_Id, global::System.DateTime create_Date)
 {
     Paths paths = new Paths();
     paths.Id = id;
     paths.Name = name;
     paths.Creator_Id = creator_Id;
     paths.Create_Date = create_Date;
     return paths;
 }
Exemple #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Paths EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPaths(Paths paths)
 {
     base.AddObject("Paths", paths);
 }
Exemple #4
0
        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);
            }
        }