public ActionResult MoveTo(Models.DiskFile.Edit vm) { using (var db = new XkSystem.Models.DbContext()) { var tb = (from p in db.Table <Disk.Entity.tbDiskFile>() .Include(p => p.tbDiskFolder) where p.Id == vm.DiskFileEdit.Id && 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(null, Url.Action("List", "DiskFile", new { folderId = vm.FolderId }), "移动成功!")); } }
public ActionResult MoveTo(int id = 0) { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.DiskFile.Edit(); if (id != 0) { var tb = (from p in db.Table <Disk.Entity.tbDiskFile>() where p.Id == id && p.tbSysUser.Id == Code.Common.UserId select new Dto.DiskFile.Edit { Id = p.Id, FileTitle = p.FileTitle }).FirstOrDefault(); if (tb != null) { vm.DiskFileEdit = tb; } } if (vm.UserId == 0) { vm.UserId = Code.Common.UserId; } return(View(vm)); } }
public ActionResult Rename(int id = 0) { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.DiskFile.Edit(); if (id != 0) { var tb = (from p in db.Table <Disk.Entity.tbDiskFile>() where p.Id == id select new Dto.DiskFile.Edit { Id = p.Id, FileTitle = p.FileTitle }).FirstOrDefault(); if (tb != null) { vm.DiskFileEdit = tb; vm.DiskFileEdit.FileTitle = vm.DiskFileEdit.FileTitle.Replace("." + vm.DiskFileEdit.FileTitle.Split(new char[] { '.' }).Last(), ""); } } return(View(vm)); } }
public ActionResult Edit(Models.DiskFile.Edit vm) { HttpPostedFileBase file = Request.Files["fileData"]; if (file.ContentLength > 0) { var filePath = Server.MapPath("~/Files/Disk/"); //if (!Directory.Exists(filePath)) //{ // Directory.CreateDirectory(filePath); //} string[] fileTypeExts = new string[] { ".jpg", ".jpeg", ".png", ".gif", ".rar", ".zip", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".flv", ".avi", ".rmvb", ".rm", ".wmv", ".mp3", ".mp4", ".wma" }; if (fileTypeExts.Contains(Path.GetExtension(file.FileName))) { string fileTitle = Path.GetFileName(file.FileName); string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + new Random().Next(10000, 99999).ToString() + "." + file.FileName.Split('.').Last(); string fileContent = file.FileName.Split('.').Last(); file.SaveAs(filePath + fileName); using (var db = new XkSystem.Models.DbContext()) { var tb = new Disk.Entity.tbDiskFile(); tb.FileTitle = fileTitle; tb.FileName = fileName; tb.FileContent = fileContent; tb.FileLength = file.ContentLength; tb.InputDate = DateTime.Now; tb.tbSysUser = db.Set <Sys.Entity.tbSysUser>().Find(Code.Common.UserId); if (vm.FolderId != 0) { tb.tbDiskFolder = db.Set <Disk.Entity.tbDiskFolder>().Find(vm.FolderId); } db.Set <Disk.Entity.tbDiskFile>().Add(tb); db.SaveChanges(); } } } return(Code.MvcHelper.Post()); }
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)); }
public ActionResult Rename(Models.DiskFile.Edit vm) { using (var db = new XkSystem.Models.DbContext()) { var error = new List <string>(); if (error.Count == decimal.Zero) { if (vm.DiskFileEdit.Id != 0) { var tb = (from p in db.Table <Disk.Entity.tbDiskFile>() where p.Id == vm.DiskFileEdit.Id select p).FirstOrDefault(); if (tb != null) { tb.FileTitle = vm.DiskFileEdit.FileTitle + "." + tb.FileName.Split(new char[] { '.' }).Last(); } } } db.SaveChanges(); return(Code.MvcHelper.Post(error)); } }
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 }), "移动成功!")); } }