Пример #1
0
 /// <summary>
 /// Create a new Rights object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="user_Id">Initial value of the User_Id property.</param>
 /// <param name="path_Id">Initial value of the Path_Id property.</param>
 /// <param name="create_right">Initial value of the Create_right property.</param>
 /// <param name="upload_right">Initial value of the Upload_right property.</param>
 /// <param name="download_right">Initial value of the Download_right property.</param>
 /// <param name="delete_right">Initial value of the Delete_right property.</param>
 /// <param name="read_right">Initial value of the Read_right property.</param>
 public static Rights CreateRights(global::System.Int32 id, global::System.Int32 user_Id, global::System.Int32 path_Id, global::System.Boolean create_right, global::System.Boolean upload_right, global::System.Boolean download_right, global::System.Boolean delete_right, global::System.Boolean read_right)
 {
     Rights rights = new Rights();
     rights.Id = id;
     rights.User_Id = user_Id;
     rights.Path_Id = path_Id;
     rights.Create_right = create_right;
     rights.Upload_right = upload_right;
     rights.Download_right = download_right;
     rights.Delete_right = delete_right;
     rights.Read_right = read_right;
     return rights;
 }
Пример #2
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);
            }
        }
Пример #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Rights EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRights(Rights rights)
 {
     base.AddObject("Rights", rights);
 }
Пример #4
0
        public ActionResult Grant(int id, FormCollection collection)
        {
            _logRespository = new GrantRightLog();
            RightType rt = 0;
            try
            {
                // TODO: Add update logic here
                Rights right;
                int User_Id = 0;
                int Path_Id = 0;
                bool Grant_Create = false;
                bool Grant_Upload = false;
                bool Grant_Download = false;
                bool Grant_Delete = false;
                bool Grant_Read = false;

                foreach (var key in collection.AllKeys)
                {
                    var value = collection[key];

                    if (key.Contains("User_Id"))
                    {
                        User_Id = Convert.ToInt32(value);
                    }
                    else if (key.Contains("Path_Id"))
                    {
                        Path_Id = Convert.ToInt32(value);
                    }
                    else if (key.Contains("Grant_Create"))
                    {
                        if (value.Contains("true"))
                        {
                            Grant_Create = true;
                            rt |= RightType.Create;
                        }
                        else
                        {
                            Grant_Create = false;
                        }
                    }
                    else if (key.Contains("Grant_Upload"))
                    {
                        if (value.Contains("true"))
                        {
                            Grant_Upload = true;
                            rt |= RightType.Upload;
                        }
                        else
                        {
                            Grant_Upload = false;
                        }
                    }
                    else if (key.Contains("Grant_Download"))
                    {
                        if (value.Contains("true"))
                        {
                            Grant_Download = true;
                            rt |= RightType.Download;
                        }
                        else
                        {
                            Grant_Download = false;
                        }
                    }
                    else if (key.Contains("Grant_Delete"))
                    {
                        if (value.Contains("true"))
                        {
                            Grant_Delete = true;
                            rt |= RightType.Delete;
                        }
                        else
                        {
                            Grant_Delete = false;
                        }
                    }
                    else if (key.Contains("Grant_Read"))
                    {
                        if (value.Contains("true"))
                        {
                            Grant_Read = true;
                            rt |= RightType.Read;
                        }
                        else
                        {
                            Grant_Read = false;
                        }

                        right = new Rights();
                        right.User_Id = User_Id;
                        right.Path_Id = Path_Id;
                        right.Create_right = Grant_Create;
                        right.Upload_right = Grant_Upload;
                        right.Download_right = Grant_Download;
                        right.Delete_right = Grant_Delete;
                        right.Read_right = Grant_Read;

                        var rightToEdit = (from c in _entities.Rights
                                           where
                                               c.User_Id == User_Id && c.Path_Id == Path_Id
                                           select c).FirstOrDefault();
                        //_entities.Rights.FirstOrDefault(x => x.User_Id == User_Id && x.Path_Id == Path_Id);

                        if (rightToEdit != null)
                        {
                            //_entities.ApplyCurrentValues<Rights>(rightToEdit.EntityKey.EntitySetName,
                            //    right);
                            _entities.DeleteObject(rightToEdit);
                            _entities.SaveChanges();
                        }

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

                        //Add by Jane
                        string userName = _entities.Users.FirstOrDefault(x => x.Id == User_Id).Name;
                        string objectName = _entities.Paths.FirstOrDefault(x => x.Id == Path_Id).Name;
                        var logToEdit = (from c in _entities.Logs
                                         where c.User_Name == userName && c.Object_Name == objectName && c.Action_Desc == (int)rt
                                         select c).FirstOrDefault();

                        if (rt != 0 && logToEdit == null)
                        {
                            _logRespository.AddLog(userName, objectName, (int)rt);
                            rt = 0;
                        }

                    }

                }
                TempData["Flag"] = 100;
                return RedirectToAction("Index");
            }
            catch
            {
                TempData["Flag"] = 101;
                return RedirectToAction("Index");
            }
        }