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); } }
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); }
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()); }
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); } }
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); }
//public HoursReminderService(IHoursReminderStore store, ConversationReference conversation) //{ // SetField.NotNull(out this._store, nameof(_store), store); // SetField.NotNull(out this._conversation, nameof(_conversation), conversation); //} //public HoursReminderService(IHoursReminderStore store, ConversationReference conversation) //{ // SetField.NotNull(out this._store, nameof(store), store); // SetField.NotNull(out this._conversation, nameof(conversation), conversation); //} public async Task ProcessReminders(CancellationToken token) { IHoursReminderStore store = new HoursReminderStore(); IEnumerable <HoursReminderModel> reminders = store.GetReminders(); // process all stored reminders... fetch the number of hours missing for that user and // then send the user a message as a reminder foreach (HoursReminderModel reminder in reminders) { try { TokenCacheFactory.SetTokenCache(reminder.TokenCache); var authToken = await ExactOnlineHelper.GetToken(); ConversationReference conversation = reminder.GetConversationReference(); double?bookedHours = await GetBookedHours(authToken); int contractHours = reminder.ContractHours ?? 40; // TODO: need to get the contracted hours from somewhere if (bookedHours == null) { await SendReminder(conversation, "Hey! I tried to look at your hours but I was unable to. Could you be so kind to do it yourself? Thanks!", token); } else if (bookedHours == 0) { await SendReminder(conversation, $"Hey! I noticed you didn't book any hours yet for this week. You can ask me to book your hours, or do so yourself in Exact.", token); } else if (bookedHours < contractHours) { await SendReminder(conversation, $"Hey! I noticed you've booked {bookedHours} hours this week, I was expecting {contractHours}. Can you please book the rest?", token); } } catch (Exception ex) { Trace.TraceError($"Something went wrong processing the reminders: {ex}."); } } }