/// <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;
                }
            }
        }
        private async Task GetNotifications()
        {
            if (!_navigationService.IsNetworkAvailable || _dataLoaded)
            {
                return;
            }

            SetProgressBar("Getting notifications...");

            try
            {
                var query = new NotificationQuery
                {
                    StartIndex = 0,
                    UserId = AuthenticationService.Current.LoggedInUser.Id
                };

                var notifications = await _apiClient.GetNotificationsAsync(query);
                Notifications = new ObservableCollection<Notification>(notifications.Notifications);

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

                var summary = await _apiClient.GetNotificationsSummary(AuthenticationService.Current.LoggedInUser.Id);

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

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

            SetProgressBar();
        }
Example #3
0
 private async Task GetNotificaitonsCount()
 {
     var query = new NotificationQuery
     {
         Limit = 5,
         StartIndex = 0,
         UserId = AuthenticationService.Current.LoggedInUserId
     };
     var summary = await ApiClient.GetNotificationsSummary(AuthenticationService.Current.LoggedInUserId);
     var notifications = await ApiClient.GetNotificationsAsync(query);
 }