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); }
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); }); }