Initial commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using SIG.Web.AppCode.Notifications.Models;
|
||||
|
||||
namespace SIG.Web.AppCode.Notifications.Contracts
|
||||
{
|
||||
public interface INotificationCenter
|
||||
{
|
||||
void Queue(NotificationMessage message);
|
||||
void MarkAsShown(int notificationId, int userId);
|
||||
IReadOnlyList<NotificationMessage> GetBellMessages(int userId);
|
||||
int CountPending(int userId);
|
||||
}
|
||||
}
|
||||
12
SIG.Web/AppCode/Notifications/Hubs/NotificationHub.cs
Normal file
12
SIG.Web/AppCode/Notifications/Hubs/NotificationHub.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNet.SignalR;
|
||||
|
||||
namespace SIG.Web.AppCode.Notifications.Hubs
|
||||
{
|
||||
public class NotificationHub : Hub
|
||||
{
|
||||
public void Ping()
|
||||
{
|
||||
Clients.Caller.pong("SignalR is working.");
|
||||
}
|
||||
}
|
||||
}
|
||||
22
SIG.Web/AppCode/Notifications/Models/NotificationMessage.cs
Normal file
22
SIG.Web/AppCode/Notifications/Models/NotificationMessage.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace SIG.Web.AppCode.Notifications.Models
|
||||
{
|
||||
[Serializable]
|
||||
public sealed class NotificationMessage
|
||||
{
|
||||
public int CveNotificacion { get; set; }
|
||||
public int CveUsuario { get; set; }
|
||||
public string TipoNotificacion { get; set; }
|
||||
public string EstadoNotificacion { get; set; }
|
||||
public string Titulo { get; set; }
|
||||
public string Mensaje { get; set; }
|
||||
public string Url { get; set; }
|
||||
public bool Leida { get; set; }
|
||||
public bool MostradaEnCampana { get; set; }
|
||||
public DateTime? FechaEnvio { get; set; }
|
||||
public DateTime? FechaLectura { get; set; }
|
||||
public DateTime FechaCreacion { get; set; }
|
||||
public DateTime? FechaActualizacion { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SIG.Web.AppCode.Notifications.Contracts;
|
||||
using SIG.Web.AppCode.Notifications.Models;
|
||||
|
||||
namespace SIG.Web.AppCode.Notifications.Services
|
||||
{
|
||||
public sealed class DummyNotificationCenter : INotificationCenter
|
||||
{
|
||||
private static readonly List<NotificationMessage> Items = new List<NotificationMessage>();
|
||||
|
||||
public void Queue(NotificationMessage message)
|
||||
{
|
||||
if (message == null) return;
|
||||
message.CveNotificacion = Items.Count + 1;
|
||||
message.FechaCreacion = System.DateTime.Now;
|
||||
message.EstadoNotificacion = "Pendiente";
|
||||
Items.Add(message);
|
||||
}
|
||||
|
||||
public void MarkAsShown(int notificationId, int userId)
|
||||
{
|
||||
var item = Items.FirstOrDefault(x => x.CveNotificacion == notificationId && x.CveUsuario == userId);
|
||||
if (item == null) return;
|
||||
item.MostradaEnCampana = true;
|
||||
}
|
||||
|
||||
public IReadOnlyList<NotificationMessage> GetBellMessages(int userId)
|
||||
{
|
||||
return Items.Where(x => x.CveUsuario == userId && !x.Leida).ToList();
|
||||
}
|
||||
|
||||
public int CountPending(int userId)
|
||||
{
|
||||
return GetBellMessages(userId).Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user