Esempio n. 1
0
        public static string GetNotificationString(this HtmlHelper html, NotificationSettingEnum type)
        {
            string result = "";

            switch (type)
            {
            case NotificationSettingEnum.UserAnswerQuestion:
                result = "đã trả lời câu hỏi của bạn:";
                break;

            case NotificationSettingEnum.UserHintQuestion:
                result = "đã gợi ý cho câu hỏi của bạn:";
                break;

            case NotificationSettingEnum.UserCommentMainPost:
                result = "đã bình luận trong:";
                break;

            case NotificationSettingEnum.Invited:
                result = "đã mời bạn vào:";
                break;

            case NotificationSettingEnum.UserComment:
                result = "đã bình luận trả lời của bạn trong:";
                break;

            case NotificationSettingEnum.AcceptedAnswer:
                result = "đã chấp nhận trả lời của bạn trong:";
                break;

            case NotificationSettingEnum.UserLikeComment:
                result = "đã thích bình luận của bạn trong:";
                break;

            case NotificationSettingEnum.ReceivedPrivilege:
                result = "bạn đã nhận được danh hiệu:";
                break;

            case NotificationSettingEnum.Banned:
                result = "đã khóa tài khoản của bạn:";
                break;

            case NotificationSettingEnum.BlockedMainPost:
                result = "đã khóa bài của bạn:";
                break;

            case NotificationSettingEnum.BlockedComment:
                result = "đã khóa khóa bình luận của bạn trong bài:";
                break;

            case NotificationSettingEnum.BlockedAnswer:
                result = "đã khóa câu trả lời của bạn trong câu hỏi:";
                break;

            case NotificationSettingEnum.VotedQuestion:
                result = "đã bình chọn câu hỏi của bạn:";
                break;

            case NotificationSettingEnum.VotedAnswer:
                result = "đã bình chọn câu trả lời của bạn tại:";
                break;

            case NotificationSettingEnum.SettedRole:
                result = "đã phân quyền cho bạn:";
                break;

            default:
                result = "bạn có thông báo mới từ hệ thống:";
                break;
            }
            return(result);
        }
Esempio n. 2
0
        public bool Like(int id)
        {
            //User user = cService.GetUser(User.Identity.GetUserId<int>());
            Constant.Enum.LikeResult result = cService.Like(id, _currentUserId);
            Post post = cService.GetPost(id);

            if (post.UserId != _currentUserId &&
                result != Constant.Enum.LikeResult.Fail &&
                result != Constant.Enum.LikeResult.Unlike)
            {
                //new Thread(() =>
                //{
                NotificationSettingEnum notiType = default(NotificationSettingEnum);
                int    userId       = 0;
                int    mainPostId   = 0;
                string content      = default(string);
                string mainPostType = default(string);
                string url          = default(string);
                switch (result)
                {
                case Constant.Enum.LikeResult.Fail:
                    break;

                case Constant.Enum.LikeResult.Article:
                    notiType   = NotificationSettingEnum.UserLikeMainPost;
                    userId     = post.UserId;
                    content    = ((Article)post).Title;
                    mainPostId = id;
                    url        = Url.Action("Detail", "Blog", new { id = mainPostId });
                    break;

                case Constant.Enum.LikeResult.Discussion:
                    notiType   = NotificationSettingEnum.UserLikeMainPost;
                    userId     = post.UserId;
                    content    = ((Discussion)post).Title;
                    mainPostId = id;
                    url        = Url.Action("Detail", "Discussion", new { id = mainPostId });
                    break;

                case Constant.Enum.LikeResult.Comment:
                    notiType     = NotificationSettingEnum.UserLikeComment;
                    userId       = post.UserId;
                    content      = ((MainPost)((Comment)post).Post).Title;
                    mainPostId   = ((MainPost)((Comment)post).Post).Id;
                    mainPostType = EntityHelper.GetMainPostTypeNameOfNormalPost(post);
                    url          = Url.Action("Detail", mainPostType, new { id = mainPostId });
                    break;

                case Constant.Enum.LikeResult.Reply:
                    notiType     = NotificationSettingEnum.UserLikeComment;
                    userId       = post.UserId;
                    content      = ((MainPost)((Comment)((Comment)post).Post).Post).Title;
                    mainPostId   = ((MainPost)((Comment)((Comment)post).Post).Post).Id;
                    mainPostType = EntityHelper.GetMainPostTypeNameOfNormalPost(post);
                    url          = Url.Action("Detail", mainPostType, new { id = mainPostId });
                    break;

                case Constant.Enum.LikeResult.Unlike:
                    break;

                default:
                    break;
                }
                //if (vote.Post.GetType().BaseType == typeof(Question))
                //{
                //    question = qService.GetQuestion(vote.PostId);
                //    notiType = NotificationSettingEnum.VotedQuestion;
                //    userId = question.UserId;
                //}
                //else
                //{
                //    question = qService.GetQuestion(((Answer)vote.Post).QuestionId);
                //    notiType = NotificationSettingEnum.VotedAnswer;
                //    userId = vote.Post.UserId;
                //}

                Notification notification = new Notification();
                notification.AuthorId    = _currentUserId;
                notification.CreatedDate = DateTime.Now;
                notification.Content     = content;
                notification.Seen        = false;
                notification.Type        = notiType;
                notification.UserId      = userId;
                notification.Link        = url;
                cService.AddNotification(notification);

                using (RealTimeService rService = new RealTimeService(new CPMathHubModelContainer(), notification.UserId))
                {
                    IEnumerable <string> connectionIds = RealTimeHub.Connections.GetConnections(notification.UserId);
                    foreach (string conId in connectionIds)
                    {
                        _hub.Clients.Client(conId).notifyNewActivity(rService.CountNewActivityNotification());
                    }
                }
                //}
                //).Start();
            }
            return(result != Constant.Enum.LikeResult.Fail);
        }