public void SetAllArticlesReadForUser(string user) { try { using (BD.AtomicRssDatabaseContainer context = new BD.AtomicRssDatabaseContainer()) { BD.Users u = (from el in context.UsersSet where el.Email == user select el).FirstOrDefault(); if (u != null) { foreach (BD.Channels chan in context.ChannelsSet) { if (chan.Users.Contains(u)) { foreach (BD.Articles article in chan.Articles) { if (!article.Users.Contains(u)) { article.Users.Add(u); } } } } context.SaveChanges(); } } } catch (Exception e) { Debug.WriteLine(e.Message + " Stacktrace : " + e.StackTrace); } }
public void AddChannels(string user, string channels) { try { using (BD.AtomicRssDatabaseContainer context = new BD.AtomicRssDatabaseContainer()) { XmlReader read = XmlReader.Create(channels); SyndicationFeed sfeed = SyndicationFeed.Load(read); read.Close(); BD.Channels chan = (from el in context.ChannelsSet where el.Title == sfeed.Title.Text select el).FirstOrDefault(); BD.Users u = (from el in context.UsersSet where el.Email == user select el).FirstOrDefault(); if (chan != null && u != null) { chan.Users.Add(u); } else if (u != null && chan == null) { chan = new BD.Channels(); chan.Author = "Unkwon"; chan.Language = (sfeed.Language == null) ? ("Uk") : (sfeed.Language); chan.Description = (sfeed.Description.Text.Length > 256) ? (sfeed.Description.Text.Substring(0, 256)) : (sfeed.Description.Text); chan.Title = sfeed.Title.Text; chan.Date = DateTime.Now; // Corrige la plus part des problemes de loading de nouveau channel chan.Link = channels; context.ChannelsSet.AddObject(chan); //foreach (SyndicationItem article in sfeed.Items) //{ // BD.Articles a = new BD.Articles(); // a.Date = article.PublishDate.DateTime; // a.Title = article.Title.Text; // a.Description = article.Summary.Text; // a.GUID = "0000"; // a.Link = article.Id; // chan.Articles.Add(a); // context.ArticlesSet.AddObject(a); //} chan.Users.Add(u); } context.SaveChanges(); } } catch (Exception e) { Debug.WriteLine(e.StackTrace); } }
public void DestroyArticlesRelationWithUser(int id_user) { try { using (BD.AtomicRssDatabaseContainer context = new BD.AtomicRssDatabaseContainer()) { BD.Users user = (from el in context.UsersSet where el.Id == id_user select el).FirstOrDefault(); if (user != null) { user.Channels.Clear(); } context.SaveChanges(); } } catch (Exception e) { Debug.WriteLine(e.Message); } }
public void DestroyChannelsRelation(int id_channels) { try { using (BD.AtomicRssDatabaseContainer context = new BD.AtomicRssDatabaseContainer()) { BD.Channels channel = (from el in context.ChannelsSet where el.Id == id_channels select el).FirstOrDefault(); if (channel != null) { channel.Users.Clear(); } context.SaveChanges(); } } catch (Exception e) { Debug.WriteLine(e.Message); } }
public void SetArticlesReadForUser(int id_article, string user) { try { using (BD.AtomicRssDatabaseContainer context = new BD.AtomicRssDatabaseContainer()) { BD.Users u = (from el in context.UsersSet where el.Email == user select el).FirstOrDefault(); BD.Articles article = (from el in context.ArticlesSet where el.Id == id_article select el).FirstOrDefault(); if (u != null && article != null) { article.Users.Add(u); } context.SaveChanges(); } } catch (Exception e) { Debug.WriteLine(e.Message); } }
public void RemoveChannelsFromUser(string user, int id_channels) { try { using (BD.AtomicRssDatabaseContainer context = new BD.AtomicRssDatabaseContainer()) { BD.Users u = (from el in context.UsersSet where el.Email == user select el).FirstOrDefault(); BD.Channels chan = (from el in context.ChannelsSet where id_channels == el.Id select el).FirstOrDefault(); if (u != null && chan != null) { chan.Users.Remove(u); } context.SaveChanges(); } } catch (Exception e) { Debug.WriteLine(e.Message); } }
public void LoadArticles() { try { using (BD.AtomicRssDatabaseContainer context = new BD.AtomicRssDatabaseContainer()) { foreach (BD.Channels chan in context.ChannelsSet) { XmlReader read = XmlReader.Create(chan.Link); SyndicationFeed feeds = SyndicationFeed.Load(read); read.Close(); Debug.WriteLine("LoadArticles : " + chan.Link); foreach (SyndicationItem article in feeds.Items) { BD.Articles a = new BD.Articles(); a.Date = article.PublishDate.DateTime; a.Title = article.Title.Text; a.Description = article.Summary.Text; a.GUID = "0000"; a.Link = article.Id; BD.Articles exist = (from el in chan.Articles where el.Link == a.Link select el).FirstOrDefault(); if (exist != null) { Debug.WriteLine("Test : " + a.Link + " exist : " + exist.Link); } if (exist == null) { Debug.WriteLine("Adding new article : " + a.Title); chan.Articles.Add(a); context.ArticlesSet.AddObject(a); } } } context.SaveChanges(); } } catch (Exception e) { Debug.WriteLine(e.Message); } }