Example #1
0
        public async Task <IActionResult> GetNavbarAsync([FromServices] IUnitOfWorkFactory unitOfWorkFactory,
                                                         [FromServices] ICommandHandlerDispatcher commandHandlerDispatcher,
                                                         [FromServices] IQueryHandlerDispatcher queryHandlerDispatcher)
        {
            var unitOfWork = unitOfWorkFactory.Create();

            var cmd = new CreateNotificationCommand("xact", "notif-" + Guid.NewGuid().ToString(), 1, "subject1", "content1", "reference1", DateTime.UtcNow);

            commandHandlerDispatcher.Handle(cmd);

            var query = new GetUnreadNotificationReceiversByUserIdQuery("xact", "system-administrator", "", 1, 10, "", true);
            var dto   = queryHandlerDispatcher.Handle <GetUnreadNotificationReceiversByUserIdQuery, PaginatedNotificationReceiverDto>(query);


            //var items = await notificationService.GetUnreadNotificationsAsync(UserId);
            //var notifications = items.OrderByDescending(p => p.Notification.DateSent).Take(15).ToList();

            ////var items2 = await messageService.GetUnreadMessagesAsync(UserId);
            ////var msgHeaders = items2.Take(15).ToList();

            //var chats = await appDbContext
            //    .ChatReceiverMessages
            //    .Include(p => p.ChatMessage)
            //        .ThenInclude(p => p.Sender)
            //            .ThenInclude(p => p.User)
            //    //.Include(p => p.ChatReceiver)
            //    .Where(p => p.ChatReceiver.ReceiverId == UserId && p.IsRead == false)
            //    .Take(15)
            //    .ToListAsync();

            ////  trigger populate
            ////var chatReceivers = await appDbContext
            ////    .ChatReceivers
            ////    .Where(p => p.ReceiverId == UserId)
            ////    .ToListAsync();


            //var model = new NavbarInfo
            //{
            //    Username = User.Identity.Name,
            //    NotificationReceivers = notifications,
            //    MessageReceiverMessages = chats
            //};


            //return Ok(model);
            unitOfWork.Commit();

            return(Ok(dto));
        }
Example #2
0
        PaginatedNotificationReceiverDto IQueryHandler <GetUnreadNotificationReceiversByUserIdQuery, PaginatedNotificationReceiverDto> .Handle(GetUnreadNotificationReceiversByUserIdQuery query)
        {
            var today = DateTime.UtcNow;

            const string sql = @"
select  nr.NotificationReceiverId as 'Id', nr.NotificationId, nr.DateRead
        , nr.DateCreated, nr.DateUpdated, nr.DateEnabled, nr.DateDeleted
from    core_NotificationReceiver nr
where   nr.ReceiverId = @UserId
and     nr.DateRead > @Today
;
select  n.NotificationId as 'Id', n.NotificationType, n.Subject, n.Content, n.ReferenceId, n.DateSent
        , n.DateCreated, n.DateUpdated, n.DateEnabled, n.DateDeleted
from    core_Notification n
join    core_NotificationReceiver nr on (nr.NotificationId = n.NotificationId)
where   nr.ReceiverId = @UserId
and     nr.DateRead > @Today
;
";

            using (var multi = DbConnection.QueryMultiple(sql, new
            {
                query.UserId,
                Today = today
            }, DbTransaction))
            {
                var items    = multi.Read <NotificationReceiverDto>().AsList();
                var subItems = multi.Read <NotificationDto>().AsList();

                items.ForEach(p =>
                {
                    p.Notification = subItems.SingleOrDefault(q => q.NotificationId == p.NotificationId);
                });

                var count = items.Count;

                var paginated = new PaginatedNotificationReceiverDto(items, query.Page, query.PageSize, count);

                return(paginated);
            }
        }