コード例 #1
0
        public async Task MissingHours(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            if (await VerifyExactOnlineAuthorization(context, activity, ""))
            {
                DateTime startDate;
                DateTime endDate;
                string   weekString;

                var message = await activity;
                if (message.Text.ToLower().Contains("last week"))
                {
                    weekString = "last week";
                    DateTimeUtils.GetThisWeek(DateTime.Now.AddDays(-7), out startDate, out endDate);
                }
                else
                {
                    weekString = "this week";
                    DateTimeUtils.GetThisWeek(DateTime.Now, out startDate, out endDate);
                }

                await context.PostAsync($"Just a minute, going to check your hours for {weekString}...");

                ExactOnlineConnector      eolConnector = ExactOnlineHelper.GetConnector();
                TimeRegistrationConnector connector    = new TimeRegistrationConnector();

                double bookedHours = await connector.GetBookedHours(eolConnector.EmployeeId, startDate, endDate, eolConnector);

                await context.PostAsync($"For {weekString} I found {bookedHours} hours booked.");

                context.Wait(MessageReceived);
            }
        }
コード例 #2
0
        private async Task <TimeRegistrationModel> TimeRegistrationCompleted(IBotContext context, TimeRegistrationModel model)
        {
            var message = "Booking your hours in Exact, just a sec...";
            await context.PostAsync(message);

            ExactOnlineConnector connector = ExactOnlineHelper.GetConnector();

            TimeRegistrationConnector timeConnector = new TimeRegistrationConnector();

            Guid projectId  = String.IsNullOrEmpty(model.Project) || model.Project == "none" ? Guid.Empty : new Guid(model.Project);
            Guid customerId = String.IsNullOrEmpty(model.Customer) ? Guid.Empty : new Guid(model.Customer);
            Guid hourTypeId = String.IsNullOrEmpty(model.HourType) ? Guid.Empty : new Guid(model.HourType);

            try
            {
                // the user will have booked time for either this week or for a specific date
                if (!model.ThisWeek)
                {
                    timeConnector.BookHours(connector.EmployeeId, customerId, hourTypeId, projectId, model.Date, model.Amount, connector);
                }
                else
                {
                    // if the hours were booked for the entire will, there will be 5 numbers in the string that need to be split
                    // out and entered for each day of the week individually
                    int      dayOfWeek  = DateTimeUtils.GetISODayOfWeek(DateTime.Now);
                    DateTime currentDay = DateTime.Now.AddDays((dayOfWeek - 1) * -1);

                    string[] hours = model.AmountPerDay.Trim().Split(' ');

                    for (int i = 0; i < 5; i++)
                    {
                        double amount = Double.Parse(hours[i]);

                        if (amount > 0)
                        {
                            timeConnector.BookHours(connector.EmployeeId, customerId, hourTypeId, projectId, currentDay, amount, connector);
                        }

                        currentDay = currentDay.AddDays(1);
                    }
                }
            }
            catch (RequestFailedException ex)
            {
                await context.PostAsync($"Hmm, that didn't work. The request failed, it returned the following:");

                await context.PostAsync($"\"{ ex.Message}\"");

                await context.PostAsync($"Sorry about that. Please try again or notify my maker.");

                return(null);
            }

            await context.PostAsync("All set! Anything else I can do for you?");

            return(model);
        }
コード例 #3
0
        public IForm <TimeRegistrationModel> BuildForm()
        {
            ExactOnlineConnector connector = ExactOnlineHelper.GetConnector();

            var byDate       = new ActiveDelegate <TimeRegistrationModel>((state) => { return(state.ThisWeek == false); });
            var askPerDay    = new ActiveDelegate <TimeRegistrationModel>((state) => { return(state.ThisWeek == true); });
            var verifyPerDay = new ValidateAsyncDelegate <TimeRegistrationModel>(ValidateHoursPerDay);

            return(new FormBuilder <TimeRegistrationModel>()
                   .Field(nameof(TimeRegistrationModel.ThisWeek))
                   .Field(BuildCustomerField(connector))
                   .Field(BuildProjectField(connector))
                   .Field(BuildHourTypeField(connector))
                   .Field(nameof(TimeRegistrationModel.Date), byDate)
                   .Field(nameof(TimeRegistrationModel.Amount), byDate)
                   .Field(nameof(TimeRegistrationModel.AmountPerDay), askPerDay, ValidateHoursPerDay)
                   .OnCompletion(TimeRegistrationCompleted)
                   .Build());
        }
コード例 #4
0
        public async Task SubmitHours(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            if (await VerifyExactOnlineAuthorization(context, activity, ""))
            {
                await context.PostAsync($"Let me check whether you're all set...");

                ExactOnlineConnector      eolConnector = ExactOnlineHelper.GetConnector();
                TimeRegistrationConnector connector    = new TimeRegistrationConnector();

                DateTime startDate, endDate;
                DateTimeUtils.GetThisWeek(DateTime.Now, out startDate, out endDate);

                double bookedHours = await connector.GetBookedHours(eolConnector.EmployeeId, startDate, endDate, eolConnector);

                ConfirmDialog.Text = $"You've registered a total number of {0} hours for this week. Do you want me to submit those?";
                var confirmationDialog = new FormDialog <ConfirmModel>(new ConfirmModel(), ConfirmDialog.BuildForm, FormOptions.PromptInStart);
                context.Call(confirmationDialog, this.ResumeAfterSubmitHoursDialog);
            }
        }
コード例 #5
0
        private async Task ResumeAfterSubmitHoursDialog(IDialogContext context, IAwaitable <ConfirmModel> result)
        {
            ConfirmModel message = await result;

            if (message.Confirmation)
            {
                DateTime startDate, endDate;
                DateTimeUtils.GetThisWeek(DateTime.Now, out startDate, out endDate);

                ExactOnlineConnector      eolConnector  = ExactOnlineHelper.GetConnector();
                TimeRegistrationConnector timeConnector = new TimeRegistrationConnector();
                timeConnector.SubmitHours(eolConnector.EmployeeId, startDate, endDate, eolConnector);

                await context.PostAsync($"Thanks, I've closed your timesheet for this week. Have a nice weekend!");
            }
            else
            {
                await context.PostAsync($"Ok. Just give me a nudge when you're ready.");
            }

            context.Wait(MessageReceived);
        }