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

58 lines
2.1 KiB
C#

using System;
using System.Data.SqlClient;
using SvetoforVKBot.Models.Updates;
using VkNet;
using VkNet.Enums.SafetyEnums;
using VkNet.Model.Keyboard;
using VkNet.Model.RequestParams;
using Newtonsoft.Json;
using VkNet.Enums.Filters;
using System.Text.RegularExpressions;
using SvetoforVKBot.Models.Commands.LK;
using System.Collections.Generic;
using SvetoforVKBot.Models.Commands.LK.SportsLK;
using System.Linq;
namespace SvetoforVKBot.Models.Commands.LK.EditData
{
public class SelectEditNotifyCount : Command
{
public override string Name => "{\"button\":\"selectEditNotifyCount-";
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;
var keyboardBuilder = new KeyboardBuilder().Clear();
Regex regex = new Regex("[^0-9]");
double activityCoef = 0;
try
{
string[] payload = update.@object.message.payload.Split('-');
int notifyCount = Convert.ToInt32(regex.Replace(payload[1], ""));
var user = db.Users.Single(usr => usr.chatId == chatId);
user.notifyCount = notifyCount;
user.tag = "Личный кабинет - Данные";
db.SaveChanges();
SelectEditDataCommand selectEditData = new SelectEditDataCommand();
selectEditData.Execute(update, client, db);
}
catch (Exception ee)
{
@params.Message = "Ошибка в SelectEditNotifyCountCommand: " + ee.Message;
@params.Attachments = null;
@params.Keyboard = null;
@params.UserId = 59111081;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
}
}
}