Esempio n. 1
0
 public static LecturesModel Convert(NewsModel obj)
 {
     LecturesModel res = new LecturesModel();
     res.text = obj.text;
     res.title = obj.title;
     return res;
 }
Esempio n. 2
0
 public static NewsModel Convert(LecturesModel obj)
 {
     NewsModel res = new NewsModel();
     res.id = -1;
     res.text = obj.text;
     res.title = obj.title;
     res.likes = 0;
     return res;
 }
Esempio n. 3
0
        public void AddNews(NewsModel news)
        {
            NewsCount++;
            news.id = NewsCount;
            AllNews.Add(news);

            xRoot.Add(new XElement("news",
                      new XAttribute("id", news.id),
                      new XElement("title", news.title),
                      new XElement("text", news.text),
                      new XElement("likes", news.likes)));
            xDoc.Save("news.xml");
        }
Esempio n. 4
0
        public void RemoveNews(NewsModel news)
        {
            NewsCount--;
            AllNews.Remove(news);

            foreach (XElement element in xDoc.Element("news").Elements("news"))
            {
                if (element.Attribute("id").Value == news.id.ToString())
                {
                    element.Remove();
                }
            }
            xDoc.Save("news.xml");
        }
Esempio n. 5
0
        public NewsStorage()
        {
            AllNews = new List<NewsModel>();
            NewsCount = 0;
            NewsModel news = new NewsModel();

            xDoc = XDocument.Load("news.xml");
            xRoot = xDoc.Element("news");

            foreach (XElement element in xDoc.Element("news").Elements("news"))
            {
                news.id = Int32.Parse(element.Attribute("id").Value); ;
                news.title = element.Element("title").Value;
                news.text = element.Element("text").Value;
                news.likes = Int32.Parse(element.Element("likes").Value);

                if (news.id > 0)
                {
                    NewsCount = news.id;
                    AllNews.Add(news);
                }
            }
        }