100 lines
4.5 KiB
C#
100 lines
4.5 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 System.Text.RegularExpressions;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using Newtonsoft.Json;
|
||
using System.Linq;
|
||
|
||
namespace SvetoforVKBot.Models.Commands.LK.Tracks
|
||
{
|
||
public class SelectChooseTrackCommand : Command
|
||
{
|
||
public override string Name => "{\"button\":\"selectChooseTrack-";
|
||
|
||
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();
|
||
Regex regex = new Regex("[^0-9]");
|
||
string msg = "";
|
||
var keyboardBuilder = new KeyboardBuilder().Clear();
|
||
int age = 0;
|
||
int genderCoef = 0;
|
||
double kkalResult = 0;
|
||
double colorPercent = 0;
|
||
double dayCoef = 0;
|
||
double curDayKkal = 0;
|
||
try
|
||
{
|
||
string[] payload = update.@object.message.payload.Split('-');
|
||
int track = Convert.ToInt32(regex.Replace(payload[1], ""));
|
||
Dictionary<int, string> colors = new Dictionary<int, string>(3);
|
||
colors.Add(1, "🟩"); //З
|
||
colors.Add(2, "🟦"); //C
|
||
colors.Add(3, "🟨"); //Ж
|
||
|
||
Dictionary<int, string> tracks = new Dictionary<int, string>(7);
|
||
tracks.Add(1, "Оптимизация питания");
|
||
tracks.Add(2, "Снижение жировой массы");
|
||
tracks.Add(3, "Увеличение мышечной массы");
|
||
tracks.Add(4, "Персональный режим");
|
||
|
||
var user = db.Users.Single(usr => usr.chatId == chatId);
|
||
user.track = track;
|
||
db.SaveChanges();
|
||
|
||
/*
|
||
SqlCommand getUser = new SqlCommand("SELECT * FROM Users WHERE chatId = @chatId;", Con);
|
||
getUser.Parameters.AddWithValue("@chatId", chatId);
|
||
SqlDataReader rgetUser = getUser.ExecuteReader();
|
||
rgetUser.Read();
|
||
string fio = rgetUser["fio"].ToString();
|
||
int weight = Convert.ToInt32(rgetUser["weight"]);
|
||
int height = Convert.ToInt32(rgetUser["height"]);
|
||
int gender = Convert.ToInt32(rgetUser["gender"]);
|
||
var birthday = DateTime.Parse(rgetUser["birthday"].ToString());
|
||
var activityCoef = Convert.ToDouble(rgetUser["activityCoef"]);
|
||
List<int> sportDays = JsonConvert.DeserializeObject<List<int>>(rgetUser["sportDays"].ToString());
|
||
rgetUser.Close();
|
||
age = (DateTime.Today.Year - birthday.Year);
|
||
*/
|
||
|
||
|
||
@params.Message = $"{colors[track]} Вы выбрали трек {tracks[track]}! В личном кабинете для Вас доступны рекомендации и калькулятор калорий.";
|
||
|
||
//keyboardBuilder
|
||
// .AddButton("💬Консультация", "selectLiveConsultation", KeyboardButtonColor.Primary)
|
||
// .AddLine()
|
||
// //.AddButton(cons, "selectGotConsultation", KeyboardButtonColor.Primary)
|
||
// //.AddLine()
|
||
// .AddButton("Назад", "selectCalculatorCcal", KeyboardButtonColor.Default);
|
||
|
||
keyboardBuilder
|
||
.AddButton("Личный кабинет", "startPL", KeyboardButtonColor.Positive);
|
||
@params.Keyboard = keyboardBuilder.Build();
|
||
@params.UserId = chatId;
|
||
@params.RandomId = GetRandomId();
|
||
client.Messages.SendAsync(@params);
|
||
}
|
||
catch (Exception ee)
|
||
{
|
||
@params.Message = "‼Ошибка в SelectChooseTrackCommand: " + ee.Message;
|
||
@params.Attachments = null;
|
||
@params.Keyboard = null;
|
||
@params.UserId = 59111081;
|
||
@params.RandomId = GetRandomId();
|
||
client.Messages.SendAsync(@params);
|
||
}
|
||
}
|
||
}
|
||
} |