From c1008e1040d42086c8c135cd4c577c51f8c68a0b Mon Sep 17 00:00:00 2001 From: West14 <30056636+West14@users.noreply.github.com> Date: Fri, 25 Feb 2022 20:47:24 +0200 Subject: [PATCH] [store] Refactor store command handler to use LINQ. --- modules/ContentStore/Handler/Store.cs | 35 +++++++-------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/modules/ContentStore/Handler/Store.cs b/modules/ContentStore/Handler/Store.cs index c07aee9..19d1f34 100644 --- a/modules/ContentStore/Handler/Store.cs +++ b/modules/ContentStore/Handler/Store.cs @@ -36,32 +36,15 @@ public class Store : BotEventHandler await Bot.SendTextMessageAsync(Chat.Id, "Reputation is unavailable."); return; } - - var rowList = new List>(); - - var counter = 0; - var list = new List(); - foreach (var item in _provider.GetServices() - .OrderBy(s => s.StoreItem.Order)) - { - var btn = item.StoreItem.ToButton(From.Id); - if ((counter & 1) == 0) // 0 - even, 1 - odd - { - list = new List - { - btn - }; - } - else - { - list.Add(btn); - rowList.Add(list); - } - - counter++; - } - - await Bot.SendTextMessageAsync(Chat.Id, "Чего пожелаете?", replyMarkup: new InlineKeyboardMarkup(rowList)); + + await Bot.SendTextMessageAsync(Chat.Id, "Чего пожелаете?", replyMarkup: new InlineKeyboardMarkup( + _provider.GetServices() + .OrderBy(x => x.StoreItem.Order) + .Select(x => x.StoreItem.ToButton(From.Id)) + .Chunk(2) + .ToList() + ) + ); } [Update(InChat.Public, UpdateFlag.CallbackQuery)]