public static void DeleteUser(int userid) { DataClassesDataContext db = new DataClassesDataContext(); db.Users.Where(u => u.id == userid) .ToList() .ForEach(u => db.Users.DeleteOnSubmit(u)); db.SubmitChanges(); }
static void Main(string[] args) { var logPath = cfg.Default.FaviconFolder + "log.txt"; try { var sites = GetSites(); var stackSites = from s in sites select new StackSite() {Description = s.Description, KeyName = s.Name.Replace(" ", ""), Name = s.Name, State = s.State.ToString(), Url = s.SiteUrl}; DataClassesDataContext ctx = new DataClassesDataContext(cfg.Default.DefaultConnectionString); foreach (var stackSite in ctx.StackSites) { ctx.StackSites.DeleteOnSubmit(stackSite); } ctx.SubmitChanges(); if (!Directory.Exists(cfg.Default.FaviconFolder)) { Directory.CreateDirectory(cfg.Default.FaviconFolder); } else { foreach (var file in Directory.GetFiles(cfg.Default.FaviconFolder)) { File.Delete(file); } } foreach (var stackSite in stackSites) { File.WriteAllText(logPath, stackSite.Name + "\n"); Console.WriteLine(stackSite.Name); try { using (var wc = new WebClient()) { byte[] faviconBytes = wc.DownloadData(stackSite.Url + "/favicon.ico"); string faviconPath = cfg.Default.FaviconFolder + stackSite.KeyName ; File.WriteAllBytes(faviconPath + ".ico", faviconBytes); using (var faviconStream = new FileStream(faviconPath + ".ico",FileMode.Open,FileAccess.Read)) { using (var faviconImage = Image.FromStream(faviconStream)) { using (var outputStream = new MemoryStream()) { faviconImage.Save(outputStream, ImageFormat.Png); File.WriteAllBytes(faviconPath + ".png", outputStream.ToArray()); } } } } } catch (Exception e) { File.WriteAllText(logPath, stackSite.Name + " - " + e.Message + "\n"); Console.WriteLine(stackSite.Name + " - " + e.Message); } ctx.StackSites.InsertOnSubmit(stackSite); } ctx.SubmitChanges(); File.WriteAllText(logPath, "Done"); Console.WriteLine("Done"); Console.Read(); } catch (Exception e) { File.WriteAllText(logPath,e.Message); Console.WriteLine(e.Message); } }
public static void AddUser(User user) { DataClassesDataContext db = new DataClassesDataContext(); user.id = GetNextId(); db.Users.InsertOnSubmit(user); db.SubmitChanges(); }
public static void AddFile(File file) { DataClassesDataContext db = new DataClassesDataContext(); file.id = GetNextId(); db.Files.InsertOnSubmit(file); db.SubmitChanges(); }
public static void DeleteFile(int fileid) { DataClassesDataContext db = new DataClassesDataContext(); db.Files.Where(u => u.id == fileid) .ToList() .ForEach(u => db.Files.DeleteOnSubmit(u)); db.SubmitChanges(); }
public static void UpdateUser(User user) { DataClassesDataContext db = new DataClassesDataContext(); db.Users.Where(u => u.id == user.id) .ToList() .ForEach(u => { u.name = user.name; u.password = user.password; u.role = user.role; }); db.SubmitChanges(); }
public static void UpdateFile(File file) { DataClassesDataContext db = new DataClassesDataContext(); db.Files.Where(u => u.id == file.id) .ToList() .ForEach(f => { f.name = file.name; f.type = file.type; f.is_public = file.is_public; }); db.SubmitChanges(); }