protected override OutputModel <ManageDeckSlotType> ProcessIntent() { string dialogActionType = Constants.DIALOG_ACTION_TYPE_ELICIT; string fulfillmentState = null; string intentName = InputModel.CurrentIntent.Name; var slots = InputModel.CurrentIntent.Slots; var errors = InputModel.CurrentIntent.Slots.Validate(); string slotToElicit = InputModel.CurrentIntent.Slots.GetSlotToElicit(); string responseMessage = String.Empty; string manageType = InputModel.CurrentIntent.Slots.ManageType.ToLower(); if (slotToElicit == nameof(ManageDeckSlotType.ManageType)) { var error = errors.FirstOrDefault(rr => rr.PropertyName == nameof(ManageDeckSlotType.ManageType)); if (error != null) { responseMessage = "Would you like to add a new, modify an existing, or delete a flash card deck?"; } else { responseMessage = String.Format(Constants.ERROR_MESSAGE_INVALID_VALUE, "Manage Type is invalid"); InputModel.CurrentIntent.Slots.ManageType = null; } } else if (slotToElicit == nameof(ManageDeckSlotType.DeckName)) { responseMessage = String.Format("What is the name of the flash card deck you'd like to {0}?", manageType); var allDecks = Dal.GetAllDecks(InputModel.UserID); if (allDecks != null && allDecks.Any()) { responseMessage = String.Format("{0} {1}", responseMessage, DeckUtilitites.CreateDeckInformationMessage(allDecks)); } } else if (slotToElicit == nameof(ManageDeckSlotType.Front)) { if (Dal.DeckExits(InputModel.UserID, slots.DeckName)) { responseMessage = "Enter the front of the card"; } else { responseMessage = String.Format("You don't have a flash card deck named {0}!", slots.DeckName); slotToElicit = null; dialogActionType = Constants.DIALOG_ACTION_TYPE_CLOSE; fulfillmentState = Constants.FULLFILLMENT_STATE_FULFILLED; intentName = null; slots = null; } } else if (slotToElicit == nameof(ManageDeckSlotType.Back)) { responseMessage = "Enter the back of the card"; } else if (slotToElicit == nameof(ManageDeckSlotType.Confirm)) { bool fulFill = false; if (manageType == Constants.ManageTypes.Add.ToString().ToLower()) { if (!Dal.DeckExits(InputModel.UserID, slots.DeckName)) { responseMessage = String.Format("Are you sure you want to add {0} as a new flash card deck?", InputModel.CurrentIntent.Slots.DeckName); } else { fulFill = true; responseMessage = String.Format("You already have a deck named {0}!", slots.DeckName); } } else if (manageType == Constants.ManageTypes.Delete.ToString().ToLower()) { if (Dal.DeckExits(InputModel.UserID, slots.DeckName)) { responseMessage = String.Format("Are you sure you want to delete the flash card deck named {0}", InputModel.CurrentIntent.Slots.DeckName); } else { fulFill = true; responseMessage = String.Format("You don't have a deck named {0}!", slots.DeckName); } } else if (manageType == Constants.ManageTypes.Modify.ToString().ToLower()) { Dal.AddCardToDeck(InputModel.UserID, slots.DeckName, slots.Front, slots.Back); responseMessage = "Would you like to add another?"; } if (fulFill) { slotToElicit = null; dialogActionType = Constants.DIALOG_ACTION_TYPE_CLOSE; fulfillmentState = Constants.FULLFILLMENT_STATE_FULFILLED; intentName = null; slots = null; } } else if (slotToElicit == string.Empty) { if (InputModel.CurrentIntent.Slots.Confirm.ToLower() == "yes") { string successType = String.Empty; if (manageType == Constants.ManageTypes.Modify.ToString().ToLower()) { slots.Front = null; slots.Back = null; slots.Confirm = null; slotToElicit = slots.GetSlotToElicit(); responseMessage = "Enter the front of the card"; } else { if (manageType == Constants.ManageTypes.Add.ToString().ToLower()) { manageType = "added"; Dal.AddNewDeck(InputModel.UserID, slots.DeckName); responseMessage = String.Format(Constants.MESSAGE_RESPONSE_UPDATE_SUCCESS, manageType); } else if (manageType == Constants.ManageTypes.Delete.ToString().ToLower()) { manageType = "deleted"; responseMessage = String.Format(Constants.MESSAGE_RESPONSE_UPDATE_SUCCESS, manageType); Dal.DeleteDeck(InputModel.UserID, slots.DeckName); } slotToElicit = null; dialogActionType = Constants.DIALOG_ACTION_TYPE_CLOSE; fulfillmentState = Constants.FULLFILLMENT_STATE_FULFILLED; intentName = null; slots = null; } } else { responseMessage = "OK"; slotToElicit = null; dialogActionType = Constants.DIALOG_ACTION_TYPE_CLOSE; fulfillmentState = Constants.FULLFILLMENT_STATE_FULFILLED; intentName = null; slots = null; } } var outputModel = new OutputModel <ManageDeckSlotType>(); outputModel.dialogAction.type = dialogActionType; outputModel.dialogAction.fulfillmentState = fulfillmentState; outputModel.dialogAction.slots = slots; outputModel.dialogAction.message.content = responseMessage; outputModel.dialogAction.message.contentType = Constants.RESPONSE_CONTENT_TYPE; outputModel.dialogAction.slotToElicit = slotToElicit; outputModel.dialogAction.intentName = intentName; return(outputModel); }
protected override OutputModel <QuizSlotType> ProcessIntent() { string fulfillmentState = null; string dialogActionType = Constants.DIALOG_ACTION_TYPE_ELICIT; string intentName = InputModel.CurrentIntent.Name; var slots = InputModel.CurrentIntent.Slots; string slotToElicit = InputModel.CurrentIntent.Slots.GetSlotToElicit(); string responseMessage = String.Empty; string quizOrder = slots.QuizOrder == null ? String.Empty : slots.QuizOrder.ToLower(); string quizProgression = slots.QuizProgression == null ? String.Empty : slots.QuizProgression.ToLower(); ResponseCard responseCard = null; if (slotToElicit == nameof(QuizSlotType.DeckName)) { responseMessage = "What is the name of the flash card deck you'd like to be quizzed on?"; var allDecks = Dal.GetAllDecks(InputModel.UserID); if (allDecks != null && allDecks.Any()) { responseMessage = String.Format("{0} {1}", responseMessage, DeckUtilitites.CreateDeckInformationMessage(allDecks)); } } else if (slotToElicit == nameof(QuizSlotType.QuizOrder)) { var allDecks = Dal.GetAllDecks(InputModel.UserID); Deck quizDeck = allDecks?.FirstOrDefault(deck => deck.DeckName == slots.DeckName); if (allDecks != null && quizDeck != null) { responseMessage = "Would you liked to be quizzed in an in order or random fashion?"; responseCard = BuildOrderResponseCard(1); quizDeck.Cards = quizDeck.GetNonDeletedCards(); quizDeck.ResetDeck(); Dal.UpdateDeck(quizDeck); } else { responseMessage = "You don't have a deck with that name!"; } } else if (slotToElicit == nameof(QuizSlotType.QuizProgression)) { Card currentCard = null; bool deleteCurrent = false; bool quizOver = false; var deck = Dal.GetDeck(InputModel.UserID, slots.DeckName); if (!deck.Cards.Any()) { responseMessage = "The deck you selected does not contain any cards!"; } //If quiz hasn't started, set random property and call GetNextCard, always. //Otherwise, use the value of the QuizProgressionSlot else if (!deck.IsQuizStarted) { deck.IsQuizRandom = quizOrder.Equals(Constants.QuizOrder.Random.ToString().ToLower()); currentCard = deck.GetNextCard(); } else { if (quizProgression == Constants.QuizProgression.Next.ToString().ToLower()) { currentCard = deck.GetNextCard(); } else if (quizProgression == Constants.QuizProgression.Previous.ToString().ToLower()) { currentCard = deck.GetPreviousCard(); } else if (quizProgression == Constants.QuizProgression.Skip.ToString().ToLower()) { currentCard = deck.SkipCurrentCardAndGetNext(); } else if (quizProgression == Constants.QuizProgression.Delete.ToString().ToLower()) { currentCard = deck.GetCurrentCard(); deleteCurrent = true; } else if (quizProgression == Constants.QuizProgression.Stop.ToString().ToLower()) { quizOver = true; } } if (currentCard == null) { quizOver = true; } else if (deleteCurrent) { currentCard.IsDeleted = true; currentCard = deck.GetNextCard(); } if (currentCard != null) { slots.QuizProgression = null; slotToElicit = slots.GetSlotToElicit(); var quizCardStatus = currentCard.GetCardStatus(); //responseMessage = String.Format("Here is the {0} of the card.", quizCardStatus.ToString().ToLower()); responseMessage = currentCard.GetCardDataBasedOnStatus(); responseCard = BuildProgressionResponseCard(2, currentCard.GetCardDataBasedOnStatus()); Dal.UpdateDeck(deck); } else { quizOver = true; } if (quizOver) { if (responseMessage == String.Empty) { responseMessage = "The quiz has ended!"; } slotToElicit = null; dialogActionType = Constants.DIALOG_ACTION_TYPE_CLOSE; fulfillmentState = Constants.FULLFILLMENT_STATE_FULFILLED; intentName = null; slots = null; } } var outputModel = new OutputModel <QuizSlotType>(); outputModel.dialogAction.fulfillmentState = fulfillmentState; outputModel.dialogAction.type = dialogActionType; outputModel.dialogAction.slots = slots; outputModel.dialogAction.message.content = responseMessage; outputModel.dialogAction.message.contentType = Constants.RESPONSE_CONTENT_TYPE; outputModel.dialogAction.slotToElicit = slotToElicit; outputModel.dialogAction.intentName = intentName; outputModel.dialogAction.responseCard = responseCard; return(outputModel); }