Добавьте файлы проекта.

This commit is contained in:
Daria
2021-10-19 06:04:52 +03:00
parent 6ee25d0f59
commit eab3081ec2
187 changed files with 100839 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
using SvetoforVKBot.Models.Updates;
using System;
using System.Data.SqlClient;
using VkNet;
using VkNet.Model.Keyboard;
using VkNet.Model.RequestParams;
using VkNet.Enums.SafetyEnums;
using System.Text.RegularExpressions;
using System.Threading;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Linq;
namespace SvetoforVKBot.Models.Commands.Registration
{
public class SelectActivityCommand : Command
{
public override string Name => "{\"button\":\"selectActivity-";
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]");
SqlCommand editUser;
try
{
string[] payload = update.@object.message.payload.Split('-');
int stackId = Convert.ToInt32(regex.Replace(payload[1], ""));
// Тут надо дописать код, сейчас ссылка на несуществующий аттрибут в таблице
var user = db.Users.Single(usr => usr.chatId == chatId);
var userStack = new List<int>();// JsonConvert.DeserializeObject<List<int>>(rgetUserStack["activity"].ToString());
//SqlCommand getUserStack = new SqlCommand("SELECT activity FROM Users WHERE chatId = @chatId;", Con);
//getUserStack.Parameters.AddWithValue("@chatId", chatId);
//SqlDataReader rgetUserStack = getUserStack.ExecuteReader();
//rgetUserStack.Read();
//var userStack = JsonConvert.DeserializeObject<List<int>>(rgetUserStack["activity"].ToString());
//rgetUserStack.Close();
if (userStack.Contains(stackId))
{
userStack.Remove(stackId);
//SqlCommand editStack = new SqlCommand("UPDATE Users SET activity = @activity WHERE chatId = @chatId;", Con);
//editStack.Parameters.AddWithValue("@chatId", chatId);
//editStack.Parameters.AddWithValue("@activity", JsonConvert.SerializeObject(userStack));
//editStack.ExecuteNonQuery();
//ShowActivity showActivity = new ShowActivity();
//showActivity.Execute(update, client, Con);
}
else
{
userStack.Add(stackId);
//SqlCommand editStack = new SqlCommand("UPDATE Users SET activity = @activity WHERE chatId = @chatId;", Con);
//editStack.Parameters.AddWithValue("@chatId", chatId);
//editStack.Parameters.AddWithValue("@activity", JsonConvert.SerializeObject(userStack));
//editStack.ExecuteNonQuery();
//ShowActivity showActivity = new ShowActivity();
//showActivity.Execute(update, client, Con);
}
var activity = JsonConvert.SerializeObject(userStack);
//куда-то сохранить в user
db.SaveChanges();
}
catch (Exception ee)
{
@params.Message = "‼Ошибка в SelectActivity: " + ee.Message;
@params.Attachments = null;
@params.Keyboard = null;
@params.UserId = 59111081;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
}
public override void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
}
}
}