예제 #1
0
        /// <summary>
        /// Get the event notifications in pagination format .
        /// then ,it will set the returned data (event notification) as read .
        /// </summary>
        /// <param name="repId"></param>
        /// <param name="pageNumber">for pagination</param>
        /// <param name="pageSize">for pagination</param>
        /// <returns></returns>
        public async Task <Response <IEnumerable <EventNotification> > > GetEventNotification(int repId, int pageNumber, int pageSize)
        {
            try
            {
                var dictionary = _repo.GetEventsNotifications(repId, pageNumber, pageSize)
                                 .ToDictionary(notification => new EventNotificationPrimaryKey(notification.DataId, notification.NotificationTypeId));
                //Reading Logic
                var r   = new ReadingHandler <EventNotificationPrimaryKey>();
                var obj = new List <IReadable <EventNotificationPrimaryKey> >(dictionary.Select(notification => new EventRead(notification.Value)));
                r.SetObj(obj);
                var readElements = r.ReadAll();//the Ids that were influenced in reading process.
                //end of reading logic
                await _unitWork.CommitAsync();

                /**
                 * after commiting ,the data is set as read ,but the client
                 * need to know the whether the received data is read or not.
                 * so we reset th data to the state it was in before commiting .
                 */
                foreach (var element in readElements)
                {
                    dictionary[new EventNotificationPrimaryKey(element.DataId, element.TypeId)].Read = false;
                }
                return(new Response <IEnumerable <EventNotification> >(dictionary.Values));
            }
            catch (Exception e)
            {
                return(new Response <IEnumerable <EventNotification> >($"ERROR :{e.Message}"));
            }
        }