public ActionResult MoveTo(int id = 0) { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.DiskFolder.Edit(); if (id != 0) { vm.DiskFolderEdit.Id = id; } if (vm.UserId == 0) { vm.UserId = Code.Common.UserId; } return(View(vm)); } }
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 }), "移动成功!")); } }
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)); } }
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)); } }