/// <summary>
        /// Method to retrieve deadlines for a course
        /// </summary>
        /// <param name="cookie"></param>
        /// <param name="deadlineId"></param>
        /// <returns></returns>
        public async Task <List <Deadlines> > RetrieveDeadlinesByCourseId(string cookie, int deadlineId)
        {
            try
            {
                using (HttpClient retrieveDeadlinesClient = new HttpClient())
                {
                    retrieveDeadlinesClient.DefaultRequestHeaders.Add("Authorization", "Token token=" + Constant.BACKPACKAPIKEY + "");
                    retrieveDeadlinesClient.DefaultRequestHeaders.Add("Cookie", cookie);

                    string responseDeadlines = await retrieveDeadlinesClient.GetStringAsync(new Uri(Constant.BASEURL + Constant.RETRIEVEDEADLINES + deadlineId, UriKind.Absolute));

                    List <Deadlines> deadlineDetails = JsonConvert.DeserializeObject <List <Deadlines> >(responseDeadlines);
                    for (int i = 0; i < deadlineDetails.Count; i++)
                    {
                        string htmlDeadlineBody = WebUtility.HtmlDecode(deadlineDetails[i].Body);
                        string parsedBody       = objParser.ParseHTMLContent(htmlDeadlineBody);
                        deadlineDetails[i].ParsedBody = parsedBody;
                    }
                    return(deadlineDetails);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async void Discussion_Loaded(object sender, RoutedEventArgs e)
        {
            //Progress Indicator
            SystemTray.ProgressIndicator = new ProgressIndicator();
            ProgressIndicator(true);
            SystemTray.ProgressIndicator.Text = "Loading...Please wait";

            var discussion = App.Current as App;

            userId                 = discussion.User.UserId;
            cookie                 = discussion.Cookie;
            discussionId           = discussion.Discussion.DiscussionId;
            subject                = discussion.Discussion.Subject;
            txtSubect.Text         = objParser.ParseHTMLContent(WebUtility.HtmlDecode(subject));
            txtSubect.TextWrapping = TextWrapping.Wrap;


            objDiscussion = await RetrieveDiscussions(cookie, discussionId);

            //discussion value
            string discuss = objParser.ParseHTMLContent(WebUtility.HtmlDecode(objDiscussion.Body));

            txtDiscussion.Text         = discuss;
            txtDiscussion.TextWrapping = TextWrapping.Wrap;
            StackPanel spComments = new StackPanel();

            for (int i = 0; i < objDiscussion.Replies.Count; i++)
            {
                //Generate rectangle 1st, then add 2 textbolck--one for Name,one for comments text and then add that rectangle to stackpanel

                //Creating border for each reply and attaching it to main spReply StackPanel
                Border breachReply = new Border();
                breachReply.Name            = "breachReply" + i;
                breachReply.BorderThickness = new Thickness(2, 2, 2, 2);
                breachReply.CornerRadius    = new CornerRadius(5);
                breachReply.BorderBrush     = new SolidColorBrush(Colors.White);
                breachReply.Margin          = new Thickness(0, 15, 0, 0);

                //parent of reply border
                spReply.Children.Add(breachReply);

                //stack panel to hold a reply and all the comments and add it to border(parent)
                StackPanel spCommentAndReply = new StackPanel();
                breachReply.Child = spCommentAndReply;


                StackPanel speachReply = new StackPanel();

                //Adding textbox for reply
                TextBlock tbName = new TextBlock();

                //tbName.Text = "Kumar" + i;
                string repliesName = objParser.ParseHTMLContent(WebUtility.HtmlDecode(objDiscussion.Replies[i].UserName));
                tbName.Text         = repliesName;
                tbName.TextWrapping = TextWrapping.Wrap;
                speachReply.Children.Add(tbName);

                TextBlock tbRply = new TextBlock();
                //tbRply.Text = "Reply" + i;
                string repliesBody = objParser.ParseHTMLContent(WebUtility.HtmlDecode(objDiscussion.Replies[i].Body));
                tbRply.Text          = repliesBody;
                tbReply.TextWrapping = TextWrapping.Wrap;


                speachReply.Children.Add(tbRply);
                //added reply  to spCommentReply stack panel
                spCommentAndReply.Children.Add(speachReply);

                //Adding textbox for comments for each reply
                for (int j = 0; j < objDiscussion.Replies[i].Comments.Count; j++)
                {
                    //Boder for comments
                    Border brComments = new Border();
                    brComments.BorderThickness = new Thickness(2, 2, 2, 2);
                    brComments.CornerRadius    = new CornerRadius(5);
                    brComments.BorderBrush     = new SolidColorBrush(Colors.White);
                    brComments.Margin          = new Thickness(5, 10, 5, 0);

                    StackPanel speachComments = new StackPanel();
                    //added border child speachcomment
                    brComments.Child = speachComments;

                    //Adding textblock for comments
                    TextBlock tbNameComments = new TextBlock();
                    //tbNameComments.Text = "Kumar" + j;
                    string commentsName = objParser.ParseHTMLContent(WebUtility.HtmlDecode(objDiscussion.Replies[i].Comments[j].UserName));
                    tbNameComments.Text         = commentsName;
                    tbNameComments.TextWrapping = TextWrapping.Wrap;

                    TextBlock tbComment = new TextBlock();
                    //tbComment.Text = "Comment" + j;
                    string commentBody = objParser.ParseHTMLContent(WebUtility.HtmlDecode(objDiscussion.Replies[i].Comments[j].comment));
                    tbComment.Text         = commentBody;
                    tbComment.TextWrapping = TextWrapping.Wrap;

                    speachComments.Children.Add(tbNameComments);
                    speachComments.Children.Add(tbComment);
                    spCommentAndReply.Children.Add(brComments);
                }

                //stack panel for sending comments
                StackPanel spsendComment = new StackPanel();
                spsendComment.Orientation = System.Windows.Controls.Orientation.Horizontal;
                //Adding textbox at last to enter comments for each reply
                TextBox tbLastComment = new TextBox();
                //assign id to a comment textbox
                tbLastComment.Name  = "LastComment" + i;
                tbLastComment.Width = 300;
                tbLastComment.Text  = "Enter your comments";
                spsendComment.Children.Add(tbLastComment);
                Button btnSend = new Button();
                //i will have discussion id
                btnSend.Click  += btnSend_Click;
                btnSend.Tag     = i;
                btnSend.Name    = "btnComnt" + i;
                btnSend.Content = "Comments";
                //btnSend.Width = 30;
                spsendComment.Children.Add(btnSend);
                spCommentAndReply.Children.Add(spsendComment);
            }

            //adding border for send reply
            Border brsendReply = new Border();

            brsendReply.BorderThickness = new Thickness(2, 2, 2, 2);
            brsendReply.CornerRadius    = new CornerRadius(5);
            brsendReply.BorderBrush     = new SolidColorBrush(Colors.White);
            brsendReply.Margin          = new Thickness(0, 25, 0, 0);


            //Adding textbox at last to enter reply..created stackpanel for placing textbox and button as c chold of spreply
            StackPanel spSendReply = new StackPanel();

            brsendReply.Child       = spSendReply;
            spSendReply.Orientation = System.Windows.Controls.Orientation.Vertical;
            //TextBox tbReply = new TextBox();
            tbReply.Text = "Enter Reply";
            spSendReply.Children.Add(tbReply);
            Button btnReply = new Button();

            btnReply.Content             = "Reply";
            btnReply.HorizontalAlignment = HorizontalAlignment.Right;
            btnReply.Click += btnReply_Click;
            //btnReply.Width = 30;
            spSendReply.Children.Add(btnReply);
            spReply.Children.Add(brsendReply);

            ProgressIndicator(false);
        }
        /// <summary>
        /// This event is fired when the Course detail page will be loaded. This method fetch the course info,deadlines,resources and discussion details
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void CourseDetail_Loaded(object sender, RoutedEventArgs e)
        {
            //Progress Indicator
            SystemTray.ProgressIndicator      = new ProgressIndicator();
            SystemTray.ProgressIndicator.Text = "Loading...Please wait";
            ProgressIndicator(true);

            var cookieApp = App.Current as App;

            cookie = cookieApp.Cookie;
            var userApp = App.Current as App;

            user = userApp.User;

            var courseApp = App.Current as App;

            courseId = courseApp.CourseId;

            //course info binding
            await RetrieveCourseDetails();

            if (objCourse.Overview == null)
            {
                tbOverview.Visibility  = System.Windows.Visibility.Collapsed;
                txtOverview.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                string htmlOverview = WebUtility.HtmlDecode(objCourse.Overview);
                string overview     = objParser.ParseHTMLContent(htmlOverview);
                txtOverview.Text = overview;
            }

            if (objCourse.TextBooks == null)
            {
                tbTextBooks.Visibility  = System.Windows.Visibility.Collapsed;
                txtTextBooks.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                string htmlTextbook = WebUtility.HtmlDecode(objCourse.TextBooks);
                string textbooks    = objParser.ParseHTMLContent(htmlTextbook);
                txtTextBooks.Text = textbooks;
            }

            if (objCourse.OfficeHours == null)
            {
                tbOfficeHours.Visibility  = System.Windows.Visibility.Collapsed;
                txtOfficeHours.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                string htmlOfficeHours = WebUtility.HtmlDecode(objCourse.OfficeHours);
                string officeHours     = objParser.ParseHTMLContent(htmlOfficeHours);
                txtOfficeHours.Text = officeHours;
            }

            if (objCourse.Credits == 0)
            {
                tbCourseCredits.Visibility  = System.Windows.Visibility.Collapsed;
                txtCourseCredits.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                txtCourseCredits.Text = objCourse.Credits.ToString();
            }

            if (objCourse.Evaluation == null)
            {
                tbEvaluation.Visibility  = System.Windows.Visibility.Collapsed;
                txtEvaluation.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                string htmlEvaluation = WebUtility.HtmlDecode(objCourse.Evaluation);
                string evaluation     = objParser.ParseHTMLContent(htmlEvaluation);
                txtEvaluation.Text = evaluation;
            }

            if (objCourse.Timings == null)
            {
                tbClassTimings.Visibility = System.Windows.Visibility.Collapsed;
                txtClassTiming.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                string htmlTimings = WebUtility.HtmlDecode(objCourse.Timings);
                string timings     = objParser.ParseHTMLContent(htmlTimings);
                txtClassTiming.Text = timings;
            }


            //course info pivot binding
            CourseInfoPivot.Title = objCourse.CourseName + "-" + objCourse.CourseCode;

            //deadlines binding
            listDeadlines = await RetrieveDeadlines();

            if (listDeadlines.Count != 0)
            {
                List <Deadlines> sortedDeadlines = new List <Deadlines>();
                //sorting the deadlines based on DueOn date
                sortedDeadlines          = listDeadlines.OrderByDescending(s => s.DueOn).ToList <Deadlines>();
                lstDeadlines.ItemsSource = sortedDeadlines;
            }
            else
            {
                tbNoDeadLines.Visibility = System.Windows.Visibility.Visible;
                tbNoDeadLines.Text       = Constant.NOCOURSEDEADLINES;
                lstDeadlines.Visibility  = System.Windows.Visibility.Collapsed;
            }

            //Fetching all the resources
            listResources = await RetrieveResources();

            //Lecture resource
            var lectureResources = listResources.Where(s => s.ResourceType == "Lecture").ToList <Usebackpack.Model.Resources>();
            //tutorial resource
            var tutorialResources = listResources.Where(s => s.ResourceType == "Tutorial").ToList <Usebackpack.Model.Resources>();
            //video resource
            var videoResources = listResources.Where(s => s.ResourceType == "Video").ToList <Usebackpack.Model.Resources>();
            //research paper resources
            var researchPaperResources = listResources.Where(s => s.ResourceType == "Research Paper").ToList <Usebackpack.Model.Resources>();
            //exam resources
            var examResources = listResources.Where(s => s.ResourceType == "Exam").ToList <Usebackpack.Model.Resources>();
            //project resources
            var projectResources = listResources.Where(s => s.ResourceType == "Project").ToList <Usebackpack.Model.Resources>();


            if (lectureResources.Count != 0)
            {
                txtLectureRType.Visibility     = System.Windows.Visibility.Visible;
                lstLectureResource.Visibility  = System.Windows.Visibility.Visible;
                lstLectureResource.ItemsSource = lectureResources;
            }

            if (tutorialResources.Count != 0)
            {
                txtTutorialRType.Visibility      = System.Windows.Visibility.Visible;
                lstTutorialsResource.Visibility  = System.Windows.Visibility.Visible;
                lstTutorialsResource.ItemsSource = tutorialResources;
            }

            if (videoResources.Count != 0)
            {
                txtVideoRType.Visibility      = System.Windows.Visibility.Visible;
                lstVideosResource.Visibility  = System.Windows.Visibility.Visible;
                lstVideosResource.ItemsSource = videoResources;
            }

            if (researchPaperResources.Count != 0)
            {
                txtReserachPaperRType.Visibility     = System.Windows.Visibility.Visible;
                lstResearchPaperResource.Visibility  = System.Windows.Visibility.Visible;
                lstResearchPaperResource.ItemsSource = researchPaperResources;
            }

            if (examResources.Count != 0)
            {
                txtExamRType.Visibility      = System.Windows.Visibility.Visible;
                lstExamsResource.Visibility  = System.Windows.Visibility.Visible;
                lstExamsResource.ItemsSource = examResources;
            }

            if (examResources.Count == 0 || researchPaperResources.Count == 0 || videoResources.Count == 0 || lectureResources.Count == 0 || tutorialResources.Count == 0)
            {
                tbNoResources.Visibility = System.Windows.Visibility.Visible;
                tbNoResources.Text       = Constant.NORESOURCES;
            }

            //Code to bind discussions
            lstDiscussion = objCourse.Discussion;
            if (lstDiscussion.Count != 0)
            {
                listDiscussion.ItemsSource = lstDiscussion;
            }

            ProgressIndicator(false);
        }