protected override async Task <Order> ProcessAsync(Order order)
        {
            HookrRepository.Context.Orders.Remove(order);
            await HookrRepository.SaveChangesAsync();

            return(order);
        }
Ejemplo n.º 2
0
        protected sealed override async Task <Order> ProcessAsync(Order order)
        {
            order.State = NextOrderState;
            await HookrRepository.SaveChangesAsync();

            await NotifyAsync(order, UserContextProvider.DatabaseUser);

            return(order);
        }
Ejemplo n.º 3
0
        protected override async Task <Order> ProcessAsync(Order order)
        {
            var(productName, productIndex, count) = ExtractProductProperties(ArgumentsLeft);
            if (count < 1)
            {
                throw new InvalidOperationException("Seems like there is no real count.");
            }

            switch (productName)
            {
            case nameof(Hookah):
            {
                await AddProductToOrderAsync(order,
                                             productIndex,
                                             count,
                                             context => context.Hookahs,
                                             x => x.OrderedHookahs);

                break;
            }

            case nameof(Tobacco):
            {
                await AddProductToOrderAsync(order,
                                             productIndex,
                                             count,
                                             context => context.Tobaccos,
                                             x => x.OrderedTobaccos);

                break;
            }

            default:
            {
                throw new InvalidOperationException("Wrong product type " + productName);
            }
            }

            await HookrRepository.SaveChangesAsync();

            return(order);
        }
        protected override async Task <Order> ProcessAsync(Order order)
        {
            order.State = OrderStates.Confirmed;
            var(
                notificationFormat,
                fromFormat,
                hookahRowFormat,
                tobaccoRowFormat,
                unknownTranslated,
                approveTranslated,
                rejectTranslated
                ) = await
                    TranslationsResolver.ResolveAsync(
                (TelegramTranslationKeys.NewOrderNotification, Array.Empty <object>()),
                (TelegramTranslationKeys.From, Array.Empty <object>()),
                (TelegramTranslationKeys.OrderNotificationHookahRow, Array.Empty <object>()),
                (TelegramTranslationKeys.OrderNotificationTobaccoRow, Array.Empty <object>()),
                (TelegramTranslationKeys.Unknown, Array.Empty <object>()),
                (TelegramTranslationKeys.Approve, Array.Empty <object>()),
                (TelegramTranslationKeys.Reject, Array.Empty <object>())
                );

            var from         = UserContextProvider.Update.From;
            var notification = string.Format(notificationFormat,
                                             order.Id,
                                             //todo rework as there is a lot of warning about possible empty pointer dereference.
                                             order.OrderedHookahs
                                             .AggregateListString(hookahRowFormat,
                                                                  x => x.Product.Name,
                                                                  x => x.Product.Price,
                                                                  x => x.Count,
                                                                  x => x.Count * x.Product.Price),
                                             order.OrderedTobaccos
                                             .AggregateListString(tobaccoRowFormat,
                                                                  x => x.Product.Name,
                                                                  x => x.Product.Price,
                                                                  x => x.Count,
                                                                  x => x.Count * x.Product.Price),
                                             string.Format(fromFormat,
                                                           string.IsNullOrEmpty(from.Username)
                        ? $"[{unknownTranslated}]"
                        : $"@{from.Username}",
                                                           string.IsNullOrEmpty(from.FirstName)
                        ? $"[{unknownTranslated}]"
                        : from.FirstName,
                                                           string.IsNullOrEmpty(from.LastName)
                        ? $"[{unknownTranslated}]"
                        : from.LastName)
                                             );
            await HookrRepository.SaveChangesAsync();

            await telegramUsersNotifier.SendAsync((client, user) =>
                                                  client.SendTextMessageAsync(user.Id,
                                                                              notification,
                                                                              ParseMode.MarkdownV2,
                                                                              replyMarkup: new InlineKeyboardMarkup(new[]
            {
                new InlineKeyboardButton
                {
                    Text         = approveTranslated,
                    CallbackData = $"/{nameof(ApproveOrderCommand).ExtractCommandName()} {order.Id}"
                },
                new InlineKeyboardButton
                {
                    Text         = rejectTranslated,
                    CallbackData = $"/{nameof(RejectOrderCommand).ExtractCommandName()} {order.Id}"
                }
            })),
                                                  TelegramUserStates.Service,
                                                  TelegramUserStates.Dev);

            return(order);
        }