Files
Parasha/SvetoforVKBot/Models/Commands/Registration/SelectActivityCoefCommand.cs
2021-10-19 06:04:52 +03:00

82 lines
2.7 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.Linq;
namespace SvetoforVKBot.Models.Commands.Registration
{
public class SelectActivityCoefCommand : Command
{
public override string Name => "{\"button\":\"selectActivityCoef-";
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]");
string voronka = "";
double activityCoef = 0;
try
{
string[] payload = update.@object.message.payload.Split('-');
int activity = Convert.ToInt32(regex.Replace(payload[1], ""));
switch(activity)
{
case 1:
activityCoef = 1.2;
break;
case 2:
activityCoef = 1.375;
break;
case 3:
activityCoef = 1.55;
break;
case 4:
activityCoef = 1.725;
break;
case 5:
activityCoef = 1.9;
break;
}
var user = db.Users.Single(usr => usr.chatId == chatId);
user.tag = "Подписчик - Регистрация - Готово";
user.voronka = "Зарегистрирован";
user.activityCoef = activityCoef;
user.reg = 1;
db.SaveChanges();
ShowLKCommand showLK = new ShowLKCommand();
showLK.Execute(update, client, db);
}
catch (Exception ee)
{
@params.Message = "Ошибка в SelectActivityCoefCommand: " + ee.Message;
@params.Attachments = null;
@params.Keyboard = null;
@params.UserId = 59111081;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
}
}
}