private void WriteFBCommentsPartial(int entryNextPosition, int rowPostion, List <FacebookPostComment> entries, String fileName)
        {
            var existingFile = new FileInfo(fileName);

            using (var package = new ExcelPackage(existingFile))
            {
                // Get the work book in the file
                var workBook = package.Workbook;
                if (workBook != null)
                {
                    if (workBook.Worksheets.Count > 0)
                    {
                        var currentWorksheet = workBook.Worksheets["7 Facebook raw data"];
                        for (int i = 0; i < _rowPerTime; i++)
                        {
                            int index = i + entryNextPosition;
                            if (index < entries.Count)
                            {
                                FacebookPostComment entry = entries[index];
                                currentWorksheet.Cells[rowPostion, 1].Value = entry.PostUrl;
                                currentWorksheet.Cells[rowPostion, 2].Value = entry.Post;
                                currentWorksheet.Cells[rowPostion, 3].Value = ConvertToJson(DateTime.Parse(entry.PostTimestamp));
                                if (entry.PostComment != null)
                                {
                                    currentWorksheet.Cells[rowPostion, 4].Value = entry.PostComment;
                                }
                                if (entry.ResponseTime != null)
                                {
                                    currentWorksheet.Cells[rowPostion, 5].Value = entry.Response;
                                    currentWorksheet.Cells[rowPostion, 6].Value = ConvertToJson(DateTime.Parse(entry.ResponseTime));
                                }
                            }
                            else
                            {
                                break;
                            }
                            rowPostion++;
                        }
                        package.Save();
                    }
                }
            }
        }
        private void SaveToDB(List <FacebookPost> posts, List <FacebookAlbum> albums)
        {
            Database context = new Database();

            // clear all existing postComment of this assessment
            context.facebookPostComments.RemoveRange(context.facebookPostComments.Where(x => x.AssessmentId == _assessment.Id));
            foreach (FacebookPost post in posts)
            {
                if (post.comments != null)
                {
                    foreach (FacebookComment comment in post.comments.data)
                    {
                        FacebookPostComment facebookPostComment = new FacebookPostComment();
                        facebookPostComment.AssessmentId  = _assessment.Id;
                        facebookPostComment.FacebookId    = _pageId;
                        facebookPostComment.Post          = post.message;
                        facebookPostComment.PostComment   = comment.message;
                        facebookPostComment.PostTimestamp = comment.created_time;
                        facebookPostComment.PostUrl       = post.actions[0].link;
                        if (comment.first_reply != null)
                        {
                            facebookPostComment.Response     = comment.first_reply;
                            facebookPostComment.ResponseTime = comment.first_reply_time;
                        }
                        context.facebookPostComments.Add(facebookPostComment);
                    }
                }
                else
                {
                    FacebookPostComment facebookPostComment = new FacebookPostComment();
                    facebookPostComment.AssessmentId  = _assessment.Id;
                    facebookPostComment.FacebookId    = _pageId;
                    facebookPostComment.Post          = post.message;
                    facebookPostComment.PostTimestamp = post.created_time;
                    facebookPostComment.PostUrl       = post.actions[0].link;
                    context.facebookPostComments.Add(facebookPostComment);
                }
            }

            foreach (FacebookAlbum album in albums)
            {
                if (album.comments != null)
                {
                    foreach (FacebookComment comment in album.comments.data)
                    {
                        FacebookPostComment facebookPostComment = new FacebookPostComment();
                        facebookPostComment.AssessmentId  = _assessment.Id;
                        facebookPostComment.FacebookId    = _pageId;
                        facebookPostComment.Post          = album.name;
                        facebookPostComment.PostComment   = comment.message;
                        facebookPostComment.PostTimestamp = comment.created_time;
                        facebookPostComment.PostUrl       = album.link;
                        if (comment.first_reply != null)
                        {
                            facebookPostComment.Response     = comment.first_reply;
                            facebookPostComment.ResponseTime = comment.first_reply_time;
                        }
                        context.facebookPostComments.Add(facebookPostComment);
                    }
                }
                else
                {
                    FacebookPostComment facebookPostComment = new FacebookPostComment();
                    facebookPostComment.AssessmentId  = _assessment.Id;
                    facebookPostComment.FacebookId    = _pageId;
                    facebookPostComment.Post          = album.name;
                    facebookPostComment.PostTimestamp = album.created_time;
                    facebookPostComment.PostUrl       = album.link;
                    context.facebookPostComments.Add(facebookPostComment);
                }
            }
            context.SaveChanges();
        }