async def add_step(self,
                    step_context: WaterfallStepContext) -> DialogTurnResult:
     title = step_context.result
     book_to_add = self.find_book(title)
     iduser = step_context.context.activity.from_property.id
     if book_to_add is not None:
         if DatabaseManager.add_book_wishlist(iduser, book_to_add,
                                              [book_to_add.genre]):
             message_text = "Il libro {} è stato aggiunto alla tua wishlist.".format(
                 book_to_add.name)
             await step_context.context.send_activity(
                 MessageFactory.text(message_text))
         else:
             message_text = "Il libro {} non è stato aggiunto alla tua wishlist.".format(
                 book_to_add.name)
             await step_context.context.send_activity(
                 MessageFactory.text(message_text))
     return await step_context.end_dialog()
Esempio n. 2
0
    async def add_to_wishlist(
            self, step_context: WaterfallStepContext) -> DialogTurnResult:
        result = step_context.result
        iduser = step_context.context.activity.from_property.id
        book_to_add = BookInfo()
        books = step_context.values["books"]
        for book in books:
            if book.site.lower() == result.lower():
                book_to_add = book
                break
        for book in books:
            if book.name is not None:
                book_to_add.name = book.name
                break
        for book in books:
            if book.author is not None:
                book_to_add.author = book.author
                break

        genres = []
        for book in books:
            if book.genre is not None:
                genres.append(book.genre)
        if book_to_add.site is not None:
            if DatabaseManager.add_book_wishlist(iduser, book_to_add, genres):
                message_text = (
                    "Il libro {} è stato aggiunto alla tua wishlist".format(
                        book_to_add.name))
                message = MessageFactory.text(message_text, message_text,
                                              InputHints.ignoring_input)
                await step_context.context.send_activity(message)
                return await step_context.end_dialog()
        message_text = (
            "Si è verificato un errore durante l'aggiunta del libro {} alla tua wishlist"
            .format(book_to_add.name))
        message = MessageFactory.text(message_text, message_text,
                                      InputHints.ignoring_input)
        await step_context.context.send_activity(message)
        return await step_context.end_dialog()