Example #1
0
        public static void addPost(XmlPost post, int topicId)
        {
            List <XmlPost> posts = XmlPost.getPosts(topicId);

            posts.Add(post);
            XmlRootAttribute oRootAttr = new XmlRootAttribute()
            {
                ElementName = "Posts", IsNullable = true
            };
            XmlSerializer oSerializer   = new XmlSerializer(typeof(List <XmlPost>), oRootAttr);
            StreamWriter  oStreamWriter = null;

            try
            {
                oStreamWriter = new StreamWriter("TopicsStorage/" + topicId + ".xml");
                oSerializer.Serialize(oStreamWriter, posts);
            }
            catch (Exception oException)
            {
                Console.WriteLine("Aplikacja wygenerowała następujący wyjątek: " + oException.Message);
            }
            finally
            {
                if (null != oStreamWriter)
                {
                    oStreamWriter.Dispose();
                }
            }
        }
Example #2
0
 public List <XmlPost> GetPosts(int id)
 {
     using (var dbContext = new ApplicationDbContext())
     {
         var topicInfo = dbContext.Topics.FirstOrDefault(t => t.Id == id);
         return(XmlPost.getPosts(id));
     }
 }