/// <summary> /// Создание бота (только телеграм) /// </summary> /// <param name="model"></param> /// <param name="masterId"></param> /// <returns></returns> public async Task <bool> CreateBotAsync(CreateBotViewModel model, Models.User user) { if (user.ConfirmEmail && user.BotCount < 3 && (await context.Bots.FirstOrDefaultAsync(b => b.Key == model.Key || b.Name == model.Name)) == null) { TelegramBot bot = new TelegramBot(model.Name, model.Key) { DateOfReg = DateTime.Now, LastActivity = DateTime.Now, MasterId = user.Id, IsActive = true, }; await bot.GetClient(); Bot bot_ = bot.TakeAsParent(); context.Bots.Add(bot_); user.BotCount++; await context.SaveChangesAsync(); bot.Id = bot_.Id; Directory.CreateDirectory(AppConfig.UsersPath + $"/{user.Id}/bots/{bot.Id}/functional"); bot.PhysicalPath = bot_.PhysicalPath = AppConfig.UsersPath + $"/{bot.MasterId}/bots/{bot_.Id}"; await bot_.SaveFunctionalAsync(new Functional() { BotId = bot.Id, CommandFunctions = bot.Functions }); await context.SaveChangesAsync(); return(true); } return(false); }
/// <summary> /// Вовзращает наследника с заполненными полями родителя (пока только телеграм) /// </summary> /// <param name="bot"></param> /// <returns></returns> private async Task <TelegramBot> TakeAsBotActivity(Bot bot) { TelegramBot b = new TelegramBot(bot.Name, bot.Key) { Id = bot.Id, DateOfReg = bot.DateOfReg, IsActive = bot.IsActive, Key = bot.Key, LastActivity = bot.LastActivity, MasterId = bot.MasterId, Name = bot.Name, Url = bot.Url }; await b.GetClient(); return(b); }