Esempio n. 1
0
        private NotificationWrapper GenerateUserNotificationHtml(List <Notification <string> > allNotifications)
        {
            if (allNotifications.Count == 0)
            {
                return new NotificationWrapper()
                       {
                           Count = 0
                       }
            }
            ;

            var razor    = new RazorTemplate();
            var sbuilder = new StringBuilder();

            //Parallel.ForEach(allNotifications, (notification) =>
            foreach (var notification in allNotifications)
            {
                if (notification.Type == Model.NotificationTypeEnum.message)
                {
                    MessageNotificationModel model = TypeSerializer.DeserializeFromString
                                                     <MessageNotificationModel>(notification.NotificationObject);

                    sbuilder.Append(
                        razor.ParseRazorTemplate <MessageNotificationModel>
                            ("~/Website/Views/NotificationPartials/Message.cshtml", model));
                }
                else if (notification.Type == Model.NotificationTypeEnum.newtopic)
                {
                    TopicNotificationModel model = TypeSerializer.DeserializeFromString
                                                   <TopicNotificationModel>(notification.NotificationObject);

                    sbuilder.Append(
                        razor.ParseRazorTemplate <TopicNotificationModel>
                            ("~/Website/Views/NotificationPartials/NewTopic.cshtml", model));
                }
                else if (notification.Type == Model.NotificationTypeEnum.moderatorinvite)
                {
                    ModeratorNotificationModel model = TypeSerializer.DeserializeFromString
                                                       <ModeratorNotificationModel>(notification.NotificationObject);

                    sbuilder.Append(
                        razor.ParseRazorTemplate <ModeratorNotificationModel>
                            ("~/Website/Views/NotificationPartials/Accept.cshtml", model));
                }
            }//);

            return(new NotificationWrapper()
            {
                Count = allNotifications.Count,
                Html = sbuilder.ToString(),
                LastNotificationGuid = allNotifications.Last().Id
            });
        }
Esempio n. 2
0
        public MessageHtmlWrapper MessagesHtml(string viewBy = null, int skip = 0)
        {
            List <MessageBag> message = new List <MessageBag>();

            if (viewBy == "messageSend")
            {
                message = SentMessages(skip);
            }
            if (viewBy == "messageReceived")
            {
                message = ReceivedMessages(skip);
            }


            var rz       = new RazorTemplate();
            var sbuilder = new StringBuilder();

            foreach (var msg in message)
            {
                sbuilder.Append(rz.ParseRazorTemplate <MessageBag>
                                    ("~/Website/Views/MessagePartials/MessagePartial.cshtml", msg));
            }

            return(new MessageHtmlWrapper {
                Html = sbuilder.ToString(), Count = message.Count
            });
        }
Esempio n. 3
0
        public void CreateModeratorInvite(Channel channel, User inviter, User invited)
        {
            var now = DateTime.UtcNow;
            var moderatorNotification = new ModeratorNotificationModel
            {
                SenderName      = inviter.FirstName,
                SenderAvatarUrl = inviter.AvatarUrl,
                ChannelName     = channel.Name,
                ChannelId       = channel.Id,
                Date            = now.ToShortDateString(),
                Time            = now.ToShortTimeString(),
                Timestamp       = now.ToFileTimeUtc(),
                Guid            = Guid.NewGuid() //gera novo GUID
            };


            var    rz        = new RazorTemplate();
            string htmlNotif = rz.ParseRazorTemplate <ModeratorNotificationModel>
                                   ("~/Website/Views/NotificationPartials/Accept.cshtml", moderatorNotification);

            var wrapper = new ModeratorNotificationWrapper()
            {
                ChannelId = moderatorNotification.ChannelId,
                Html      = htmlNotif
            };

            NimbusHubContext.Clients.Group(NimbusHub.GetMessageGroupName(invited.Id)).newModeratorNotification(wrapper);

            StoreNotification(moderatorNotification, invited.Id);
        }
Esempio n. 4
0
        public MessageHtmlWrapper MessageHtml(int id)
        {
            MessageBag bag = new MessageBag();

            using (var db = DatabaseFactory.OpenDbConnection())
            {
                var receiverMsg = db.Where <ReceiverMessage>(r => r.UserId == NimbusUser.UserId &&
                                                             r.MessageId == id &&
                                                             r.Status == Model.Enums.MessageType.received).FirstOrDefault();
                if (receiverMsg != null)
                {
                    var msg = db.Where <Message>(m => m.Id == id).FirstOrDefault();
                    if (msg == null)
                    {
                        return new MessageHtmlWrapper()
                               {
                                   Count = 0
                               }
                    }
                    ;
                    //                                    .Select(r =>
                    //                                        db.Where<Message>(m => m.Id == r.MessageId && m.Visible == true).FirstOrDefault())
                    //                                    .Where(msg => msg != null);

                    User user = db.SelectParam <User>(u => u.Id == msg.SenderId).FirstOrDefault();
                    bag.ChannelId      = msg.ChannelId;
                    bag.Date           = msg.Date;
                    bag.Id             = msg.Id;
                    bag.SenderId       = msg.SenderId;
                    bag.Text           = msg.Text.Length > 100 ? msg.Text.Substring(0, 100) : msg.Text;
                    bag.Title          = msg.Title;
                    bag.Visible        = msg.Visible;
                    bag.UserName       = user.FirstName + " " + user.LastName;
                    bag.AvatarUrl      = user.AvatarUrl;
                    bag.UserReadStatus = receiverMsg.UserReadStatus;
                }
                else
                {
                    return(new MessageHtmlWrapper()
                    {
                        Count = 0
                    });
                }
            }

            var    rz          = new RazorTemplate();
            string htmlMessage = rz.ParseRazorTemplate <MessageBag>
                                     ("~/Website/Views/MessagePartials/MessagePartial.cshtml", bag);

            return(new MessageHtmlWrapper {
                Count = 1, Html = htmlMessage
            });
        }
Esempio n. 5
0
        public MessageHtmlWrapper MessageExpandHtml(int id)
        {
            MessageBag message = ExpandMsg(id);

            var rz       = new RazorTemplate();
            var sbuilder = new StringBuilder();

            sbuilder.Append(rz.ParseRazorTemplate <MessageBag>
                                ("~/Website/Views/MessagePartials/MessageExpandPartial.cshtml", message));

            return(new MessageHtmlWrapper {
                Html = sbuilder.ToString()
            });
        }
Esempio n. 6
0
        public ChnByCategoryHtmlWrapper AbstChannelHtml(int id, string nameCat)
        {
            var    rz   = new RazorTemplate();
            string html = "";
            List <Nimbus.Model.ORM.Channel> channel = new List <Nimbus.Model.ORM.Channel>();

            channel = ChannelByCategory(id, nameCat);

            foreach (var item in channel)
            {
                html += rz.ParseRazorTemplate <Nimbus.Model.ORM.Channel>
                            ("~/Website/Views/ChannelPartials/ChannelPartial.cshtml", item);
            }
            return(new ChnByCategoryHtmlWrapper {
                Html = html, Count = channel.Count
            });
        }
Esempio n. 7
0
        public CommentHtmlWrapper CommentsHtml(int id = 0, int skip = 0, string type = null)
        {
            List <CommentBag> comments = new List <CommentBag>();
            string            partial  = "~/Website/Views/CommentPartials/PartialComment.cshtml";

            if (type == "channel")
            {
                comments = ShowChannelComment(id, skip);
            }
            else if (type == "topic")
            {
                comments = ShowTopicComment(id, skip);
            }
            else if (type == "notificationtopic")
            {
                comments = ShowTopicComment(id, skip);
                partial  = "~/Website/Views/CommentPartials/PartialTopicComment.cshtml";
            }
            else if (type == "child")
            {
                comments = ShowMoreCommentChild(id, skip);
            }
            else if (type == "oneparent")
            {
                comments = ShowParentComment(id, 0);
                //comments.FirstOrDefault().IsRazorEngine = true;
                partial = "~/Website/Views/CommentPartials/PartialTopicComment.cshtml";
            }
            else if (type == "onechild")
            {
                comments = ShowChildComment(id);
            }

            var    rz   = new RazorTemplate();
            string html = "";

            foreach (var cmt in comments)
            {
                html += rz.ParseRazorTemplate <CommentBag>(partial, cmt);
            }

            return(new CommentHtmlWrapper {
                Html = html, Count = comments.Count
            });
        }
Esempio n. 8
0
        /// <summary>
        /// Envia notificações de tópico novo para os usuários seguidores do canal.
        /// Utiliza mesmo canal de notificações de mensagem.
        /// </summary>
        /// <param name="topic"></param>
        public void NewTopic(Topic topic)
        {
            using (var db = DatabaseFactory.OpenDbConnection())
            {
                var channelFollowers = db.Where <ChannelUser>(chu => chu.ChannelId == topic.ChannelId &&
                                                              chu.Follow == true &&
                                                              chu.Accepted == true &&
                                                              chu.Visible == true);

                var channel = db.Where <Channel>(ch => ch.Id == topic.ChannelId).FirstOrDefault();

                var now = DateTime.UtcNow;

                var nt = new TopicNotificationModel()
                {
                    TopicId          = topic.Id,
                    TopicName        = topic.Title,
                    ChannelId        = topic.ChannelId,
                    ChannelName      = channel.Name,
                    TopicImage       = topic.ImgUrl,
                    NotificationType = Model.NotificationTypeEnum.newtopic,

                    Date      = now.ToShortDateString(),
                    Time      = now.ToShortTimeString(),
                    Timestamp = now.ToFileTimeUtc(),
                };

                var    rz        = new RazorTemplate();
                string htmlNotif = rz.ParseRazorTemplate <TopicNotificationModel>
                                       ("~/Website/Views/NotificationPartials/NewTopic.cshtml", nt);

                foreach (var follower in channelFollowers)
                {
                    var ntClone = new TopicNotificationModel(nt);
                    NimbusHubContext.Clients.Group(NimbusHub.GetFollowerGroupName(follower.UserId)).newMessageNotification(htmlNotif);

                    StoreNotification(ntClone, follower.UserId);
                }

                var ntChClone = new TopicNotificationModel(nt);
                StoreNotificationChannel(ntChClone);
            }
        }
Esempio n. 9
0
        public void NewMessage(Model.ORM.Message msg)
        {
            var        sender    = msg.Receivers.Where(r => r.UserId == msg.SenderId).FirstOrDefault();
            List <int> receivers = msg.Receivers.Where(r => r.UserId != msg.SenderId).Select(s => s.UserId).ToList();

            if (receivers.Count() == 0)
            {
                receivers = new List <int>();
                receivers.Add(sender.UserId);
            }


            var messageNotification = new MessageNotificationModel
            {
                SenderName      = sender.Name,
                SenderAvatarUrl = sender.AvatarUrl,
                Subject         = msg.Title,
                MessageId       = msg.Id,
                Date            = msg.Date.ToShortDateString(),
                Time            = msg.Date.ToShortTimeString(),
                Timestamp       = msg.Date.ToFileTimeUtc()
            };

            Parallel.ForEach(receivers, (receiver) =>
            {
                var msgCopy = new MessageNotificationModel(messageNotification);

                var rz           = new RazorTemplate();
                string htmlNotif = rz.ParseRazorTemplate <MessageNotificationModel>
                                       ("~/Website/Views/NotificationPartials/Message.cshtml", msgCopy);

                var wrapper = new MessageNotificationWrapper()
                {
                    MessageId = msgCopy.MessageId,
                    Html      = htmlNotif
                };

                NimbusHubContext.Clients.Group(NimbusHub.GetMessageGroupName(receiver)).newMessageNotification(wrapper);

                StoreNotification(msgCopy, receiver);
            });
        }