public FilesController() { Context = new FileViewerContext(); if (!DataBaseCleaned) { Viewer viewer = new Viewer(); Task.Run(() => Viewer.CleanDataBase()); DataBaseCleaned = true; } }
public static void CleanDataBase() { FileViewerContext context = new FileViewerContext(); List <PathInfo> pathInfos = context.PathInfos.ToList(); foreach (PathInfo pathInfo in pathInfos) { if (!Directory.Exists(pathInfo.RootPath)) { context.Entry(pathInfo).State = System.Data.Entity.EntityState.Deleted; } } context.SaveChanges(); return; }