Files
Parasha/SvetoforVKBot/Models/Commands/ExpertLK/SelectParticipantInfoCommand.cs
2021-10-20 06:09:18 +03:00

76 lines
3.0 KiB
C#

using Newtonsoft.Json;
using SvetoforVKBot.Models.Updates;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using System.Linq;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using VkNet;
using VkNet.Enums.SafetyEnums;
using VkNet.Model.Attachments;
using VkNet.Model.Keyboard;
using VkNet.Model.RequestParams;
namespace SvetoforVKBot.Models.Commands.ExpertLK
{
public class SelectParticipantInfoCommand : Command
{
public override string Name => "{\"button\":\"selectParticipantInfo-";
public override void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db) { }
public override void ExecutePL(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
var chatId = update.@object.message.from_id;
MessagesSendParams @params = new MessagesSendParams();
var keyboardBuilder = new KeyboardBuilder().Clear();
List<UserObject> users = new List<UserObject>();
List<int> chatIds = new List<int>();
string name = "";
Regex regex = new Regex("[^0-9]");
try
{
string[] payload = update.@object.message.payload.Split('-');
int userId = Convert.ToInt32(regex.Replace(payload[1], ""));
//@params.Message = "Выберите участника.\n";
var user = db.Users.Single(usr => usr.id == userId);
int uChatId = Convert.ToInt32(user.chatId);
var idsVk = new long[] { uChatId };
var userVk = client.Users.Get(idsVk);
//string fio = user.fio;
var birthday = user.birthday;
var jsPhones = JsonConvert.DeserializeObject<List<string>>(user.phone);
@params.Message = "Участник:\n\n" +
userVk[0].FirstName + " " + userVk[0].LastName + "\n" +
"Дата рождения: " + birthday.ToShortDateString() + "\n" +
"Телефон: " + jsPhones[0];
keyboardBuilder
.AddButton("Вкл. персональный режим", "selectPersonalPlan-" + userId, KeyboardButtonColor.Positive)
.AddLine()
.AddButton("Назад", "selectExpertLK", KeyboardButtonColor.Default);
@params.Keyboard = keyboardBuilder.Build();
@params.UserId = chatId;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
catch (Exception ee)
{
@params.Message = "Ошибка в SelectParticipantInfoCommand: " + ee.Message;
@params.Attachments = null;
@params.Keyboard = null;
@params.UserId = 59111081;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
}
}
}