public async System.Threading.Tasks.Task <PartialViewResult> Post(PostViewModel data) { Post newPost = new Post(); newPost.Post_Status = 0; _viewModel = new PostViewModel(); FieldHelper.CopyNotNullValue(newPost, data); newPost.CreatedDate = DateTime.Now; if (data.Option == 0 && newPost.Id_Type == 8) { //post to fb toiec var IdPost = await _fbService.PostingToGroupFB(newPost.Content); newPost.Id_PostFB = IdPost.id; } _postService.Add(newPost); _postService.Save(); // string url = MaHoaMD5.Encrypt(newPost.Id + "#" + newPost.UpdatedDate); //Send notify ApplicationUser userPost = _service.GetUserById(newPost.Id_User); FieldHelper.CopyNotNullValue(PostViewModel, userPost); FieldHelper.CopyNotNullValue(PostViewModel, newPost); PostViewModel.TypeToString = _postTypeService.GetById(newPost.Id_Type).Name; PostVoteDetail vote = _postVoteDetailService.getVoteByIdUser(newPost.Id_User, newPost.Id); if (vote != null) { PostViewModel.Vote = vote.Vote; } //Send noti for all user register var userIDList = getUserIDListBasedOnType(newPost.Id_Type); foreach (var userID in userIDList) { var sendPostToUser = _service.GetUserById(userID); if (sendPostToUser.Id_Messenger != userPost.Id_Messenger && sendPostToUser.Id_Messenger != null && _eventService.IsFreeTime(sendPostToUser.Email)) { //Create json send............ FBPostNoti newNoti = new FBPostNoti(); newNoti.recipient.id = sendPostToUser.Id_Messenger; newNoti.message.attachment.payload.text = "```\r\n" + "💬 Bạn có một câu hỏi: " + "\r\n" + '"' + newPost.Content + '"' + "\r\n```"; NotiButton button = new NotiButton(); button.payload = "REPLAY_" + newPost.Id; newNoti.message.attachment.payload.buttons.Add(button); // ChatBotMessenger.sendRequest(JsonConvert.SerializeObject(newNoti)); } } return(PartialView("_Post", PostViewModel)); }
public async Task <string> createNewPostViaFB(string messID, string containQues, int typeQues) { //Determine user var userMakeQues = _service.listUserID().Where(x => x.Id_Messenger == messID).ToList(); if (userMakeQues.Count != 0) { Post newPost = new Model.Post(); newPost.Content = containQues; newPost.DatePost = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds.ToString(); newPost.Id_User = userMakeQues.FirstOrDefault().Id; newPost.Id_Type = typeQues; // TOIEC //Post to fb group if (newPost.Id_Type == 8) { try { //post to fb toiec var IdPost = await _fbService.PostingToGroupFB(newPost.Content); newPost.Id_PostFB = IdPost.id; } catch (Exception e) { } } _postService.Add(newPost); _postService.Save(); //Send noti for all user register var userIDList = getUserIDListBasedOnType(typeQues); foreach (var userID in userIDList) { var sendToUser = _service.GetUserById(userID); if (sendToUser.Id_Messenger != messID && sendToUser.Id_Messenger != null && _eventService.IsFreeTime(sendToUser.Email)) { //Create json send............ FBPostNoti newNoti = new FBPostNoti(); newNoti.recipient.id = sendToUser.Id_Messenger; newNoti.message.attachment.payload.text = "```\r\n" + "💬 Bạn có một câu hỏi: " + "\r\n" + '"' + newPost.Content + '"' + "\r\n```"; NotiButton button = new NotiButton(); button.payload = "REPLAY_" + newPost.Id; newNoti.message.attachment.payload.buttons.Add(button); // ChatBotMessenger.sendRequest(JsonConvert.SerializeObject(newNoti)); } } } return(""); }