Task IActivityLogger.LogAsync(IActivity activity) { IMessageActivity msg = activity.AsMessageActivity(); try { using (SqlDataStore.DataContext dataContext = new SqlDataStore.DataContext()) { var newActivity = Mapper.Map <IMessageActivity, SqlDataStore.Models.Activity>(msg); dataContext.Activities.Add(newActivity); dataContext.SaveChanges(); } } catch (Exception e) { Console.WriteLine(e); } return(Task.CompletedTask); }
public async Task CreditCardIntent(IDialogContext context, LuisResult result) { try { List <CreditCard> creditCards = null; using (SqlDataStore.DataContext dataContext = new SqlDataStore.DataContext()) { var q = from creditCard in dataContext.CreditCards select creditCard; creditCards = q.ToList(); } if (creditCards != null && creditCards.Count > 0) { await context.PostAsync($"We've found {creditCards.Count} credit cards that might interest you..."); var resultMessage = context.MakeMessage(); resultMessage.AttachmentLayout = AttachmentLayoutTypes.Carousel; foreach (var creditCard in creditCards) { var adaptiveCard = CreditCardFactory(creditCard); Attachment attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = adaptiveCard }; resultMessage.Attachments.Add(attachment); } await context.PostAsync(resultMessage); } } catch (Exception e) { Console.WriteLine(e); await context.PostAsync("I'm having some trouble getting credit card details at the moment, maybe try again in a minute or two."); } }
private async Task ResumeAfterSalaryQueryDialog(IDialogContext context, IAwaitable <UserDetail> result) { try { var salaryQuery = await result; List <UserDetail> similarJobs = null; using (SqlDataStore.DataContext dataContext = new SqlDataStore.DataContext()) { salaryQuery.JobTitle = salaryQuery.JobTitle.ToLower(); dataContext.UserDetails.Add(salaryQuery); dataContext.SaveChanges(); var q = from userDetail in dataContext.UserDetails where userDetail.JobTitle.ToLower().Contains(salaryQuery.JobTitle.ToLower()) && userDetail.Location.ToLower().Contains(salaryQuery.Location.ToLower()) select userDetail; similarJobs = q.ToList(); } if (similarJobs != null && similarJobs.Count() > 0) { await context.PostAsync("Nice! Looks like we've found some people in your area that do the same thing as you."); double averageSalary = 0; foreach (var similarJob in similarJobs) { averageSalary = averageSalary + similarJob.Salary; } averageSalary = averageSalary / similarJobs.Count(); if (salaryQuery.Salary > averageSalary) { await context.PostAsync($"Wow, you earn above the average in your area for people with your job!"); await context.PostAsync($"The average salary is only £{string.Format("{0:0.00}", averageSalary)}"); await context.PostAsync($"That means you earn £{string.Format("{0:0.00}", (salaryQuery.Salary - averageSalary))} more than the average {salaryQuery.JobTitle} in your area."); } else { await context.PostAsync($"Hmmmm... Time to ask your boss about a pay increase. You earn less than the going rate in your area."); await context.PostAsync($"The average salary for a {salaryQuery.JobTitle} is £{string.Format("{0:0.00}", averageSalary)}"); await context.PostAsync("So your salary is a bit lower than other people in your area. Don't worry! Want to take a break? Type 'Let's Play' for a game :)"); } } else { await context.PostAsync( "Your PorgPowered survey has been successfully completed. You will get a confirmation email and SMS. Thanks for using PorgPowered salary bot, Welcome Again And May The Porg Be With you!!! :)"); } } catch (FormCanceledException ex) { string reply; if (ex.InnerException == null) { reply = "It looks like you have quit the survey. Rerun this at any time by simply typing \"Start Salary Calculator\""; } else { reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}"; } await context.PostAsync(reply); } finally { context.Done <object>(null); } }