public static void SaveNewFileInDB(FileStream file, string TZ, string filedesc, string extention, string remark) { using (DBcomfilerEntities context = new DBcomfilerEntities()) { //todo convert from the system.io object to my file. DAL.File newFile = new DAL.File(); string[] fileLongName = file.Name.Split('\\'); string[] fileName = fileLongName[fileLongName.Length - 1].Split('.'); string id = fileName[0]; newFile.ID = id; newFile.CreatorID = TZ; newFile.Date_Creation = DateTime.Now; newFile.Desctiption = filedesc; newFile.ExtensionID = context.Extensions.FirstOrDefault(x => x.Extension1 == extention).ID; newFile.Version = 1; try { context.Files.Add(newFile); context.SaveChanges(); } catch (Exception e) { throw e; } } }
public static List <DAL.File> Search(string directory, string searchString) { bool searchSubdirectories = true; bool caseSensitive = true; bool useRegex = true; string docxText = null; List <DAL.File> searchfiles = new List <DAL.File>(); var isMatch = useRegex ? new Predicate <string>(x => Regex.IsMatch(x, searchString)) : new Predicate <string>(x => x.IndexOf(searchString, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase) >= 0); // TODO rekorsive to all the directories in this directory foreach (var filePath in Directory.GetFiles(directory, "*.docx", searchSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)) { FileStream stream = null; using (stream = System.IO.File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { if (stream.Length == 0) { continue; } docxText = new DocxToStringConverter(stream).Convert(); } if (isMatch(docxText)) { using (DBcomfilerEntities context = new DBcomfilerEntities()) { string idFile = stream.Name.Substring(stream.Name.Length - 41).ToString(); string id = idFile.Remove(idFile.Length - 5); DAL.File file = context.Files.FirstOrDefault(x => x.ID == id); searchfiles.Add(file); } } } return(searchfiles); }
private static string GetExtentionById(string extentionId) { using (DBcomfilerEntities context = new DBcomfilerEntities()) { int intExtentionId = int.Parse(extentionId); return(context.Extensions.FirstOrDefault(x => x.ID == intExtentionId).Extension1); } }
public static DateTime GetFileDateByName(string fileName) { using (DBcomfilerEntities context = new DBcomfilerEntities()) { DAL.File file = context.Files.FirstOrDefault(x => x.ID == fileName); { return(Convert.ToDateTime(file.Date_Creation)); } } }
public static List <DAL.Extension> GetAllExtentions() { using (DBcomfilerEntities context = new DBcomfilerEntities()) { List <Extension> extentions = context.Extensions.ToList(); if (extentions != null) { return(extentions); } return(null); } }
public static List <DAL.File> GetAllFiles() { using (DBcomfilerEntities context = new DBcomfilerEntities()) { List <DAL.File> files = context.Files.ToList(); if (files != null) { return(files); } } return(null); }
private static string GetUserNameByEmail(string sendEmail) { using (DBcomfilerEntities context = new DBcomfilerEntities()) { var user = context.Users.FirstOrDefault(x => x.Email == sendEmail); if (user != null) { return(user.UserName); } } return(null); }
public static User GetUserByUserName(string userName) { using (DBcomfilerEntities context = new DBcomfilerEntities()) { var user = context.Users.FirstOrDefault(x => x.UserName == userName); if (user != null) { return(user); } } return(null); }
public static List <Category> GetAllCategories() { using (DBcomfilerEntities context = new DBcomfilerEntities()) { var categories = context.Categories.ToList(); if (categories != null) { return(categories); } } return(null); }
public static List <User> GetAllUsers() { using (DBcomfilerEntities context = new DBcomfilerEntities()) { var users = context.Users.ToList(); if (users != null) { return(users); } } return(null); }
public static DAL.File GetFileByName(string fileName) { using (DBcomfilerEntities context = new DBcomfilerEntities()) { var file = context.Files.FirstOrDefault(x => x.ID == fileName); if (file != null) { return(file); } } return(null); }