Beispiel #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());
        }
        public ModifyMessageResponse Handle(ModifyMessageRequest request)
        {
            var message = _messages.Get(request.MessageId);

            message.Content = request.NewMessageContent;
            _messages.Update(message);

            return(new ModifyMessageResponse());
        }
Beispiel #3
0
        public SubscribeResponse Handle(SubscribeRequest request)
        {
            var community = _communities.Get(request.CommunityId);

            community.Subscribers.Add(request.PhoneNumber);
            _communities.Update(community);

            return(new SubscribeResponse());
        }
Beispiel #4
0
        public UnscheduleMessageResponse Handle(UnscheduleMessageRequest request)
        {
            var message = _messages.Get(request.MessageId);

            _scheduler.Unschedule(message.JobId);

            message.DateTimeToSend = null;
            _messages.Update(message);

            return(new UnscheduleMessageResponse());
        }
Beispiel #5
0
        public UnsubscribeResponse Handle(UnsubscribeRequest request)
        {
            var community = _communities.Get(request.CommunityId);
            var success   = community.Subscribers.Remove(request.PhoneNumber);

            if (success)
            {
                _communities.Update(community);
            }

            return(new UnsubscribeResponse());
        }
Beispiel #6
0
        public SendMessageResponse Handle(SendMessageRequest request)
        {
            _messages.Create(request.Message);

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

            phoneNumbers.ForEach(phoneNumber =>
                                 _sms.SendMessageAsync(request.Message, phoneNumber)
                                 );
            return(new SendMessageResponse());
        }
Beispiel #7
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());
        }
        public GetMessageResponse Handle(GetMessageRequest request)
        {
            var message = _messages.Get(request.MessageId);

            return(new GetMessageResponse(message));
        }