Beispiel #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);
                // 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);
            }
        }
Beispiel #2
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");
            }
        }