Beispiel #1
0
        public IList <Notification> GetNotifications(NotificationQuery notificationQuery)
        {
            var notifications = NotificationStorage.GetData().Select(x => x.Value);

            notifications = notifications.Where(x => x.PersonRef == notificationQuery.PersonId && x.RoleRef == notificationQuery.RoleId);

            if (notificationQuery.Id.HasValue)
            {
                notifications = notifications.Where(x => x.Id == notificationQuery.Id);
            }
            if (notificationQuery.Shown.HasValue)
            {
                notifications = notifications.Where(x => x.Shown == notificationQuery.Shown);
            }

            if (notificationQuery.FromDate.HasValue)
            {
                notifications = notifications.Where(x => x.Created >= notificationQuery.FromDate.Value);
            }
            if (notificationQuery.ToDate.HasValue)
            {
                notifications = notifications.Where(x => x.Created <= notificationQuery.ToDate.Value);
            }

            if (notificationQuery.Type.HasValue)
            {
                notifications = notifications.Where(x => x.Type == notificationQuery.Type);
            }
            notifications = notifications.Skip(notificationQuery.Start).Take(notificationQuery.Count).OrderByDescending(x => x.Created);
            return(notifications.ToList());
        }
        private PaginatedList <NotificationDetails> GetNotifications(NotificationQuery query)
        {
            Trace.Assert(Context.SchoolLocalId.HasValue);
            Trace.Assert(Context.PersonId.HasValue);

            using (var uow = Read())
            {
                if (BaseSecurity.IsDistrictAdmin(Context))
                {
                    query.SchoolId = Context.SchoolLocalId.Value;
                }
                query.PersonId = Context.PersonId.Value;
                query.RoleId   = Context.RoleId;
                var notifications = new NotificationDataAccess(uow).GetPaginatedNotificationsDetails(query, !Context.MessagingDisabled);
                var classIds      = notifications.Where(x => x.AnnouncementRef.HasValue && x.Announcement is ClassAnnouncement)
                                    .Select(x => (x.Announcement as ClassAnnouncement).ClassRef)
                                    .ToList();
                IList <ClassAnnouncementType> classAnnouncementTypes = ServiceLocator.ClassAnnouncementTypeService.GetClassAnnouncementTypes(classIds);
                foreach (var notification in notifications)
                {
                    var classAnn = notification.Announcement as ClassAnnouncement;
                    if (classAnn != null && classAnn.ClassAnnouncementTypeRef.HasValue)
                    {
                        var classAnnType = classAnnouncementTypes.First(x => x.Id == classAnn.ClassAnnouncementTypeRef);
                        notification.ClassAnnouncementType = classAnnType;
                    }
                }
                return(notifications);
            }
        }
Beispiel #3
0
        public NotificationQueryTest()
        {
            var serviceScope = CreateNewScope();
            var scope        = serviceScope.CreateScope();

            _dbContext         = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
            _logger            = new FakeIWebLogger();
            _notificationQuery = new NotificationQuery(_dbContext, new FakeIWebLogger());
        }
        /// <summary>
        /// Gets the notifications.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns>NotificationResult.</returns>
        public NotificationResult GetNotifications(NotificationQuery query)
        {
            var result = new NotificationResult();

            var clauses   = new List <string>();
            var paramList = new List <object>();

            if (query.IsRead.HasValue)
            {
                clauses.Add("IsRead=?");
                paramList.Add(query.IsRead.Value);
            }

            clauses.Add("UserId=?");
            paramList.Add(query.UserId.ToGuidBlob());

            var whereClause = " where " + string.Join(" And ", clauses.ToArray(clauses.Count));

            using (WriteLock.Read())
            {
                using (var connection = CreateConnection(true))
                {
                    result.TotalRecordCount = connection.Query("select count(Id) from Notifications" + whereClause, paramList.ToArray(paramList.Count)).SelectScalarInt().First();

                    var commandText = string.Format("select Id,UserId,Date,Name,Description,Url,Level,IsRead,Category,RelatedId from Notifications{0} order by IsRead asc, Date desc", whereClause);

                    if (query.Limit.HasValue || query.StartIndex.HasValue)
                    {
                        var offset = query.StartIndex ?? 0;

                        if (query.Limit.HasValue || offset > 0)
                        {
                            commandText += " LIMIT " + (query.Limit ?? int.MaxValue).ToString(CultureInfo.InvariantCulture);
                        }

                        if (offset > 0)
                        {
                            commandText += " OFFSET " + offset.ToString(CultureInfo.InvariantCulture);
                        }
                    }

                    var resultList = new List <Notification>();

                    foreach (var row in connection.Query(commandText, paramList.ToArray(paramList.Count)))
                    {
                        resultList.Add(GetNotification(row));
                    }

                    result.Notifications = resultList.ToArray(resultList.Count);
                }
            }

            return(result);
        }
        private async Task GetNotificaitonsCount()
        {
            var query = new NotificationQuery
            {
                Limit      = 5,
                StartIndex = 0,
                UserId     = AuthenticationService.Current.LoggedInUser.Id
            };
            var summary = await _apiClient.GetNotificationsSummary(AuthenticationService.Current.LoggedInUser.Id);

            var notifications = await _apiClient.GetNotificationsAsync(query);
        }
        public async Task AddNotification_DbUpdateConcurrencyException()
        {
            IsCalledDbUpdateConcurrency = false;
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MovieListDatabase")
                          .Options;

            var fakeQuery = new NotificationQuery(new AppDbContextConcurrencyException(options), new FakeIWebLogger());
            await fakeQuery.AddNotification("");

            Assert.IsTrue(IsCalledDbUpdateConcurrency);
        }
Beispiel #7
0
        /// <summary>
        /// Gets the notifications.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns>NotificationResult.</returns>
        public NotificationResult GetNotifications(NotificationQuery query)
        {
            var result = new NotificationResult();

            using (var connection = CreateConnection(true).Result)
            {
                using (var cmd = connection.CreateCommand())
                {
                    var clauses = new List <string>();

                    if (query.IsRead.HasValue)
                    {
                        clauses.Add("IsRead=@IsRead");
                        cmd.Parameters.Add(cmd, "@IsRead", DbType.Boolean).Value = query.IsRead.Value;
                    }

                    clauses.Add("UserId=@UserId");
                    cmd.Parameters.Add(cmd, "@UserId", DbType.Guid).Value = new Guid(query.UserId);

                    var whereClause = " where " + string.Join(" And ", clauses.ToArray());

                    cmd.CommandText = string.Format("select count(Id) from Notifications{0};select Id,UserId,Date,Name,Description,Url,Level,IsRead,Category,RelatedId from Notifications{0} order by IsRead asc, Date desc", whereClause);

                    using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        if (reader.Read())
                        {
                            result.TotalRecordCount = reader.GetInt32(0);
                        }

                        if (reader.NextResult())
                        {
                            var notifications = GetNotifications(reader);

                            if (query.StartIndex.HasValue)
                            {
                                notifications = notifications.Skip(query.StartIndex.Value);
                            }

                            if (query.Limit.HasValue)
                            {
                                notifications = notifications.Take(query.Limit.Value);
                            }

                            result.Notifications = notifications.ToArray();
                        }
                    }

                    return(result);
                }
            }
        }
Beispiel #8
0
        public async Task <IActionResult> AcceptApplication(int id)
        {
            await Db.Connection.OpenAsync();

            var query  = new NotificationQuery(Db);
            var result = await query.FindOneAsync(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }
            result.MarkedRead = true;
            await result.UpdateAsync();

            return(new OkObjectResult(result));
        }
Beispiel #9
0
        public async Task <List <NotificationQueryModel> > HandleAsync(NotificationQuery query)
        {
            var notifications = await _context.Notification
                                .Where(t => t.CourseId == query.CourseId)
                                .Select(t => new NotificationQueryModel
            {
                Id          = t.Id,
                SubmittedAt = t.SubmittedAt,
                Title       = t.Title,
                Course      = t.Course.Name,
                SubmittedBy = $"{t.SubmittedBy.Name} {t.SubmittedBy.Surname}",
                Description = t.Description
            })
                                .ToListAsync();

            return(notifications);
        }
Beispiel #10
0
        public async Task <IActionResult> GetNotifications(int eventId)
        {
            List <NotificationDTO> resultOfDTOs = new List <NotificationDTO>();

            await Db.Connection.OpenAsync();

            var query  = new NotificationQuery(Db);
            var result = await query.GetAllAsync(eventId);

            if (!(result is null))
            {
                foreach (Notification notification in result)
                {
                    resultOfDTOs.Add(notification.ConvertToDTO());
                }
            }

            return(new OkObjectResult(resultOfDTOs));
        }
Beispiel #11
0
        public PaginatedList <NotificationDetails> GetPaginatedNotificationsDetails(NotificationQuery notificationQuery)
        {
            var notifications = GetNotifications(notificationQuery);
            var nfDetails     = new List <NotificationDetails>();

            foreach (var notification in notifications)
            {
                var notificationDetails = (NotificationDetails)notification;

                notificationDetails.Person = ServiceLocator.PersonService.GetPersonDetails(notificationDetails.PersonRef);

                //TODO: impl this later
                //if (notificationDetails.AnnouncementRef.HasValue)
                //    notificationDetails.Announcement = ServiceLocator.AnnouncementService.GetAnnouncementById(notificationDetails.AnnouncementRef.Value);



                //if (notificationDetails.PrivateMessageRef.HasValue)
                //    notificationDetails.PrivateMessage =
                //        ServiceLocator.PrivateMessageService.GetMessage(notificationDetails.PrivateMessageRef.Value);

                if (notificationDetails.QuestionPersonRef.HasValue)
                {
                    notificationDetails.QuestionPerson = ServiceLocator.PersonService.GetPersonDetails(notificationDetails.QuestionPersonRef.Value);
                }

                if (notificationDetails.MarkingPeriodRef.HasValue)
                {
                    notificationDetails.MarkingPeriod =
                        ServiceLocator.MarkingPeriodService.GetMarkingPeriodById(notificationDetails.MarkingPeriodRef.Value);
                }

                nfDetails.Add(notificationDetails);
            }
            return(new PaginatedList <NotificationDetails>(nfDetails, notificationQuery.Start / notificationQuery.Count,
                                                           notificationQuery.Count, NotificationStorage.GetData().Count));
        }
Beispiel #12
0
        private async Task GetNotifications()
        {
            if (!NavigationService.IsNetworkAvailable || _dataLoaded)
            {
                return;
            }

            SetProgressBar(AppResources.SysTrayGettingNotifications);

            try
            {
                var query = new NotificationQuery
                {
                    StartIndex = 0,
                    UserId     = AuthenticationService.Current.LoggedInUserId,
                    Limit      = 20
                };

                var notifications = await ApiClient.GetNotificationsAsync(query);

                Notifications = new ObservableCollection <Notification>(notifications.Notifications);

                await ApiClient.MarkNotificationsRead(AuthenticationService.Current.LoggedInUserId, Notifications.Select(x => x.Id), true);

                var summary = await ApiClient.GetNotificationsSummary(AuthenticationService.Current.LoggedInUserId);

                Messenger.Default.Send(new NotificationMessage(summary, Constants.Messages.NotificationCountMsg));

                _dataLoaded = true;
            }
            catch (HttpException ex)
            {
                Utils.HandleHttpException("GetNotifications()", ex, NavigationService, Log);
            }

            SetProgressBar();
        }