public FileModel CreateFile(DirectoryModel inDir, string name) { if (inDir == null) return null; string path = DecodeHashToPath(inDir.Hash, false); var model = DB.GetModelByHash(path); using (var context = new FileManagerContext()) { bool exist = context.ElfinderFiles.Count(x => x.Name == name && x.Parent_id == model.Id) > 0; if (exist) return null; } try { var filekey = this._key.CreateFileKey(name); this._uploadFile.SaveFile(new byte[0], filekey); var createdFile = new ElfinderFile { Name = name, Parent_id = model.Id, Mime = name.Substring(name.LastIndexOf('.') + 1), Read = true, Write = true, Width = 0, Content = filekey, Locked = false, Height = 0, Hidden = false, Mtime = DateTime.Now, Size = 0 }; using (var context = new FileManagerContext()) { context.ElfinderFiles.Add(createdFile); context.SaveChanges(); } return createFileModel(createdFile, inDir.Hash); } catch { throw new Exception(); return null; } }
public DirectoryModel CreateDirectory(DirectoryModel inDir, string name) { if (inDir == null) return null; string path = DecodeHashToPath(inDir.Hash, false); var model = DB.GetModelByHash(path); using (var context = new FileManagerContext()) { bool exist = context.ElfinderFiles.Count(x => x.Name == name && x.Parent_id == model.Id) > 0; if (exist) return null; } try { var createdDirectory = new ElfinderFile { Name = name, Parent_id = model.Id,// int.Parse(DecodeHashToPath(inDir.Hash, false)), Mime = "directory", Read = true, Write = true, Width = 0, Content = this._key.CreateFileKey("noname"), Locked = false, Height = 0, Hidden = false, Mtime = DateTime.Now, Size = 0 }; using (var context = new FileManagerContext()) { context.ElfinderFiles.Add(createdDirectory); context.SaveChanges(); } return createDirectoryModel(createdDirectory, EncodePathToHash(createdDirectory.Content), inDir.Hash); } catch { throw; } }