Beispiel #1
0
        /// <summary>
        /// Save the entry - check if it exists, if not create it
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private Task <NotificationEntry> SaveNotification(ConsumeContext <NotificationEntryDTO> context)
        {
            var exists = Repo.GetAllByExternalID(context.Message.ExternalID).Where(
                r => r.NotificationType == context.Message.NotificationType &&
                r.SubscriptionID == context.Message.SubscriptionID &&
                r.NotificationSubtype == context.Message.NotificationSubtype).FirstOrDefault();

            var from = context.Message;

            if (exists == null)
            {
                Logger.LogInformation("Adding Notification entry: {0} - {1}", context.Message.ID, context.Message.Code);
                NotificationEntry rec = new()
                {
                    Code           = from.Code,
                    ExternalID     = from.ExternalID,
                    Description    = from.Description,
                    Duedate        = from.Duedate,
                    Enddate        = from.Enddate,
                    ExpectedAction = from.ExpectedAction,

                    NotificationType    = from.NotificationType,
                    NotificationSubtype = from.NotificationSubtype,
                    Salutation          = from.Salutation,
                    Startdate           = from.Startdate,
                    SubscriptionID      = from.SubscriptionID,
                    SubscriptionGroup   = from.SubscriptionGroup,

                    URL = from.URL
                };

                return(Repo.Post(rec));
            }
            else
            {
                Logger.LogInformation("Updating Notification entry: {0} - {1}", context.Message.ID, context.Message.Code);
                exists.Code              = from.Code;
                exists.ExternalID        = from.ExternalID;
                exists.Description       = from.Description;
                exists.Duedate           = from.Duedate;
                exists.Enddate           = from.Enddate;
                exists.ExpectedAction    = from.ExpectedAction;
                exists.Salutation        = from.Salutation;
                exists.Startdate         = from.Startdate;
                exists.SubscriptionGroup = from.SubscriptionGroup;
                exists.URL = from.URL;

                return(Repo.Put(exists));
            }
        }
        public Task Consume(ConsumeContext <NotificationEntryDTO> context)
        {
            Logger.LogDebug("RemoveNotificationItem entry: {0} - {1}", context.Message.ID, context.Message.Code);

            // get the entry - check if it exists, if not don't try to delete it
            var exists = Repo.GetAllByExternalID(context.Message.ExternalID).Where(
                r => r.NotificationType == context.Message.NotificationType &&
                r.SubscriptionID == context.Message.SubscriptionID &&
                r.URL == context.Message.URL).FirstOrDefault();

            if (exists != null)
            {
                Logger.LogInformation("Removing Notification entry: {0} - {1}", context.Message.ID, context.Message.Code);
                return(Repo.Delete(exists));
            }
            return(new Task <bool>(() => true));
        }