Beispiel #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));
            }
        }
        public static ChromeNotification WithPayload(this ChromeNotification n, string payload)
        {
            if (payload.Length > 256)
            {
                throw new ArgumentOutOfRangeException("Payload length must be <= 256");
            }

            n.Payload = payload;
            return(n);
        }
Beispiel #3
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));
                }
            }
        }
Beispiel #4
0
        public void TestOAuth()
        {
            var wait = new ManualResetEvent(false);

            var chan = new ChromePushChannel(new ChromePushChannelSettings(oauthClientId, oauthSecret)
            {
                AuthorizationCode = "4/Ndq0smr04tldagzUcJa9MFdamaAt.srbbbJRseYMTmmS0T3UFEsOetIXtfQI",
                RefreshToken      = "1/3n7TKFv2xoHNBuKqHEXDLpiBZJVGkExnR1K_uHhU0H4"
            });

            var n = new ChromeNotification();

            n.ChannelId    = "14952429134341445468/nndgomkogokhhfiogeamahchcbkldiok";
            n.SubChannelId = ChromeNotificationSubChannel.SubChannel0;
            n.Payload      = "Test";

            var cb = new PushSharp.Core.SendNotificationCallbackDelegate((sender, response) => wait.Set());

            chan.SendNotification(n, cb);

            wait.WaitOne();
        }
 public static ChromeNotification ForChannelId(this ChromeNotification n, string channelId)
 {
     n.ChannelId = channelId;
     return(n);
 }
 public static ChromeNotification ForSubChannelId(this ChromeNotification n, ChromeNotificationSubChannel subChannel)
 {
     n.SubChannelId = subChannel;
     return(n);
 }