Добавьте файлы проекта.
This commit is contained in:
111
SvetoforVKBot/Models/Commands/Registration/SelectDayCommand.cs
Normal file
111
SvetoforVKBot/Models/Commands/Registration/SelectDayCommand.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
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 System.Linq;
|
||||
|
||||
namespace SvetoforVKBot.Models.Commands.Registration
|
||||
{
|
||||
public class SelectDayCommand : Command
|
||||
{
|
||||
public override string Name => "{\"button\":\"selectDay-";
|
||||
|
||||
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]");
|
||||
ShowSportDays showSportDays = new ShowSportDays();
|
||||
//int i = 1;
|
||||
try
|
||||
{
|
||||
string[] payload = update.@object.message.payload.Split('-');
|
||||
int day = Convert.ToInt32(regex.Replace(payload[1], ""));
|
||||
//int sportId = Convert.ToInt32(regex.Replace(payload[2], ""));
|
||||
|
||||
var user = db.Users.Single(usr => usr.chatId == chatId);
|
||||
List<int> sportDays = JsonConvert.DeserializeObject<List<int>>(user.sportDays);
|
||||
|
||||
if (day == 0)
|
||||
{
|
||||
if (sportDays.Count > 0)
|
||||
{
|
||||
if (user.reg == 0)
|
||||
{
|
||||
keyboardBuilder
|
||||
.AddButton("Раз в день", "selectNotifyCount-1", KeyboardButtonColor.Primary)
|
||||
.AddLine()
|
||||
.AddButton("Три раза в день", "selectNotifyCount-3", KeyboardButtonColor.Primary)
|
||||
.AddLine()
|
||||
.AddButton("Более 3х раз", "selectNotifyCount-4", KeyboardButtonColor.Primary)
|
||||
.AddLine()
|
||||
.AddButton("Никогда", "selectNotifyCount-0", KeyboardButtonColor.Default);
|
||||
|
||||
@params.Message = "Благодарим за регистрацию! Ваш личный кабинет сформирован.\n" +
|
||||
"Последний вопрос: как часто Вы готовы получать напоминания от чат-бота?\n\n" +
|
||||
"Вы будете получать уведомления о приёмах пищи и воды. Если Вы хотите сформировать привычку " +
|
||||
"по режиму питания или употреблению достаточного количества воды, выберите вариант \"Более 3х раз\".\n" +
|
||||
"Наш чат-бот не будет рассылать рекламу или спам. Только персональные уведомления и рекомендации по здоровому питанию.";
|
||||
@params.Keyboard = keyboardBuilder.Build();
|
||||
@params.UserId = chatId;
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
keyboardBuilder
|
||||
.AddButton("Личный кабинет", "startPL", KeyboardButtonColor.Positive);
|
||||
|
||||
@params.Message = "Супер! Продуктивной недели💪🏻";
|
||||
@params.Keyboard = keyboardBuilder.Build();
|
||||
@params.UserId = chatId;
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
showSportDays.Execute(update, client, db);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (sportDays.Contains(day))
|
||||
sportDays.Remove(day);
|
||||
else
|
||||
sportDays.Add(day);
|
||||
|
||||
user.sportDays = JsonConvert.SerializeObject(sportDays);
|
||||
db.SaveChanges();
|
||||
|
||||
|
||||
showSportDays.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user