Пример #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);
            }
        }
Пример #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
        public ContentResult UploadFile()
        {
            Request.ContentEncoding = Encoding.GetEncoding("UTF-8");

            Response.ContentEncoding = Encoding.GetEncoding("UTF-8");
            Response.Charset = "UTF-8";

            string result = "";

            //FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(sessionid);
            //if (ticket != null)
            //{
            //    var identity = new FormsIdentity(ticket);
            //    if (identity.IsAuthenticated)
            //    {
                    if (!PathModel.path.Equals(PathModel.root))
                    {
                        //判断当前路径 该用户是否有Upload权限
                        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 == PathModel.path).Id;
                        var right = _entities.Rights.FirstOrDefault(x => x.User_Id == User_Id && x.Path_Id == Path_Id);
                        if (right != null && right.Upload_right)
                        {
                            //log
                            _logRespository = new AddFolderOrFileLog();

                            foreach (string file in Request.Files)
                            {
                                HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                                var fileName = PathModel.path + "\\" + System.IO.Path.GetFileName(hpf.FileName);
                                result += fileName;
                                hpf.SaveAs(fileName);
                                result = "ok";

                                _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name,
                                fileName,
                                0);
                            }

                        }
                        else
                        {
                            //ViewBag.ErrorMessage = "!!You have no upload right on this folder";
                            result = "You have no upload right on this folder!";
                        }

                    }
                    else
                    {
                        //ViewBag.ErrorMessage = "!!You can not upload under root";
                        //Response.Write(0);
                        result = "You can not upload under root!";
                //    }
                //}
            }
            return Content(result);
        }