Пример #1
0
        public void initChatBotMenu()
        {
            ChatbotMenu menu = new ChatbotMenu();
            //
            PersistentMenu infoMenu = new PersistentMenu();

            //
            infoMenu.locale          = "default";
            infoMenu.call_to_actions = new List <CallToAction>();
            //\
            CallToAction parentMenu3 = new CallToAction();

            parentMenu3.title           = "🔍 Đặt câu hỏi nhanh ";
            parentMenu3.type            = "nested";
            parentMenu3.call_to_actions = new List <CallToAction2>();
            //Child menu
            foreach (var typeObj in _postTypeService.GetAll())
            {
                CallToAction2 childMenu = new CallToAction2();
                childMenu.payload = "POST_TYPE_" + typeObj.Id;
                childMenu.title   = "🚩." + typeObj.Name;
                childMenu.type    = "postback";
                parentMenu3.call_to_actions.Add(childMenu);
            }
            infoMenu.call_to_actions.Add(parentMenu3);
            //
            CallToAction parentMenu = new CallToAction();

            parentMenu.title   = "🎓 Xác thực token với Olympus";
            parentMenu.type    = "postback";
            parentMenu.payload = "XACTHUC";
            infoMenu.call_to_actions.Add(parentMenu);
            //
            CallToAction parentMenu2 = new CallToAction();

            parentMenu2.title   = "💡 Luyện tập";
            parentMenu2.type    = "postback";
            parentMenu2.payload = "LUYENTAP";
            infoMenu.call_to_actions.Add(parentMenu2);
            //

            menu.persistent_menu.Add(infoMenu);
            ChatBotMessenger.sendRequest(JsonConvert.SerializeObject(menu, Newtonsoft.Json.Formatting.None,
                                                                     new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            }), true);
        }
Пример #2
0
        public ActionResult Index(int id, int?Comment)
        {
            string id_user = User.Identity.GetUserId();

            _viewModel = new PostViewModel();
            CreateLayoutView("Trả lời câu hỏi");
            Post            post = _postService.GetById(id);
            ApplicationUser user = _service.GetUserById(post.Id_User);

            FieldHelper.CopyNotNullValue(PostViewModel, user);
            FieldHelper.CopyNotNullValue(PostViewModel, post);
            PostViewModel.TypeToString = _postTypeService.GetById(post.Id_Type).Name;
            PostVoteDetail   votePost         = _postVoteDetailService.getVoteByIdUser(id_user, post.Id);
            CommentViewModel commentCorrected = null;

            if (votePost != null)
            {
                PostViewModel.Vote = votePost.Vote;
            }
            List <Comment> listComment      = new List <Comment>();
            List <Comment> listChildComment = new List <Comment>();

            listComment = _commentOfPost.getCommentOfPost(post.Id);
            foreach (var parent in listComment)
            {
                CommentViewModel commentViewModel = new CommentViewModel();
                user = _service.GetUserById(parent.Id_User);
                CommentVoteDetail voteComment = _commentVoteDetailService.getVoteByIdUser(id_user, parent.Id);
                if (voteComment != null)
                {
                    commentViewModel.Vote = voteComment.Vote;
                }
                FieldHelper.CopyNotNullValue(commentViewModel, user);
                FieldHelper.CopyNotNullValue(commentViewModel, parent);
                listChildComment = _commentOfPost.getChildOfComment(parent.Id_Post, parent.Id);
                if (listChildComment.Count != 0)
                {
                    foreach (var child in listChildComment)
                    {
                        CommentViewModel commentChildViewModel = new CommentViewModel();
                        user = _service.GetUserById(child.Id_User);
                        FieldHelper.CopyNotNullValue(commentChildViewModel, user);
                        FieldHelper.CopyNotNullValue(commentChildViewModel, child);
                        commentViewModel.listChildComment.Add(commentChildViewModel);
                    }
                }
                if (Comment != null && commentViewModel.Id.Equals(Comment))
                {
                    PostViewModel.listComment.Insert(0, commentViewModel);
                }
                else
                {
                    if (commentViewModel.Corrected)
                    {
                        commentCorrected = commentViewModel;
                    }
                    else
                    {
                        PostViewModel.listComment.Add(commentViewModel);
                    }
                }
            }
            if (commentCorrected != null)
            {
                PostViewModel.listComment.Insert(0, commentCorrected);
            }
            List <PostType>          listPostType          = _postTypeService.GetAll().ToList();
            List <PostTypeViewModel> listPostTypeViewModel = new List <PostTypeViewModel>();

            foreach (PostType item in listPostType)
            {
                PostTypeViewModel postType = new PostTypeViewModel();
                FieldHelper.CopyNotNullValue(postType, item);
                postType.Register = _detailUserTypeService.getRegisterPostType(id_user, item.Id);
                listPostTypeViewModel.Add(postType);
            }
            ViewBag.ListPostType = listPostTypeViewModel;
            return(View(PostViewModel));
        }
Пример #3
0
        public ActionResult NewsFeed(string username)
        {
            _viewModel = new NewsFeedViewModel();
            CreateLayoutView("Trang cá nhân");
            if (username == "false")
            {
                username = _viewModel.User.UserName;
            }
            ApplicationUser userCur = _service.GetUserByUserName(username);

            FieldHelper.CopyNotNullValue(NewsFeedViewModel, userCur);

            List <Post> listPost = new List <Post>();

            listPost = _postService.getPostByUser(userCur.Id).Take(5).ToList();
            NewsFeedViewModel.ListPostType = _postTypeService.GetAll().ToList();

            foreach (Post post in listPost)
            {
                PostViewModel   postViewModel = new PostViewModel();
                ApplicationUser user          = _service.GetUserById(post.Id_User);
                FieldHelper.CopyNotNullValue(postViewModel, user);
                FieldHelper.CopyNotNullValue(postViewModel, post);

                postViewModel.TypeToString = _postTypeService.GetById(post.Id_Type).Name;
                PostVoteDetail votePost = _postVoteDetailService.getVoteByIdUser(NewsFeedViewModel.Id, post.Id);
                if (votePost != null)
                {
                    postViewModel.Vote = votePost.Vote;
                }
                List <Comment> listComment      = new List <Comment>();
                List <Comment> listChildComment = new List <Comment>();
                listComment = _commentOfPost.getCommentOfPost(post.Id);
                foreach (var parent in listComment)
                {
                    CommentViewModel commentViewModel = new CommentViewModel();
                    user = _service.GetUserById(parent.Id_User);
                    CommentVoteDetail voteComment = _commentVoteDetailService.getVoteByIdUser(NewsFeedViewModel.Id, parent.Id);
                    if (voteComment != null)
                    {
                        commentViewModel.Vote = voteComment.Vote;
                    }
                    FieldHelper.CopyNotNullValue(commentViewModel, user);
                    FieldHelper.CopyNotNullValue(commentViewModel, parent);
                    listChildComment = _commentOfPost.getChildOfComment(parent.Id_Post, parent.Id);
                    if (listChildComment.Count != 0)
                    {
                        foreach (var child in listChildComment)
                        {
                            CommentViewModel commentChildViewModel = new CommentViewModel();
                            user = _service.GetUserById(child.Id_User);
                            FieldHelper.CopyNotNullValue(commentChildViewModel, user);
                            FieldHelper.CopyNotNullValue(commentChildViewModel, child);
                            commentViewModel.listChildComment.Add(commentChildViewModel);
                        }
                    }
                    if (commentViewModel.Corrected)
                    {
                        postViewModel.listComment.Insert(0, commentViewModel);
                    }
                    else
                    {
                        postViewModel.listComment.Add(commentViewModel);
                    }
                }
                NewsFeedViewModel.ListPost.Add(postViewModel);
            }
            List <String> listFriend = _friendService.GetAllFriend(userCur.Id);

            foreach (String friend in listFriend)
            {
                FriendViewModel friendViewModel = new FriendViewModel();
                ApplicationUser user            = _service.GetUserById(friend);
                FieldHelper.CopyNotNullValue(friendViewModel, user);
                NewsFeedViewModel.ListFriend.Add(friendViewModel);
            }
            return(PartialView("_NewsFeed", NewsFeedViewModel));
        }