Files
Parasha/SvetoforVKBot/Models/Commands/LK/Cart/SelectConfirmClearCartCommand.cs
2021-10-19 06:04:52 +03:00

54 lines
1.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Data.SqlClient;
using SvetoforVKBot.Models.Commands.LK.Menu.Products;
using SvetoforVKBot.Models.Updates;
using VkNet;
using VkNet.Model.RequestParams;
using VkNet.Model.Keyboard;
using VkNet.Enums.SafetyEnums;
using Newtonsoft.Json;
using System.Linq;
namespace SvetoforVKBot.Models.Commands.LK.Cart
{
public class SelectConfirmClearCartCommand : Command
{
public override string Name => "{\"button\":\"selectConfirmClearCart\"}";
public override void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
}
public override void ExecutePL(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
MessagesSendParams @params = new MessagesSendParams();
var chatId = update.@object.message.from_id;
string msg = "";
var keyboardBuilder = new KeyboardBuilder().Clear();
try
{
var user = db.Users.Single(usr => usr.chatId == chatId);
var jsCart = JsonConvert.DeserializeObject<CartObject>(user.cart);
jsCart.orders.RemoveAll(o => o.id.StartsWith("0-") == false);
user.cart = JsonConvert.SerializeObject(jsCart);
db.SaveChanges();
msg = "✅Корзина очищена.\nВозвращаю в Личный кабинет.\n";
ShowLKCommand showLK = new ShowLKCommand();
showLK.Execute(update, client, db);
}
catch (Exception ee)
{
@params.Message = "‼Ошибка в SelectConfirmClearCartCommand: " + ee.Message;
@params.Attachments = null;
@params.Keyboard = null;
@params.UserId = 59111081;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
}
}
}