/// <summary> /// Gets view reflections data. /// </summary> /// <param name="reflectionId">reflectionId.</param> /// <returns>A task that represents the work queued to execute.</returns> public async Task <ViewReflectionsEntity> GetViewReflectionsData(Guid reflectionId) { _telemetry.TrackEvent("GetViewReflectionsData"); try { ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); ViewReflectionsEntity viewReflectionsEntity = new ViewReflectionsEntity(); QuestionsDataRepository questionsDataRepository = new QuestionsDataRepository(_configuration, _telemetry); // Get reflection data ReflectionDataEntity refData = await reflectionDataRepository.GetReflectionData(reflectionId) ?? null; Dictionary <int, List <FeedbackDataEntity> > feedbackData = await feedbackDataRepository.GetReflectionFeedback(reflectionId) ?? null; List <QuestionsDataEntity> questions = await questionsDataRepository.GetQuestionsByQID(refData.QuestionID) ?? null; viewReflectionsEntity.ReflectionData = refData; viewReflectionsEntity.FeedbackData = feedbackData; viewReflectionsEntity.Question = questions.Find(x => x.QuestionID == refData.QuestionID); return(viewReflectionsEntity); } catch (Exception ex) { _telemetry.TrackException(ex); return(null); } }
/// <summary> /// Save Question data in Table Storage based on different conditions. /// </summary> /// <param name="taskInfo">This parameter is a ViewModel.</param> /// <returns>Null.</returns> public async Task SaveQuestionsDataAsync(TaskInfo taskInfo) { _telemetry.TrackEvent("DeleteReflections"); try { QuestionsDataRepository questionsDataRepository = new QuestionsDataRepository(_configuration, _telemetry); QuestionsDataEntity questionEntity = new QuestionsDataEntity { QuestionID = taskInfo.questionID, PartitionKey = PartitionKeyNames.QuestionsDataTable.QuestionsDataPartition, RowKey = taskInfo.questionRowKey, Question = taskInfo.question, IsDefaultFlag = false, QuestionCreatedDate = DateTime.Now, CreatedBy = taskInfo.postCreateBy, CreatedByEmail = taskInfo.postCreatedByEmail, }; await questionsDataRepository.CreateOrUpdateAsync(questionEntity); } catch (Exception ex) { _telemetry.TrackException(ex); } }
/// <summary> /// Save Question data in Table Storage for deafult questions based on different conditions. /// </summary> /// <returns>Null.</returns> public async Task SaveDefaultQuestionsDataAsync() { QuestionsDataRepository questionsDataRepository = new QuestionsDataRepository(_configuration, _telemetry); var isDefaultQuestionsPresent = await questionsDataRepository.IsDefaultQuestionAlreadyPresent(); if (!isDefaultQuestionsPresent) { _telemetry.TrackEvent("DefaultQuestions"); try { List <string> questions = _configuration.GetSection("DefaultQuestions:Questions").Get <List <string> >(); foreach (string question in questions) { QuestionsDataEntity questionEntity = new QuestionsDataEntity { QuestionID = Guid.NewGuid(), PartitionKey = PartitionKeyNames.QuestionsDataTable.QuestionsDataPartition, RowKey = Guid.NewGuid().ToString(), Question = question, IsDefaultFlag = true, QuestionCreatedDate = DateTime.Now, }; await questionsDataRepository.CreateOrUpdateAsync(questionEntity); } } catch (Exception ex) { _telemetry.TrackException(ex); } } }
/// <summary> /// Initializes a new instance of the <see cref="HomeController"/> class. /// Home controller. /// </summary> public HomeController(QuestionsDataRepository dataRepository, IConfiguration configuration, ReflectionDataRepository refrepository, IWebHostEnvironment webHostEnvironment, TelemetryClient telemetry, IDataBase dbHelper) { _repository = dataRepository; _configuration = configuration; _refrepository = refrepository; _webHostEnvironment = webHostEnvironment; _telemetry = telemetry; _dbHelper = dbHelper; }
/// <summary> /// On Teams Task Module Submit Async. /// </summary> /// <param name="turnContext">turnContext.</param> /// <param name="taskModuleRequest">taskModuleRequest.</param> /// <param name="cancellationToken">cancellationToken.</param> /// <returns>.</returns> protected override async Task <TaskModuleResponse> OnTeamsTaskModuleSubmitAsync(ITurnContext <IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, CancellationToken cancellationToken) { ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); QuestionsDataRepository questiondatarepository = new QuestionsDataRepository(_configuration, _telemetry); FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); try { TaskInfo taskInfo = JsonConvert.DeserializeObject <TaskInfo>(taskModuleRequest.Data.ToString()); var reply = Activity.CreateMessageActivity(); // Check if message id is present in reflect data ReflectionDataEntity reflectData = await reflectionDataRepository.GetReflectionData(taskInfo.reflectionID); QuestionsDataEntity question = await questiondatarepository.GetQuestionData(reflectData.QuestionID); Dictionary <int, List <FeedbackDataEntity> > feedbacks = await feedbackDataRepository.GetReflectionFeedback(taskInfo.reflectionID); var adaptiveCard = _cardHelper.FeedBackCard(feedbacks, taskInfo.reflectionID, question.Question); Attachment attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = adaptiveCard }; reply.Attachments.Add(attachment); if (reflectData.MessageID == null) { var result = turnContext.SendActivityAsync(reply, cancellationToken); reflectData.MessageID = result.Result.Id; // update messageid in reflection table await reflectionDataRepository.InsertOrMergeAsync(reflectData); } else { reply.Id = reflectData.MessageID; await turnContext.UpdateActivityAsync(reply); } return(null); } catch (System.Exception e) { _telemetry.TrackException(e); Console.WriteLine(e.Message.ToString()); return(null); } }
/// <summary> /// Get the data from the Recurrence able storage based on the email id. /// </summary> /// <param name="email">email id of the creator of the reflection.</param> /// <returns>RecurssionScreenData model.</returns> public async Task <List <RecurssionScreenData> > GetRecurrencePostsDataAsync(string email) { _telemetry.TrackEvent("GetRecurrencePostsDataAsync"); try { ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); QuestionsDataRepository questionsDataRepository = new QuestionsDataRepository(_configuration, _telemetry); RecurssionDataRepository recurssionDataRepository = new RecurssionDataRepository(_configuration, _telemetry); List <ReflectionDataEntity> allActiveRefs = await reflectionDataRepository.GetAllActiveReflection(email); List <Guid?> allActiveRefIDs = allActiveRefs.Select(c => c.ReflectionID).ToList(); List <Guid?> allActiveQuestionIDs = allActiveRefs.Select(c => c.QuestionID).ToList(); List <QuestionsDataEntity> allQuestionsData = await questionsDataRepository.GetAllQuestionData(allActiveQuestionIDs); List <RecurssionDataEntity> allRecurssionData = await recurssionDataRepository.GetAllRecurssionData(allActiveRefIDs); List <RecurssionScreenData> screenData = new List <RecurssionScreenData>(); foreach (var rec in allRecurssionData) { RecurssionScreenData recurssionScreenData = new RecurssionScreenData(); recurssionScreenData.RefID = rec.ReflectionID; var reflection = await reflectionDataRepository.GetReflectionData(rec.ReflectionID); recurssionScreenData.CreatedBy = reflection.CreatedBy; recurssionScreenData.RefCreatedDate = reflection.RefCreatedDate; recurssionScreenData.Privacy = reflection.Privacy; recurssionScreenData.Question = allQuestionsData.Where(c => c.QuestionID.ToString() == reflection.QuestionID.ToString()).Select(d => d.Question).FirstOrDefault().ToString(); recurssionScreenData.ExecutionDate = rec.ExecutionDate; recurssionScreenData.ExecutionTime = rec.ExecutionTime; recurssionScreenData.NextExecutionDate = rec.NextExecutionDate; recurssionScreenData.RecurssionType = rec.RecursstionType; recurssionScreenData.CustomRecurssionTypeValue = rec.CustomRecurssionTypeValue; recurssionScreenData.ScheduleId = rec.ScheduleId; if (recurssionScreenData.RecurssionType != null && recurssionScreenData.NextExecutionDate != null) { screenData.Add(recurssionScreenData); } } return(screenData); } catch (Exception ex) { _telemetry.TrackException(ex); return(null); } }
/// <summary> /// Save Reflection data in Table Storage based on different conditions. /// </summary> /// <param name="taskInfo">This parameter is a ViewModel.</param> /// <returns>Null.</returns> public async Task SaveReflectionDataAsync(TaskInfo taskInfo) { _telemetry.TrackEvent("SaveReflectionDataAsync"); try { ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); QuestionsDataRepository questionsDataRepository = new QuestionsDataRepository(_configuration, _telemetry); if (taskInfo != null) { taskInfo.reflectionID = Guid.NewGuid(); taskInfo.recurssionID = Guid.NewGuid(); if (taskInfo.questionID == null) { taskInfo.questionID = Guid.NewGuid(); } ReflectionDataEntity reflectEntity = new ReflectionDataEntity { ReflectionID = taskInfo.reflectionID, PartitionKey = PartitionKeyNames.ReflectionDataTable.ReflectionDataPartition, RowKey = taskInfo.reflectionRowKey, CreatedBy = taskInfo.postCreateBy, CreatedByEmail = taskInfo.postCreatedByEmail, RefCreatedDate = DateTime.Now, QuestionID = taskInfo.questionID, Privacy = taskInfo.privacy, RecurrsionID = taskInfo.recurssionID, ChannelID = taskInfo.channelID, MessageID = taskInfo.messageID, SendNowFlag = taskInfo.postSendNowFlag, IsActive = taskInfo.IsActive, ReflectMessageId = taskInfo.reflectMessageId, TenantId = taskInfo.teantId, ServiceUrl = taskInfo.serviceUrl, ScheduleId = taskInfo.scheduleId }; await reflectionDataRepository.InsertOrMergeAsync(reflectEntity); if (await questionsDataRepository.IsQuestionAlreadyPresent(taskInfo.question, taskInfo.postCreatedByEmail) == false) { await SaveQuestionsDataAsync(taskInfo); } else { var ques = await questionsDataRepository.GetQuestionData(taskInfo.questionID); taskInfo.questionRowKey = ques.RowKey; } if (!(taskInfo.postSendNowFlag == true)) { await SaveRecurssionDataAsync(taskInfo); } } } catch (Exception ex) { _telemetry.TrackException(ex); } }
/// <summary> /// On message activity sync. /// </summary> /// <param name="turnContext">turnContext.</param> /// <param name="cancellationToken">cancellationToken.</param> /// <returns>.</returns> protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { _telemetry.TrackEvent("OnMessageActivityAsync"); try { FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); RecurssionDataRepository recurssionDataRepository = new RecurssionDataRepository(_configuration, _telemetry); QuestionsDataRepository questiondatarepository = new QuestionsDataRepository(_configuration, _telemetry); if (turnContext.Activity.Value != null) { var response = JsonConvert.DeserializeObject <UserfeedbackInfo>(turnContext.Activity.Value.ToString()); var reply = Activity.CreateMessageActivity(); if (response.type == ReflectConstants.SaveFeedBack) { var name = (turnContext.Activity.From.Name).Split(); response.userName = name[0] + ' ' + name[1]; response.emailId = await _dbHelper.GetUserEmailId(turnContext); // Check if this is user's second feedback FeedbackDataEntity feebackData = await feedbackDataRepository.GetReflectionFeedback(response.reflectionId, response.emailId); if (feebackData != null && response.emailId == feebackData.FeedbackGivenBy) { feebackData.Feedback = response.feedbackId; await feedbackDataRepository.CreateOrUpdateAsync(feebackData); } else { await _dbHelper.SaveReflectionFeedbackDataAsync(response); } try { // Check if message id is present in reflect data ReflectionDataEntity reflectData = await reflectionDataRepository.GetReflectionData(response.reflectionId); QuestionsDataEntity question = await questiondatarepository.GetQuestionData(reflectData.QuestionID); Dictionary <int, List <FeedbackDataEntity> > feedbacks = await feedbackDataRepository.GetReflectionFeedback(response.reflectionId); var adaptiveCard = _cardHelper.FeedBackCard(feedbacks, response.reflectionId, question.Question); TaskInfo taskInfo = new TaskInfo(); taskInfo.question = question.Question; taskInfo.postCreateBy = reflectData.CreatedBy; taskInfo.privacy = reflectData.Privacy; taskInfo.reflectionID = reflectData.ReflectionID; Attachment attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = adaptiveCard }; reply.Attachments.Add(attachment); if (reflectData.MessageID == null) { var result = turnContext.SendActivityAsync(reply, cancellationToken); reflectData.MessageID = result.Result.Id; // update message-id in reflection table await reflectionDataRepository.InsertOrMergeAsync(reflectData); } else { reply.Id = reflectData.MessageID; await turnContext.UpdateActivityAsync(reply); } } catch (System.Exception e) { _telemetry.TrackException(e); Console.WriteLine(e.Message.ToString()); } } } else { await turnContext.SendActivityAsync(MessageFactory.Text($"Hello from Olga."), cancellationToken); } } catch (Exception ex) { _telemetry.TrackException(ex); } }
/// <summary> /// On Teams Task Module Fetch Async. /// </summary> /// <param name="turnContext">turnContext.</param> /// <param name="taskModuleRequest">taskModuleRequest.</param> /// <param name="cancellationToken">cancellationToken.</param> /// <returns>.</returns> protected override async Task <TaskModuleResponse> OnTeamsTaskModuleFetchAsync(ITurnContext <IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, CancellationToken cancellationToken) { _telemetry.TrackEvent("OnTeamsTaskModuleFetchAsync"); try { ReflctionData reldata = JsonConvert.DeserializeObject <ReflctionData>(taskModuleRequest.Data.ToString()); FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); RecurssionDataRepository recurssionDataRepository = new RecurssionDataRepository(_configuration, _telemetry); QuestionsDataRepository questiondatarepository = new QuestionsDataRepository(_configuration, _telemetry); var response = new UserfeedbackInfo(); var name = (turnContext.Activity.From.Name).Split(); response.userName = name[0] + ' ' + name[1]; response.emailId = await _dbHelper.GetUserEmailId(turnContext); var reflectionid = reldata.datajson.ReflectionId; var feedbackId = reldata.datajson.FeedbackId; response.reflectionId = reflectionid; response.feedbackId = feedbackId; // Check if this is user's second feedback FeedbackDataEntity feebackData = await feedbackDataRepository.GetReflectionFeedback(response.reflectionId, response.emailId); TaskInfo taskInfo = new TaskInfo(); if (response.feedbackId != 0) { if (feebackData != null && response.emailId == feebackData.FeedbackGivenBy) { feebackData.Feedback = response.feedbackId; await feedbackDataRepository.CreateOrUpdateAsync(feebackData); } else { await _dbHelper.SaveReflectionFeedbackDataAsync(response); } try { // Check if message id is present in reflect data ReflectionDataEntity reflectData = await reflectionDataRepository.GetReflectionData(response.reflectionId); QuestionsDataEntity question = await questiondatarepository.GetQuestionData(reflectData.QuestionID); Dictionary <int, List <FeedbackDataEntity> > feedbacks = await feedbackDataRepository.GetReflectionFeedback(response.reflectionId); var adaptiveCard = _cardHelper.FeedBackCard(feedbacks, response.reflectionId, question.Question); taskInfo.question = question.Question; taskInfo.postCreateBy = reflectData.CreatedBy; taskInfo.privacy = reflectData.Privacy; taskInfo.reflectionID = reflectData.ReflectionID; Attachment attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = adaptiveCard, }; var reply = Activity.CreateMessageActivity(); reply.Attachments.Add(attachment); if (reflectData.MessageID == null) { var result = turnContext.SendActivityAsync(reply, cancellationToken); reflectData.MessageID = result.Result.Id; // update messageid in reflection table await reflectionDataRepository.InsertOrMergeAsync(reflectData); } else { reply.Id = reflectData.MessageID; await turnContext.UpdateActivityAsync(reply); } } catch (System.Exception e) { _telemetry.TrackException(e); Console.WriteLine(e.Message.ToString()); } } return(new TaskModuleResponse { Task = new TaskModuleContinueResponse { Value = new TaskModuleTaskInfo() { Height = 600, Width = 600, Title = "Track how you're feeling every day.", Url = reldata.data.URL + reflectionid + '/' + feedbackId + '/' + response.userName, }, }, }); } catch (Exception ex) { _telemetry.TrackException(ex); return(null); } }
/// <summary> /// RunJob. /// </summary> /// <param name="state">state.</param> private async void RunJob(object state) { _telemetry.TrackEvent("RunJob"); try { ChannelAccount channelAccount = new ChannelAccount(_configuration["MicrosoftAppId"]); Attachment attachment = new Attachment(); TeamsChannelData channelData = new TeamsChannelData() { Notification = new NotificationInfo(true) }; RecurssionDataRepository recurssionDataRepository = new RecurssionDataRepository(_configuration, _telemetry); ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); QuestionsDataRepository questiondatarepository = new QuestionsDataRepository(_configuration, _telemetry); var recurssionData = await recurssionDataRepository.GetAllRecurssionData(); foreach (RecurssionDataEntity recurssionDataEntity in recurssionData) { var reflectionData = await reflectionDataRepository.GetReflectionData(recurssionDataEntity.ReflectionID); var question = await questiondatarepository.GetQuestionData(reflectionData.QuestionID); TaskInfo taskInfo = new TaskInfo(); taskInfo.question = question.Question; taskInfo.postCreateBy = reflectionData.CreatedBy; taskInfo.privacy = reflectionData.Privacy; taskInfo.reflectionID = reflectionData.ReflectionID; var newPostCard = _cardHelper.CreateNewReflect(taskInfo); Attachment newPostCardAttachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = newPostCard }; var PostCardFeedback = _cardHelper.FeedBackCard(new Dictionary <int, List <FeedbackDataEntity> >(), taskInfo.reflectionID, taskInfo.question);; Attachment PostCardFeedbackAttachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = PostCardFeedback }; var proactiveNotification = await new ProactiveMessageHelper(_configuration).SendChannelNotification(channelAccount, reflectionData.ServiceUrl, reflectionData.ChannelID, "", newPostCardAttachment); if (proactiveNotification.IsSuccessful && proactiveNotification.MessageId != null) { reflectionData.ReflectMessageId = proactiveNotification.MessageId.Split("=")[1]; var feedbackproactivemessage = await new ProactiveMessageHelper(_configuration).SendChannelNotification(channelAccount, reflectionData.ServiceUrl, reflectionData.ChannelID, "", PostCardFeedbackAttachment, reflectionData.ReflectMessageId); if (feedbackproactivemessage.IsSuccessful && proactiveNotification.MessageId != null) { reflectionData.MessageID = feedbackproactivemessage.MessageId; await _dbHelper.UpdateReflectionMessageIdAsync(reflectionData); } } var calculatedNextExecutionDateTime = _dbHelper.GetCalculatedNextExecutionDateTimeAsync(recurssionDataEntity); recurssionDataEntity.NextExecutionDate = null; await recurssionDataRepository.CreateOrUpdateAsync(recurssionDataEntity); if (calculatedNextExecutionDateTime != null) { ReflectionDataEntity newreflectionDataEntity = new ReflectionDataEntity(); RecurssionDataEntity newRecurssionDataEntity = new RecurssionDataEntity(); var reflectionid = Guid.NewGuid(); var recurrsionid = Guid.NewGuid(); newreflectionDataEntity = reflectionData; newreflectionDataEntity.RowKey = Guid.NewGuid().ToString(); newreflectionDataEntity.ReflectionID = reflectionid; newreflectionDataEntity.RefCreatedDate = DateTime.Now; newreflectionDataEntity.RecurrsionID = recurrsionid; await reflectionDataRepository.CreateAsync(newreflectionDataEntity); newRecurssionDataEntity = recurssionDataEntity; newRecurssionDataEntity.RowKey = Guid.NewGuid().ToString(); newRecurssionDataEntity.ReflectionID = reflectionid; newRecurssionDataEntity.CreatedDate = DateTime.Now; newRecurssionDataEntity.RecurssionID = recurrsionid; newRecurssionDataEntity.NextExecutionDate = calculatedNextExecutionDateTime; await recurssionDataRepository.CreateAsync(newRecurssionDataEntity); } } } catch (Exception ex) { _telemetry.TrackException(ex); } }