Ejemplo n.º 1
0
        public async Task SendNextImportantAnnouncement(DeleteAnnouncementWS deletedAnnouncementData)
        {
            var nextAnnouncement = _context.Announcements.Where(x => (x.AnnouncementImportantIndicator == 1 &&
                                                                      x.AnnouncementShow == true))
                                   .OrderByDescending(x => (x.AnnouncementDateModified > x.AnnouncementDateCreated) ?
                                                      x.AnnouncementDateModified :
                                                      x.AnnouncementDateCreated)
                                   .Skip(deletedAnnouncementData.PageSize - 1)
                                   .FirstOrDefault();

            await Clients.Others.SendAsync("DeletedImportantAnnouncementIdReceived", nextAnnouncement, deletedAnnouncementData.DeletedAnnouncementId);
        }
Ejemplo n.º 2
0
        public async Task SendNextTheLatestAnnouncement(DeleteAnnouncementWS deletedAnnouncementData)
        {
            var nextAnnouncement = _context.Announcements.Where(x => x.AnnouncementShow == true)
                                   .OrderByDescending(x => (x.AnnouncementDateModified > x.AnnouncementDateCreated) ?
                                                      x.AnnouncementDateModified :
                                                      x.AnnouncementDateCreated)
                                   .Skip(deletedAnnouncementData.PageSize - 1)
                                   .FirstOrDefault();

            var nextAnnouncementDetails = new AnnouncementDetails
            {
                AnnouncementId           = nextAnnouncement.AnnouncementId,
                AnnouncementTitle        = nextAnnouncement.AnnouncementTitle,
                AnnouncementDescription  = nextAnnouncement.AnnouncementDescription,
                AnnouncementDateCreated  = nextAnnouncement.AnnouncementDateCreated,
                AnnouncementDateModified = nextAnnouncement.AnnouncementDateModified,
                AnnouncementExpiryDate   = nextAnnouncement.AnnouncementExpiryDate,
                ImportantIndicator       = nextAnnouncement.AnnouncementImportantIndicator,
                CategoryId = nextAnnouncement.CategoryId
            };
            var categ = _context.Categories.FirstOrDefault(x => x.CategoryId == nextAnnouncement.CategoryId);

            nextAnnouncementDetails.CategoryName = categ.CategoryName;
            nextAnnouncementDetails.PriorityId   = categ.PriorityId;
            var prior = _context.Priorities.FirstOrDefault(x => x.PriorityId == categ.PriorityId);

            nextAnnouncementDetails.PriorityValue = prior.PriorityValue;
            nextAnnouncementDetails.UserCreatedId = nextAnnouncement.UserCreatedId;
            var userCreated = _userManager.Users.FirstOrDefault(user => user.Id == nextAnnouncement.UserCreatedId);

            nextAnnouncementDetails.UserCreatedFirstName = userCreated.FirstName;
            nextAnnouncementDetails.UserCreatedLastName  = userCreated.LastName;
            if (nextAnnouncement.UserModifiedId != null)
            {
                nextAnnouncementDetails.UserModifiedId = nextAnnouncement.UserModifiedId;
                var userModified = _userManager.Users.FirstOrDefault(user => user.Id == nextAnnouncement.UserModifiedId);
                nextAnnouncementDetails.UserModifiedFirstName = userModified.FirstName;
                nextAnnouncementDetails.UserModifiedLastName  = userModified.LastName;
            }
            var files = _context.Files.Where(x => x.AnnouncementId == nextAnnouncement.AnnouncementId)
                        .ToList();

            files.ForEach(file =>
            {
                nextAnnouncementDetails.Files.Add(file);
            });

            await Clients.Others.SendAsync("DeletedTheLatestAnnouncementIdReceived", nextAnnouncementDetails, deletedAnnouncementData.DeletedAnnouncementId);
        }