Пример #1
0
 public static string forumTopicsTemplateSerializer(CollectionForumTopicsTemplate rforumtopicstemplate)
 {
     string response = JsonConvert.SerializeObject(rforumtopicstemplate);
     return response;
 }
Пример #2
0
        private async void PostTopic_Click(object sender, RoutedEventArgs e)
        {
            RootObjectForumTopics rftopics = new RootObjectForumTopics();
            CollectionForumTopicsTemplate rfttemplate = new CollectionForumTopicsTemplate();
            RootObjectUsers ruser = new RootObjectUsers();
            RootObjectForumPosts rfposts = new RootObjectForumPosts();
            CollectionForumPostsTemplate rfptemplate = new CollectionForumPostsTemplate();
            if (Subject.Text == "" || Message.Text == "")
            {

            } 
            else
            {
                try
                {
                    /// filling out the template for Forum Topics
                    string forumtopic = await mlibrary.readFile("forum_topics");
                    rftopics = forum_topics.forumtopicsDataDeserializer(forumtopic);
                    rfttemplate = rftopics.collection.template;
                    Hashtable rfttemplate_ht = new Hashtable();
                    for (int i = 0; i < rfttemplate.data.Count; i++)
                    {
                        rfttemplate_ht.Add(rfttemplate.data[i].name, i);
                    }
                    rfttemplate.data[(int)rfttemplate_ht["title"]].value = Subject.Text;
                    if (broadcast_to_team.IsChecked == true)
                    {
                        rfttemplate.data[(int)rfttemplate_ht["is_announcement"]].value = true;
                    }
                    else
                    {
                        rfttemplate.data[(int)rfttemplate_ht["is_announcement"]].value = false;
                    }
                    rfttemplate.data[(int)rfttemplate_ht["team_id"]].value = teamid.ToString();
                    rfttemplate.data[(int)rfttemplate_ht["type"]].value = "forum_topic";
                    string rftresponse = forum_topics.forumTopicsTemplateSerializer(rfttemplate);
                    rftresponse = "{\"template\":" + rftresponse + "}";
                    Debug.WriteLine(rftresponse);
                    // make POST to forum_topic
                    await APILibrary.apiPOST((string)ApplicationData.Current.LocalSettings.Values["Tokens"], rftresponse, rftopics.collection.href);

                    // read POST response to fetch message id.
                    string postresp = await mlibrary.readFile("POSTresponse");
                    rftopics = forum_topics.forumtopicsDataDeserializer(postresp);

                    string userclass = await mlibrary.readSerializedUserClass();
                    Debug.WriteLine(userclass);
                    ruser = Users.usersDataDeserializer(userclass);
                    Debug.WriteLine(ruser.items[0].id);
                    /// filling out the template for forum posts
                    string forumposts = await mlibrary.readFile("forum_posts");
                    rfposts = forum_posts.forumpostsDataDeserializer(forumposts);
                    rfptemplate = rfposts.collection.template;
                    Hashtable rfptemplate_ht = new Hashtable();
                    for(int i=0; i < rfptemplate.data.Count; i++)
                    {
                        rfptemplate_ht.Add(rfptemplate.data[i].name, i);
                    }
                    long teammember_id = 0;
                    for (int i = 0; i < ruser.teams.Count; i++)
                    {
                        if (ruser.teams[i].id == (long)ApplicationData.Current.LocalSettings.Values["currentTeamID"])
                        {
                            teammember_id = ruser.teams[i].loggedInUsersmemberID;
                        }
                    }
                    rfptemplate.data[(int)rfptemplate_ht["forum_topic_id"]].value = rftopics.collection.items[0].data[0].value;
                    rfptemplate.data[(int)rfptemplate_ht["member_id"]].value = teammember_id;
                    rfptemplate.data[(int)rfptemplate_ht["message"]].value = Message.Text;
                    rfptemplate.data[(int)rfptemplate_ht["broadcast_to_team"]].value = rfttemplate.data[(int)rfttemplate_ht["is_announcement"]].value;
                    rfptemplate.data[(int)rfptemplate_ht["type"]].value = "forum_post";

                    string rfpresponse = forum_posts.forumpostsTemplateSerializer(rfptemplate);
                    rfpresponse = "{\"template\":" + rfpresponse + "}";
                    string remove = "{\"name\":\"division_member_id\",\"value\":null},";
                    int index = rfpresponse.IndexOf(remove);
                    rfpresponse = (index < 0) ? rfpresponse : rfpresponse.Remove(index, remove.Length);

                    Debug.WriteLine(rfpresponse);
                    await APILibrary.apiPOST((string)ApplicationData.Current.LocalSettings.Values["Tokens"], rfpresponse, rfposts.collection.href);
                    Frame rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(Forums), teamid);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Exception returned in AddNewForumTopic.xaml.cs : " + ex);
                    Frame rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(Forums), teamid);
                }
            }
        }