예제 #1
0
        public async Task Create(SarEvent newEvent)
        {
            using (var db = dbFactory())
            {
                db.Events.Add(newEvent);
                await db.SaveChangesAsync();

                // TODO: push notification
            }
        }
        public async Task <TwilioResponse> DoMenu(TwilioRequest request)
        {
            var response = new TwilioResponse();

            if (request.Digits == "1")
            {
                var now      = TimeUtils.GetLocalDateTime(this.config);
                var newEvent = new SarEvent {
                    Name = "New Event at " + TimeUtils.GetMiltaryTimeVoiceText(now), Opened = now
                };
                await this.eventService.Create(newEvent);

                LoadActiveEvents();
                this.session.EventId = newEvent.Id;

                BeginMenu(response);
                response.SayVoice("Created " + newEvent.Name);

                await EndMenu(response);
            }
            else if (request.Digits == "2")
            {
                using (var db = dbFactory())
                {
                    BuildSetEventMenu(response, string.Empty, Url.Content("~/api/VoiceAdmin/Menu"));
                }
            }
            else if (request.Digits == "3")
            {
                response.SayVoice("Record a short description of this event at the tone");
                response.Record(new { maxLength = 120, action = GetAction("SetDescription", controller: "VoiceAdmin") });
                BeginMenu(response);
                await EndMenu(response);
            }
            else if (request.Digits == "9")
            {
                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("targetId", this.session.EventId.ToString());
                response.BeginGather(new { numDigits = 1, action = GetAction("ConfirmClose", args, controller: "VoiceAdmin"), timeout = 10 });
                response.SayVoice("Press 9 to confirm close of {0}. Press any other key to return to menu.", GetEventName());
                response.EndGather();
            }
            else if (request.Digits == "0")
            {
                response.Redirect(GetAction("Menu"));
            }
            else
            {
                response.SayVoice("I didn't understand.");
                BeginMenu(response);
                await EndMenu(response);
            }
            return(response);
        }
예제 #3
0
 protected override void DefaultSetup()
 {
     base.DefaultSetup();
     this.From = new SarEvent
     {
         Id     = 5,
         Name   = "Victim",
         Opened = new DateTime(2015, 1, 1),
     };
     this.To = new SarEvent
     {
         Id     = 6,
         Name   = "Winner",
         Opened = new DateTime(2015, 1, 2)
     };
     this.Events.Add(this.From);
     this.Events.Add(this.To);
 }
예제 #4
0
        public void AnswerKnownCallerOneMission()
        {
            var context  = VoiceTestContext.GetDefault <VoiceTestContext>();
            var theEvent = new SarEvent {
                Id = 3, Name = "Test Event", Opened = DateTime.Now.AddHours(-4), OutgoingUrl = "https://example.com/sample.mp3"
            };

            context.EventsServiceMock
            .Setup(f => f.ListActive()).Returns(() => Task.FromResult(new List <SarEvent> {
                theEvent
            }));

            var expectedText = string.Format(Speeches.CurrentEventTemplate, theEvent.Name)
                               + theEvent.OutgoingUrl
                               + GetKnownMemberSigninPrompt(context)
                               + string.Format(Speeches.PromptRecordMessageTemplate, 3)
                               + string.Format(Speeches.PromptChangeResponder, 8)
                               + string.Format(Speeches.PromptAdminMenu, 9);

            var response = AnswerCallCheckResult(context, expectedText);

            Assert.IsTrue(response.Descendants("Play").First().Value == theEvent.OutgoingUrl, "says outgoing message");
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="isNew"></param>
        /// <param name="dbFactory"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        internal static async Task <SubmitResult <EventEntry> > SaveEvent(EventEntry value, bool isNew, Func <IMissionLineDbContext> dbFactory, IConfigSource config)
        {
            var result = new SubmitResult <EventEntry>();

            if (string.IsNullOrWhiteSpace(value.Name))
            {
                result.Errors.Add(new SubmitError("name", "Required"));
            }
            DateTimeOffset localOpened = value.Opened.ToOrgTime(config);

            if (localOpened < minDate || localOpened > maxDate)
            {
                result.Errors.Add(new SubmitError("opened", "Date invalid or out of range"));
            }
            DateTimeOffset?localClosed = value.Closed == null ? (DateTimeOffset?)null : value.Closed.Value.ToOrgTime(config);

            if (localClosed.HasValue)
            {
                if (localClosed < minDate || localClosed > maxDate)
                {
                    result.Errors.Add(new SubmitError("closed", "Date invalid or out of range"));
                }
                else if (localClosed < localOpened)
                {
                    result.Errors.Add(new SubmitError("closed", "Must be after open time"));
                }
            }

            if (result.Errors.Count == 0)
            {
                using (var db = dbFactory())
                {
                    SarEvent evt;
                    if (isNew)
                    {
                        evt = new SarEvent
                        {
                            Name   = value.Name,
                            Opened = localOpened,
                            Closed = localClosed
                        };
                        db.Events.Add(evt);
                    }
                    else
                    {
                        evt = db.Events.Single(f => f.Id == value.Id);
                    }

                    if (value.Name != evt.Name)
                    {
                        evt.Name = value.Name;
                    }
                    if (localOpened != evt.Opened)
                    {
                        evt.Opened = localOpened;
                    }
                    if (localClosed != evt.Closed)
                    {
                        evt.Closed = localClosed;
                    }

                    await db.SaveChangesAsync();

                    result.Data = new[] { evt }.AsQueryable().Select(proj).Single();
                    config.GetPushHub <CallsHub>().updatedEvent(result.Data);
                }
            }
            return(result);
        }
예제 #6
0
 internal static EventEntry GetEventEntry(SarEvent evt)
 {
     return(compiledProj(evt));
 }