コード例 #1
0
        public static List <Dto.DiskFile.Info> SelectDescendantsByFolder(List <int> folderIds)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                List <Dto.DiskFile.Info> fileDescendants = new List <Dto.DiskFile.Info>();

                List <Dto.DiskFolder.Info> folderDescendants = DiskFolderController.SelectDescendants(folderIds);
                foreach (var folder in folderDescendants)
                {
                    var tb = (from t in db.Table <Disk.Entity.tbDiskFile>()
                              where t.tbDiskFolder.Id == folder.Id
                              select new Dto.DiskFile.Info
                    {
                        Id = t.Id,
                        FileTitle = t.FileTitle,
                        FileName = t.FileName,
                        FolderId = t.tbDiskFolder.Id,
                        FolderPath = folder.FolderPath
                    }).ToList();

                    fileDescendants = fileDescendants.Union(tb).ToList();
                }

                return(fileDescendants);
            }
        }
コード例 #2
0
        public ActionResult DeleteChecked(List <string> ids)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                foreach (string id in ids)
                {
                    string[] arrId = id.Split(new char[] { '-' });
                    int      _id   = Convert.ToInt32(arrId[0]);
                    if (arrId[1] == "Folder")
                    {
                        DiskFolderController.Delete(_id);
                    }
                    else
                    {
                        if (_id != 0)
                        {
                            var tb = (from p in db.Table <Disk.Entity.tbDiskFile>()
                                      where p.Id == _id && p.tbSysUser.Id == Code.Common.UserId
                                      select p).FirstOrDefault();
                            if (tb != null)
                            {
                                tb.IsDeleted = true;
                            }
                        }
                    }
                }

                db.SaveChanges();

                return(Code.MvcHelper.Post());
            }
        }
コード例 #3
0
        public ActionResult DownloadFolder(int id)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var tb = (from t in db.Table <Disk.Entity.tbDiskFolder>()
                          where t.Id == id && t.tbSysUser.Id == Code.Common.UserId
                          select t).FirstOrDefault();

                if (tb != null)
                {
                    List <int> ids = new List <int>();
                    ids.Add(tb.Id);
                    List <Dto.DiskFolder.Info> folderDescendants = DiskFolderController.SelectDescendants(ids);

                    string strTempPathName = Path.GetTempPath() + Guid.NewGuid().ToString();
                    string strTempPath     = strTempPathName + "/";
                    string zipFileName     = strTempPathName + ".zip";

                    foreach (var folder in folderDescendants)
                    {
                        if (!Directory.Exists(strTempPath + folder.FolderPath))
                        {
                            Directory.CreateDirectory(strTempPath + folder.FolderPath);
                        }
                    }

                    List <Dto.DiskFile.Info> diskFileDescendants = DiskFileController.SelectDescendantsByFolder(ids);
                    string strFilesDiskPath = Server.MapPath("~/Files/Disk/");
                    foreach (var diskFile in diskFileDescendants)
                    {
                        FileInfo file = new FileInfo(strFilesDiskPath + diskFile.FileName);
                        file.CopyTo(strTempPath + diskFile.FolderPath + diskFile.FileTitle);
                    }

                    Code.ZipHelper.CreateZip(zipFileName, strTempPath + tb.DiskFolderName + "/");

                    Code.FileHelper.DeleteDirectory(strTempPath);

                    return(File(zipFileName, Code.Common.DownloadType, tb.DiskFolderName + ".zip"));
                }

                return(RedirectToAction("List"));
            }
        }
コード例 #4
0
        public ActionResult MoveTo(Models.DiskFolder.Edit vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();

                List <int> ids = new List <int>();
                ids.Add(vm.DiskFolderEdit.Id);
                List <Dto.DiskFolder.Info> folderDescendants = DiskFolderController.SelectDescendants(ids);

                if (folderDescendants.Select(t => t.Id).Contains(vm.DiskFolderEdit.ParentId))
                {
                    error.AddError("文件夹不能移动到自身及子文件夹中!");
                }

                if (error.Count() == 0)
                {
                    var tb = (from p in db.Table <Disk.Entity.tbDiskFolder>()
                              .Include(p => p.tbDiskFolderParent)
                              where p.Id == vm.DiskFolderEdit.Id && p.tbSysUser.Id == Code.Common.UserId
                              select p).FirstOrDefault();
                    if (tb != null)
                    {
                        if (vm.DiskFolderEdit.ParentId == 0)
                        {
                            tb.tbDiskFolderParent = null;
                        }
                        else
                        {
                            tb.tbDiskFolderParent = db.Set <Disk.Entity.tbDiskFolder>().Find(vm.DiskFolderEdit.ParentId);
                        }
                    }

                    db.SaveChanges();
                }

                return(Code.MvcHelper.Post(error, Url.Action("List", "DiskFile", new
                {
                    folderId = vm.FolderId
                }), "移动成功!"));
            }
        }
コード例 #5
0
        public ActionResult Edit()
        {
            var vm = new Models.DiskFile.Edit();

            #region 校验上传文件夹权限
            if (vm.FolderId != 0)
            {
                var diskFolder = DiskFolderController.SelectInfo(vm.FolderId);
                if (diskFolder != null &&
                    !diskFolder.UserId.Equals(Code.Common.UserId) &&
                    !DiskFolderController.CheckDickTypePublic(vm.FolderId) &&
                    !DiskPowerController.CheckInput(vm.FolderId, Code.Common.UserId) &&
                    Code.Common.UserType != Code.EnumHelper.SysUserType.Administrator)
                {
                    return(Content(String.Format("您不具备当前文件夹:【{0}】的上传权限!", diskFolder.DiskFolderName)));
                }
            }
            #endregion

            return(View(vm));
        }
コード例 #6
0
        public ActionResult DownloadChecked(string ids)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                List <int> fileIds   = new List <int>();
                List <int> folderIds = new List <int>();
                string[]   arrIds    = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (arrIds.Length == 1)
                {
                    string[] arrId = arrIds[0].Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                    if (arrId[1] == "Folder")
                    {
                        int folderId = arrId[0].ConvertToInt();
                        var tb       = (from t in db.Table <Disk.Entity.tbDiskFolder>()
                                        where t.Id == folderId
                                        select t).FirstOrDefault();

                        if (tb != null)
                        {
                            folderIds.Add(folderId);
                            List <Dto.DiskFolder.Info> folderDescendants = DiskFolderController.SelectDescendants(folderIds);

                            string strTempPathName = Path.GetTempPath() + Guid.NewGuid().ToString();
                            string strTempPath     = strTempPathName + "/";
                            string zipFileName     = strTempPathName + ".zip";

                            foreach (var folder in folderDescendants)
                            {
                                if (!Directory.Exists(strTempPath + folder.FolderPath))
                                {
                                    Directory.CreateDirectory(strTempPath + folder.FolderPath);
                                }
                            }

                            List <Dto.DiskFile.Info> diskFileDescendants = DiskFileController.SelectDescendantsByFolder(folderIds);
                            string strFilesDiskPath = Server.MapPath("~/Files/Disk/");
                            foreach (var diskFile in diskFileDescendants)
                            {
                                FileInfo file = new FileInfo(strFilesDiskPath + diskFile.FileName);
                                file.CopyTo(strTempPath + diskFile.FolderPath + diskFile.FileTitle);
                            }

                            Code.ZipHelper.CreateZip(zipFileName, strTempPath + tb.DiskFolderName + "/");

                            Code.FileHelper.DeleteDirectory(strTempPath);

                            return(File(zipFileName, Code.Common.DownloadType, tb.DiskFolderName + ".zip"));
                        }
                    }
                    else
                    {
                        int fileId = arrId[0].ConvertToInt();
                        if (fileId != 0)
                        {
                            var tb = (from p in db.Table <Disk.Entity.tbDiskFile>()
                                      where p.Id == fileId
                                      select p).FirstOrDefault();
                            if (tb != null)
                            {
                                string filePath = Server.MapPath("~/Files/Disk/") + tb.FileName;

                                return(File(filePath, Code.Common.DownloadType, tb.FileTitle));
                            }
                        }
                    }
                }
                else
                {
                    foreach (string strIds in arrIds)
                    {
                        string[] arrId = strIds.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);

                        if (arrId[1] == "Folder")
                        {
                            folderIds.Add(arrId[0].ConvertToInt());
                        }
                        else
                        {
                            fileIds.Add(arrId[0].ConvertToInt());
                        }
                    }

                    List <Dto.DiskFolder.Info> folderDescendants = DiskFolderController.SelectDescendants(folderIds);
                    string strTempPathName = Path.GetTempPath() + Guid.NewGuid().ToString();
                    string strTempPath     = strTempPathName + "/";
                    string zipFileName     = strTempPathName + ".zip";

                    if (!Directory.Exists(strTempPath))
                    {
                        Directory.CreateDirectory(strTempPath);
                    }

                    foreach (var folder in folderDescendants)
                    {
                        if (!Directory.Exists(strTempPath + folder.FolderPath))
                        {
                            Directory.CreateDirectory(strTempPath + folder.FolderPath);
                        }
                    }

                    List <Dto.DiskFile.Info> diskFileDescendants = DiskFileController.SelectDescendantsByFolder(folderIds);
                    foreach (var fileId in fileIds)
                    {
                        var tb = (from t in db.Table <Disk.Entity.tbDiskFile>()
                                  where t.Id == fileId
                                  select new Dto.DiskFile.Info
                        {
                            Id = t.Id,
                            FileTitle = t.FileTitle,
                            FileName = t.FileName,
                            FolderId = t.tbDiskFolder == null ? 0 : t.tbDiskFolder.Id
                        }).FirstOrDefault();
                        if (tb != null)
                        {
                            diskFileDescendants.Add(tb);
                        }
                    }

                    string strFilesDiskPath = Server.MapPath("~/Files/Disk/");
                    foreach (var diskFile in diskFileDescendants)
                    {
                        FileInfo file = new FileInfo(strFilesDiskPath + diskFile.FileName);
                        file.CopyTo(strTempPath + diskFile.FolderPath + diskFile.FileTitle);
                    }

                    Code.ZipHelper.CreateZip(zipFileName, strTempPath + "/");

                    Code.FileHelper.DeleteDirectory(strTempPath);

                    return(File(zipFileName, Code.Common.DownloadType, DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".zip"));
                }

                return(Content("<script>alert('文件不存在');</script>"));
            }
        }
コード例 #7
0
        public ActionResult MoveToChecked(Models.DiskFile.Edit vm, string ids)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();

                List <int> fileIds   = new List <int>();
                List <int> folderIds = new List <int>();
                string[]   arrIds    = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string id in arrIds)
                {
                    string[] arrId = id.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                    if (arrId[1] == "Folder")
                    {
                        folderIds.Add(Convert.ToInt32(arrId[0]));
                    }
                    else
                    {
                        fileIds.Add(Convert.ToInt32(arrId[0]));
                    }
                }

                List <Dto.DiskFolder.Info> folderDescendants = DiskFolderController.SelectDescendants(folderIds);

                if (folderDescendants.Select(t => t.Id).Contains(vm.DiskFileEdit.FolderId))
                {
                    error.AddError("文件夹不能移动到自身及子文件夹中!");
                }

                if (error.Count() == 0)
                {
                    foreach (int folderId in folderIds)
                    {
                        var tb = (from p in db.Table <Disk.Entity.tbDiskFolder>()
                                  .Include(p => p.tbDiskFolderParent)
                                  where p.Id == folderId && p.tbSysUser.Id == Code.Common.UserId
                                  select p).FirstOrDefault();
                        if (tb != null)
                        {
                            if (vm.DiskFileEdit.FolderId == 0)
                            {
                                tb.tbDiskFolderParent = null;
                            }
                            else
                            {
                                tb.tbDiskFolderParent = db.Set <Disk.Entity.tbDiskFolder>().Find(vm.DiskFileEdit.FolderId);
                            }
                        }
                    }

                    foreach (int fileId in fileIds)
                    {
                        var tb = (from p in db.Table <Disk.Entity.tbDiskFile>()
                                  .Include(p => p.tbDiskFolder)
                                  where p.Id == fileId && p.tbSysUser.Id == Code.Common.UserId
                                  select p).FirstOrDefault();
                        if (tb != null)
                        {
                            if (vm.DiskFileEdit.FolderId == 0)
                            {
                                tb.tbDiskFolder = null;
                            }
                            else
                            {
                                tb.tbDiskFolder = db.Set <Disk.Entity.tbDiskFolder>().Find(vm.DiskFileEdit.FolderId);
                            }
                        }
                    }

                    db.SaveChanges();
                }

                return(Code.MvcHelper.Post(error, Url.Action("List", "DiskFile", new
                {
                    folderId = vm.FolderId
                }), "移动成功!"));
            }
        }
コード例 #8
0
        public ActionResult List()
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.DiskFile.List();

                var tbDiskType = DiskTypeController.SelectInfo(vm.DiskTypeId);

                #region 文件夹路径
                if (vm.UserId == 0)
                {
                    vm.FolderPath = DiskFolderController.SelectFolderPath(vm.FolderId);
                }
                else
                {
                    if (tbDiskType != null && tbDiskType.DiskType == Code.EnumHelper.DiskType.Public)
                    {
                        var tbSysUser    = db.Set <Sys.Entity.tbSysUser>().Find(vm.UserId);
                        var tbDiskFolder = (from t in db.Table <Disk.Entity.tbDiskFolder>()
                                            where t.DiskFolderName == "教师共享文件夹"
                                            select t).FirstOrDefault();
                        vm.FolderPath = DiskFolderController.SelectFolderPath(tbDiskFolder.Id);
                        vm.FolderPath.Add(new Dto.DiskFolder.Info
                        {
                            DiskFolderName = tbSysUser.UserName,
                            DiskTypeId     = vm.DiskTypeId,
                            UserId         = tbSysUser.Id,
                            ParentId       = 0
                        });
                    }

                    if (vm.FolderId != 0)
                    {
                        vm.FolderPath = vm.FolderPath.Union(DiskFolderController.SelectFolderPath(vm.FolderId, vm.DiskTypeId, vm.UserId)).ToList();
                    }
                }
                #endregion

                #region 文件夹
                if (vm.FolderId == 0)
                {
                    if (vm.DiskTypeId == 0)
                    {
                        // /Disk/DiskFile/List
                        vm.DiskFileList = DiskFolderController.SelectPublicRootFolder();
                        vm.DiskFileList = vm.DiskFileList.Union(DiskFolderController.SelectByParentId(vm.FolderId, vm.SearchText, 0, Code.Common.UserId)).ToList();
                    }

                    if (vm.UserId != 0)
                    {
                        vm.DiskFileList = DiskFolderController.SelectByDiskPermitPublic(vm.UserId, vm.DiskTypeId);
                        vm.DiskFileList = vm.DiskFileList.Union(DiskFolderController.SelectByDiskPermitAuthorize(vm.UserId, vm.DiskTypeId)).ToList();
                    }
                }
                else
                {
                    if (tbDiskType != null && tbDiskType.DiskType == Code.EnumHelper.DiskType.Public)
                    {
                        // 管理员查看全部
                        if (Code.Common.UserType == Code.EnumHelper.SysUserType.Administrator)
                        {
                            vm.DiskFileList = DiskFolderController.SelectPublicFolderByParentId(vm.FolderId);
                        }
                        else
                        {
                            // 学校共享文件夹-共有
                            vm.DiskFileList = DiskFolderController.SelectPublicFolderByParentId(vm.FolderId, Code.EnumHelper.DiskPermit.Public);

                            // 学校共享文件夹-授权
                            var tbDiskFolderAuthorize = DiskFolderController.SelectPublicFolderAuthorizeByParentId(vm.FolderId, Code.EnumHelper.DiskPermit.Public);
                            foreach (Dto.DiskFile.List diskFile in tbDiskFolderAuthorize)
                            {
                                if (!vm.DiskFileList.Any(t => t.FileTitle.Equals(diskFile.FileTitle)))
                                {
                                    vm.DiskFileList.Add(diskFile);
                                }
                            }
                        }

                        var folder = (from t in db.Table <Disk.Entity.tbDiskFolder>()
                                      where t.Id == vm.FolderId
                                      select t).FirstOrDefault();
                        if (folder != null)
                        {
                            if (folder.DiskFolderName.Equals("教师共享文件夹"))
                            {
                                vm.DiskFileList = vm.DiskFileList.Union(DiskFolderController.SelectByPublic(Code.EnumHelper.DiskType.Private, vm.DiskTypeId)).ToList();

                                foreach (Dto.DiskFile.List diskFile in DiskFolderController.SelectByAuthorize(Code.EnumHelper.DiskType.Private, vm.DiskTypeId))
                                {
                                    if (!vm.DiskFileList.Any(t => t.FileTitle.Equals(diskFile.FileTitle)))
                                    {
                                        vm.DiskFileList.Add(diskFile);
                                    }
                                }
                            }
                            else if (!folder.DiskFolderName.Equals("公开文件夹") && !(folder.DiskFolderName.Equals("学校共享文件夹")))
                            {
                                vm.DiskFileList = DiskFolderController.SelectByParentId(vm.FolderId, vm.SearchText, vm.DiskTypeId, vm.UserId);
                            }
                        }
                    }
                    else
                    {
                        vm.DiskFileList = DiskFolderController.SelectByParentId(vm.FolderId, vm.SearchText);
                    }
                }
                #endregion

                #region 文件
                var tbDiskFile = from t in db.Table <Disk.Entity.tbDiskFile>()
                                 select t;
                if (vm.FolderId != 0)
                {
                    tbDiskFile = tbDiskFile.Where(t => t.tbDiskFolder.Id == vm.FolderId);
                }
                else
                {
                    tbDiskFile = tbDiskFile.Where(t => t.tbDiskFolder == null);

                    //if (vm.UserId != 0)
                    //{
                    //    tbDiskFile = tbDiskFile.Where(t => t.tbSysUser.Id == vm.UserId);
                    //}
                    //else
                    //{
                    tbDiskFile = tbDiskFile.Where(t => t.tbSysUser.Id == Code.Common.UserId);
                    //}
                }
                if (!String.IsNullOrWhiteSpace(vm.SearchText))
                {
                    tbDiskFile = tbDiskFile.Where(t => t.FileTitle.Contains(vm.SearchText));
                }

                int diskTypeId = DiskTypeController.SelectByEnumDiskType(Code.EnumHelper.DiskType.Private).Id;

                var tb = (from t in tbDiskFile
                          orderby t.Id descending
                          select new Dto.DiskFile.List
                {
                    Id = t.Id,
                    DiskTypeId = t.tbDiskFolder == null ? diskTypeId : t.tbDiskFolder.tbDiskType.Id,
                    FileType = "File",
                    FileTitle = t.FileTitle,
                    FileLength = t.FileLength,
                    InputDate = t.InputDate,
                    UserId = t.tbSysUser.Id,
                    UserName = t.tbSysUser.UserName
                }).ToList();

                vm.DiskFileList = vm.DiskFileList.Union(tb).ToList();
                #endregion

                #region 文件夹文件权限

                // 管理权限
                vm.AdminFolderIds = DiskFolderController.SelectOwnFolderIdsByUserId(Code.Common.UserId);
                if (Code.Common.UserType == Code.EnumHelper.SysUserType.Administrator)
                {
                    vm.AdminFolderIds = vm.AdminFolderIds.Union(DiskFolderController.SelectDiskPermitPublicFolderIdsByUserId(Code.EnumHelper.DiskType.Public, Code.Common.UserId)).ToList();
                }
                vm.AdminFolderIds = vm.AdminFolderIds.Union(DiskFolderController.SelectDiskPermitPublicFolderIdsByUserId(Code.EnumHelper.DiskType.Private, Code.Common.UserId)).ToList();
                vm.AdminFolderIds = vm.AdminFolderIds.Union(DiskPowerController.SelectAdminFolderIds(Code.Common.UserId)).ToList();

                // 查看权限
                vm.ViewFolderIds = DiskFolderController.SelectOwnFolderIdsByUserId(Code.Common.UserId);
                vm.ViewFolderIds = vm.ViewFolderIds.Union(DiskFolderController.SelectDiskPermitPublicFolderIdsByUserId(Code.EnumHelper.DiskType.Public, Code.Common.UserId)).ToList();
                vm.ViewFolderIds = vm.ViewFolderIds.Union(DiskFolderController.SelectDiskPermitPublicFolderIdsByUserId(Code.EnumHelper.DiskType.Private, Code.Common.UserId)).ToList();
                vm.ViewFolderIds = vm.ViewFolderIds.Union(DiskPowerController.SelectViewFolderIds(Code.Common.UserId)).ToList();

                #endregion

                #region 文件权限
                vm.AdminFileIds = DiskFileController.SelectDescendantsByFolder(vm.AdminFolderIds).Select(t => t.Id).ToList();
                vm.ViewFileIds  = DiskFileController.SelectDescendantsByFolder(vm.ViewFolderIds).Select(t => t.Id).ToList();

                var MyRootFileIds = (from t in db.Table <Disk.Entity.tbDiskFile>()
                                     where t.tbDiskFolder == null &&
                                     t.tbSysUser.Id == Code.Common.UserId
                                     select t.Id).ToList();
                vm.AdminFileIds = vm.AdminFileIds.Union(MyRootFileIds).ToList();
                vm.ViewFileIds  = vm.ViewFileIds.Union(MyRootFileIds).ToList();

                #endregion

                return(View(vm));
            }
        }
コード例 #9
0
        public ActionResult Edit(Models.DiskFolder.Edit vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();

                #region 新建公共文件夹校验

                var diskType = db.Set <Disk.Entity.tbDiskType>().Find(vm.DiskFolderEdit.DiskTypeId);
                if (diskType.DiskType == Code.EnumHelper.DiskType.Public && Code.Common.UserType != Code.EnumHelper.SysUserType.Administrator)
                {
                    error.AddError("需要管理员身份新建公开文件夹!");
                }

                #endregion

                if (error.Count == decimal.Zero)
                {
                    if (db.Table <Disk.Entity.tbDiskFolder>().Where(d => d.DiskFolderName == vm.DiskFolderEdit.DiskFolderName &&
                                                                    d.tbSysUser.Id == Code.Common.UserId &&
                                                                    d.tbDiskFolderParent.Id == vm.DiskFolderEdit.ParentId &&
                                                                    d.Id != vm.DiskFolderEdit.Id).Any())
                    {
                        error.AddError("该文件夹名称已存在!");
                    }
                    else
                    {
                        if (vm.DiskFolderEdit.Id == 0)
                        {
                            var tb = new Disk.Entity.tbDiskFolder();
                            tb.No = vm.DiskFolderEdit.No == null
                                ? db.Table <Disk.Entity.tbDiskFolder>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1
                                : (int)vm.DiskFolderEdit.No;

                            tb.DiskFolderName = vm.DiskFolderEdit.DiskFolderName;
                            tb.tbDiskType     = diskType;
                            tb.DiskPermit     = vm.DiskFolderEdit.DiskPermit;
                            tb.tbSysUser      = db.Set <Sys.Entity.tbSysUser>().Find(Code.Common.UserId);

                            if (vm.FolderId != 0)
                            {
                                if (diskType.DiskType == Code.EnumHelper.DiskType.Public)
                                {
                                    tb.tbDiskFolderParent = db.Table <Disk.Entity.tbDiskFolder>()
                                                            .Where(t => t.Id == vm.FolderId)
                                                            .FirstOrDefault();
                                }
                                else
                                {
                                    tb.tbDiskFolderParent = db.Table <Disk.Entity.tbDiskFolder>()
                                                            .Where(t => t.Id == vm.FolderId && t.tbSysUser.Id == Code.Common.UserId)
                                                            .FirstOrDefault();
                                }
                            }

                            db.Set <Disk.Entity.tbDiskFolder>().Add(tb);
                        }
                        else
                        {
                            var tb = (from p in db.Table <Disk.Entity.tbDiskFolder>()
                                      where p.Id == vm.DiskFolderEdit.Id
                                      select p).FirstOrDefault();
                            if (tb != null)
                            {
                                tb.No = vm.DiskFolderEdit.No == null?db.Table <Disk.Entity.tbDiskFolder>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.DiskFolderEdit.No;

                                tb.DiskFolderName = vm.DiskFolderEdit.DiskFolderName;
                                tb.DiskPermit     = vm.DiskFolderEdit.DiskPermit;

                                // 同时设置子文件夹权限
                                var tbDiskFolderDescendants = DiskFolderController.SelectDescendants(new List <int> {
                                    tb.Id
                                });
                                foreach (var folder in tbDiskFolderDescendants)
                                {
                                    if (folder.Id != vm.DiskFolderEdit.Id)
                                    {
                                        var tbDiskFolder = db.Set <Disk.Entity.tbDiskFolder>().Find(folder.Id);
                                        if (tbDiskFolder != null)
                                        {
                                            tbDiskFolder.DiskPermit = vm.DiskFolderEdit.DiskPermit;
                                        }
                                    }

                                    // 删除文件夹授权
                                    if (vm.DiskFolderEdit.DiskPermit != Code.EnumHelper.DiskPermit.Authorize)
                                    {
                                        DiskPowerController.DeleteByFolderId(folder.Id);
                                    }
                                }
                            }
                            else
                            {
                                error.AddError(Resources.LocalizedText.MsgNotFound);
                            }
                        }
                    }
                }

                db.SaveChanges();

                return(Code.MvcHelper.Post(error));
            }
        }
コード例 #10
0
        public ActionResult Edit(int id = 0)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.DiskFolder.Edit();

                var tbDiskType = DiskTypeController.SelectInfo(vm.DiskTypeId);
                if (tbDiskType != null && tbDiskType.DiskType == Code.EnumHelper.DiskType.Public)
                {
                    if (Code.Common.UserType != Code.EnumHelper.SysUserType.Administrator)
                    {
                        return(Content("只有管理员才可以新建公开文件夹!"));
                    }
                    else
                    {
                        // 管理员只能新建【学校共享文件夹】的子文件夹
                        var tbDiskFolder = (from t in db.Table <Disk.Entity.tbDiskFolder>()
                                            where t.DiskFolderName.Equals("学校共享文件夹") &&
                                            t.tbDiskType.DiskType == Code.EnumHelper.DiskType.Public
                                            select t).FirstOrDefault();
                        if (tbDiskFolder != null)
                        {
                            List <int> ids = new List <int>();
                            ids.Add(tbDiskFolder.Id);

                            if (!DiskFolderController.SelectDescendants(ids).Select(t => t.Id).Contains(vm.FolderId))
                            {
                                return(Content("只能在学校共享文件夹中新建子文件夹!"));
                            }
                            else
                            {
                                vm.DiskFolderEdit.DiskPermit = Code.EnumHelper.DiskPermit.Public;
                            }
                        }
                    }
                }

                vm.DiskTypeList = Disk.Controllers.DiskTypeController.SelectInfoList();

                if (id != 0)
                {
                    var tb = (from p in db.Table <Disk.Entity.tbDiskFolder>()
                              where p.Id == id
                              select new Dto.DiskFolder.Edit
                    {
                        Id = p.Id,
                        No = p.No,
                        DiskFolderName = p.DiskFolderName,
                        DiskTypeId = p.tbDiskType.Id,
                        DiskPermit = p.DiskPermit
                    }).FirstOrDefault();
                    if (tb != null)
                    {
                        vm.DiskFolderEdit = tb;
                    }
                }
                else
                {
                    vm.DiskFolderEdit.DiskTypeId = (tbDiskType == null || tbDiskType.DiskType == Code.EnumHelper.DiskType.Private)
                        ? vm.DiskTypeList.Where(t => t.DiskType == Code.EnumHelper.DiskType.Private).FirstOrDefault().Id
                        : vm.DiskTypeList.Where(t => t.DiskType == Code.EnumHelper.DiskType.Public).FirstOrDefault().Id;
                }

                return(View(vm));
            }
        }