예제 #1
0
        public ScheduleMessageResponse Handle(ScheduleMessageRequest request)
        {
            var message = new Message()
            {
                Content        = request.MessageContent,
                DateTimeToSend = request.DateTimeToSend,
                CommunityId    = request.CommunityId
            };

            message = _messages.Create(message);

            var phoneNumbers = _communities
                               .Get(request.CommunityId)
                               .Subscribers
                               .ToList();

            var jobId = _scheduler.Schedule(
                () => phoneNumbers.ForEach(
                    phoneNumber => _sms.SendMessageAsync(
                        message,
                        phoneNumber)),
                request.DateTimeToSend);

            message.JobId = jobId;
            _messages.Update(message);

            return(new ScheduleMessageResponse());
        }
예제 #2
0
        public RescheduleMessageResponse Handle(RescheduleMessageRequest request)
        {
            var message = _messages.Get(request.MessageId);

            message.DateTimeToSend = request.NewDateTimeToSend;
            _messages.Update(message);

            var phoneNumbers = _communities
                               .Get(message.CommunityId)
                               .Subscribers
                               .ToList();

            _scheduler.Schedule(
                () => phoneNumbers.ForEach(
                    phoneNumber => _sms.SendMessageAsync(
                        message,
                        phoneNumber)),
                request.NewDateTimeToSend);

            return(new RescheduleMessageResponse());
        }