Exemplo n.º 1
0
        public async Task <PartialViewResult> Comment(CommentViewModel data, bool IsFromBot = false)
        {
            _viewModel = new CommentViewModel();
            Comment comment = new Comment();

            FieldHelper.CopyNotNullValue(comment, data);
            comment.Corrected = false;
            //  comment.CreatedBy =
            comment.DateComment = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds.ToString();
            _commentOfPost.Add(comment);
            _commentOfPost.Save();
            Post post = _postService.GetById(comment.Id_Post);

            post.Comment++;
            _postService.Update(post);
            _postService.Save();
            ApplicationUser user = _service.GetUserById(comment.Id_User);

            FieldHelper.CopyNotNullValue(CommentViewModel, user);
            FieldHelper.CopyNotNullValue(CommentViewModel, comment);
            CommentViewModel.Id_UserPost = post.Id_User;
            if (data.Id_Comment == 0)
            {
                if (CommentViewModel.Id_UserPost != User.Identity.GetUserId())
                {
                    Notification notification = new Notification();
                    notification.Id_User     = data.Id_User;
                    notification.Id_Friend   = CommentViewModel.Id_UserPost;
                    notification.Id_Post     = data.Id_Post;
                    notification.Id_Comment  = comment.Id;
                    notification.DateComment = data.DateComment;
                    var userOfPost = _service.GetUserById(post.Id_User);
                    //Send noti to chrome
                    //
                    _notificationService.Add(notification);
                    _notificationService.Save();
                    //Send noti via chatbot
                    ChatBotMessenger.sendTextMeg(userOfPost.Id_Messenger, "🔥 *Câu hỏi:* " + post.Content + "\r\n" + "✎ *Đáp án:* " + comment.Content);
                    //Send noti for chrome
                    ChromeNotiJson postJson = new ChromeNotiJson();
                    postJson.title       = "Bạn có câu trả lời: ";
                    postJson.text        = post.Content + "<br/>" + comment.Content;
                    postJson.urlQuestion = "http://olympusenglish.azurewebsites.net/Post?id=" + post.Id;
                    if (IsFromBot)
                    {
                        ChromeNotification.sendNoti(userOfPost.Email, post.Id, comment.Id);
                    }
                    await NotificationHub.sendNoti(userOfPost.Email, JsonConvert.SerializeObject(postJson));
                }
                return(PartialView("_Comment", CommentViewModel));
            }
            else
            {
                return(PartialView("_ChildComment", CommentViewModel));
            }
        }
Exemplo n.º 2
0
        public async Task CheckAnswerOnFB()
        {
            //Lay danh sách cac bài post chưa có câu trả lời
            //  var listPost = _postService.GetAll().Where(x => x.Id_PostFB != null && x.Post_Status == 0);
            var listPost = _postService.checkPostOnGroup();

            foreach (var post in listPost)
            {
                var dapAn = await _fbService.DetectedAnswOfPost(post.Id_PostFB);

                if (dapAn != "")
                {
                    post.Post_Status = 10;
                    Comment comment = new Comment();
                    comment.Corrected = false;
                    comment.Content   = dapAn;
                    //Admin
                    comment.Id_User     = post.Id_User;
                    comment.Id_Post     = post.Id;
                    comment.DateComment = DateTime.Now.Ticks.ToString();
                    _commentOfPost.Add(comment);
                    _commentOfPost.Save();
                    _postService.Update(post);
                    _postService.Save();

                    //Send noti via chatbot
                    var userOfPost = _service.GetUserById(post.Id_User);
                    //   var userOfCmt = _service.GetUserById(comment.Id_User);
                    ChatBotMessenger.sendTextMeg(userOfPost.Id_Messenger, "🔥 *Câu hỏi:* " + post.Content + "\r\n" + "✎ *Đáp án:* " + comment.Content);
                    //Send noti for chrome
                    ChromeNotiJson postJson = new ChromeNotiJson();
                    postJson.title       = "Bạn có câu trả lời: ";
                    postJson.text        = post.Content + "<br/>" + comment.Content;
                    postJson.urlQuestion = "http://olympusenglish.azurewebsites.net/Post?id=" + post.Id;
                    //if (IsFromBot)
                    {
                        ChromeNotification.sendNoti(userOfPost.Email, post.Id, comment.Id);
                    }
                    await NotificationHub.sendNoti(userOfPost.Email, JsonConvert.SerializeObject(postJson));
                }
            }
        }
Exemplo n.º 3
0
        protected async System.Threading.Tasks.Task <string> sendNofityToMessenger(Post post, ApplicationUser user)
        {
            ChromeNotiJson postJson = new ChromeNotiJson();

            postJson.title       = "Bạn có một câu hỏi: ";
            postJson.text        = post.Content;
            postJson.urlQuestion = "http://olympusenglish.azurewebsites.net/Post?id=" + post.Id;
            NotificationHub.sendNoti(user.Email, JsonConvert.SerializeObject(postJson));
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            var paramChatfuel = "https://api.chatfuel.com/bots/59a43f64e4b03a25b73c0ebd/users/" + user.Id_Messenger + "/" + "send?chatfuel_token=vnbqX6cpvXUXFcOKr5RHJ7psSpHDRzO1hXBY8dkvn50ZkZyWML3YdtoCnKH7FSjC&chatfuel_block_id=5a294932e4b0d0e603f29776";

            paramChatfuel += "&title=Bạn có 1 câu hỏi :" + post.Content;
            //MaHoaMD5.Encrypt()
            paramChatfuel += "&url=http://olympusenglish.azurewebsites.net/Post?id=" + post.Id;
            paramChatfuel += "&idques=" + post.Id;
            paramChatfuel += ChatBotMessenger.getVocaNull();
            var response2 = await client.PostAsync(paramChatfuel, null);

            return("");
        }