public static async void AddVacancу(TelegramBotClient botClient, Message message, TelegramContext db) { try { var vacancу = new Vacancу() { User = db.Users.Where(x => x.Id == (int)message.Chat.Id).SingleOrDefault(), CreatedOn = DateTime.UtcNow, IsCreationFinished = false }; var userStare = db.UserStates.Where(x => x.User.Id == vacancу.User.Id).SingleOrDefault(); userStare.Vacancy = vacancу; db.Vacancies.Add(vacancу); db.UserStates.Update(userStare); db.SaveChanges(); StateManager.StateUpdate(message.Chat.Id, (int)UserStatesEnum.AddHeader); var messageText = $"Введите название проекта/задачи/должности\n\nПример: Разработка сайта, Менеджер по продажам"; await SendMessage(botClient, message, messageText); } catch (Exception ex) { SendErrorMessage(ex, botClient, message); } }
public static async void AddHeader(TelegramBotClient botClient, Message message, TelegramContext db) { try { var userState = db.UserStates.Include(x => x.User).Where(x => x.User.Id == message.Chat.Id).Include(x => x.Vacancy).SingleOrDefault(); userState.Vacancy.Header = message.Text; db.UserStates.Update(userState); db.SaveChanges(); var keyboard = new InlineKeyboardMarkup( new InlineKeyboardButton[] { new InlineKeyboardButton { Text = "Подтвердить", CallbackData = "AddDescription" }, new InlineKeyboardButton { Text = "Изменить", CallbackData = "AddHeader" } } ); var messageText = $"<b>{userState.Vacancy.Header}</b>\n\nПодтвердите введённый заголовок или измените его."; await SendMessage(botClient, message, messageText, keyboard); } catch (Exception ex) { SendErrorMessage(ex, botClient, message); } }
public static async void AddDescription(TelegramBotClient botClient, Message message, TelegramContext db) { try { var userState = db.UserStates.Include(x => x.User).Where(x => x.User.Id == message.Chat.Id).Include(x => x.Vacancy).SingleOrDefault(); userState.Vacancy.Description = message.Text; db.UserStates.Update(userState); db.SaveChanges(); var keyboard = new InlineKeyboardMarkup( new InlineKeyboardButton[] { new InlineKeyboardButton { Text = "Подтвердить", CallbackData = "AddResponsibilities" }, new InlineKeyboardButton { Text = "Изменить", CallbackData = "AddDescription" } } ); var description = string.IsNullOrWhiteSpace(userState.Vacancy.Description) ? "" : $"{userState.Vacancy.Description}\n\n"; var messageText = $"<b>{userState.Vacancy.Header}</b>\n\n" + $"{description}" + $"Подтвердите описание вашей компании или измените его."; await SendMessage(botClient, message, messageText, keyboard); } catch (Exception ex) { SendErrorMessage(ex, botClient, message); } }
public override async Task ExecuteAsync(Message message, TelegramBotClient botClient) { var chatId = message.Chat.Id; using (TelegramContext db = new TelegramContext()) { var User = db.Users.Where(p => p.UserId == message.From.Id).SingleOrDefault(); if (User == null) { ObjectsModels.User user = new ObjectsModels.User { UserId = message.From.Id, Name = message.From.Username }; ObjectsModels.UserState US = new ObjectsModels.UserState { UserId = message.From.Id, State = (int)UserStatesEnum.Empty }; db.Users.Add(user); db.UserStates.Add(US); db.SaveChanges(); BuildingsManager.MainMenu(user, db, message, botClient); } else { BuildingsManager.MainMenu(User, db, message, botClient); } } }
public override async Task ExecuteAsync(Message message, TelegramBotClient botClient) { var chatId = (int)message.Chat.Id; using (TelegramContext db = new TelegramContext()) { var User = db.Users.Where(p => p.Id == message.From.Id).SingleOrDefault(); if (User == null) { User user = new User { Id = chatId, Name = message.From.Username }; UserState us = new UserState { User = user, State = (int)UserStatesEnum.Empty, LastMessageId = message.MessageId }; db.Users.Add(user); db.UserStates.Add(us); db.SaveChanges(); UserLocker.AddUser(chatId); UserLocker.LockUser(chatId); } VacanciesManager.MainMenu(message, botClient); } }
public static void StateUpdate(long userId, int state) { using (TelegramContext db = new TelegramContext()) { var userState = db.UserStates.Where(x => x.User.Id == userId).SingleOrDefault(); userState.State = state; db.UserStates.Update(userState); db.SaveChanges(); } }
private static async void AddResponsibilitiesCallback(TelegramBotClient botClient, Message message, TelegramContext db) { var userState = db.UserStates.Include(x => x.User).Where(x => x.User.Id == message.Chat.Id).Include(x => x.Vacancy).SingleOrDefault(); userState.Vacancy.Responsibilities = ""; db.UserStates.Update(userState); db.SaveChanges(); StateManager.StateUpdate(message.Chat.Id, (int)UserStatesEnum.AddResponsibilities); var messageText = $"Введите список обязаностей соискателя (меню \"Что нужно делать\"). Каждый пункт отправляйте отдельным сообщением."; await VacanciesManager.SendMessage(botClient, message, messageText); }
public static async void SaveVacancу(TelegramBotClient botClient, Message message, TelegramContext db) { try { var userState = db.UserStates.Include(x => x.User).Where(x => x.User.Id == message.Chat.Id).Include(x => x.Vacancy).SingleOrDefault(); userState.Vacancy.IsCreationFinished = true; var description = string.IsNullOrWhiteSpace(userState.Vacancy.Description) ? "" : $"{userState.Vacancy.Description}\n\n"; var requirements = string.IsNullOrWhiteSpace(userState.Vacancy.Requirements) ? "" : $"<b>Требования:</b>\n{userState.Vacancy.Requirements}\n"; var offered = string.IsNullOrWhiteSpace(userState.Vacancy.Offered) ? "" : $"<b>Что предлагаем</b>:\n{userState.Vacancy.Offered}\n"; var additionalComment = string.IsNullOrWhiteSpace(userState.Vacancy.AdditionalComment) ? "" : $"{userState.Vacancy.AdditionalComment}\n\n"; var vacancyText = $"<b>{userState.Vacancy.Header}</b>\n\n" + $"{description}" + $"<b>Что делать:</b>\n{userState.Vacancy.Responsibilities}\n" + $"{requirements}" + $"{offered}" + $"<b>Оплата:</b>\n{userState.Vacancy.PaymentOffers}\n\n" + $"{additionalComment}" + $"<b>Контакты:</b>\n{userState.Vacancy.Contacts}\n"; userState.Vacancy.Text = vacancyText; db.UserStates.Update(userState); db.SaveChanges(); var keyboard = new InlineKeyboardMarkup( new InlineKeyboardButton[] { new InlineKeyboardButton { Text = "Главное меню", CallbackData = "MainMenu" } } ); var messageText = $"Вакансия №{userState.Vacancy.Id} создана! \n\nДля оплаты и выбора даты свяжитесь с нами и укажите номер вакансии: @VLADvesna."; await SendMessage(botClient, message, messageText, keyboard); var username = message.Chat.Username; var adminMessage = string.IsNullOrEmpty(message.Chat.Username) ? $"Вакансия №{userState.Vacancy.Id} \n\n{userState.Vacancy.Text}" : $"Вакансия №{userState.Vacancy.Id} от @{message.Chat.Username} \n\n{userState.Vacancy.Text}";//@{message.Chat.Username} await botClient.SendTextMessageAsync("481884934", adminMessage, Telegram.Bot.Types.Enums.ParseMode.Html, false, false, 0, replyMarkup : null); StateManager.StateUpdate(message.Chat.Id, (int)UserStatesEnum.Empty); } catch (Exception ex) { SendErrorMessage(ex, botClient, message); } }
private static async void AddContactsCallback(TelegramBotClient botClient, Message message, TelegramContext db) { var userState = db.UserStates.Include(x => x.User).Where(x => x.User.Id == message.Chat.Id).Include(x => x.Vacancy).SingleOrDefault(); userState.Vacancy.Contacts = ""; db.UserStates.Update(userState); db.SaveChanges(); StateManager.StateUpdate(message.Chat.Id, (int)UserStatesEnum.AddContacts); var messageText = $"Введите ваши контакты (меню \"Контакты\"). Каждый пункт отправляйте отдельным сообщением."; await VacanciesManager.SendMessage(botClient, message, messageText); }
public static void StateUpdate(long userId, int state, int?buildingId = null) { using (TelegramContext db = new TelegramContext()) { var userState = db.UserStates.Where(x => x.UserId == userId).SingleOrDefault(); userState.State = state; if (buildingId != null) { userState.BuildingId = (int)buildingId; } db.UserStates.Update(userState); db.SaveChanges(); } }
public static async void AddBuildingAddress(TelegramBotClient botClient, TelegramContext db, Message message, UserState userState) { try { var building = db.Buildings.Where(x => x.Id == userState.BuildingId).SingleOrDefault(); building.Address = message.Text; db.Buildings.Update(building); db.SaveChanges(); StateManager.StateUpdate(message.Chat.Id, (int)UserStatesEnum.AddBuildingComment); await botClient.SendTextMessageAsync(message.Chat.Id, "Введи коментар до будівлі", Telegram.Bot.Types.Enums.ParseMode.Default, false, false, 0); } catch (Exception ex) { await botClient.SendTextMessageAsync(message.Chat.Id, "Ошибка: " + ex.Message, Telegram.Bot.Types.Enums.ParseMode.Default); } }
public static async void AddBuildingComment(TelegramBotClient botClient, TelegramContext db, Message message, UserState userState) { try { var building = db.Buildings.Where(x => x.Id == userState.BuildingId).SingleOrDefault(); building.Comment = message.Text; db.Buildings.Update(building); db.SaveChanges(); StateManager.StateUpdate(message.Chat.Id, (int)UserStatesEnum.AddBuildingPhoto); await botClient.SendTextMessageAsync(message.Chat.Id, "Надсилай фото будівлі, а коли закінчиш напиши команду /save щоб зберегти пост!", Telegram.Bot.Types.Enums.ParseMode.Default, false, false, 0); } catch (Exception ex) { await botClient.SendTextMessageAsync(message.Chat.Id, "Ошибка: " + ex.Message, Telegram.Bot.Types.Enums.ParseMode.Default); } }
public static async void AddContacts(TelegramBotClient botClient, Message message, TelegramContext db) { try { var userState = db.UserStates.Include(x => x.User).Where(x => x.User.Id == message.Chat.Id).Include(x => x.Vacancy).SingleOrDefault(); userState.Vacancy.Contacts += $"{message.Text}\n"; db.UserStates.Update(userState); db.SaveChanges(); var keyboard = new InlineKeyboardMarkup( new InlineKeyboardButton[] { new InlineKeyboardButton { Text = "Следующий шаг", CallbackData = "ConfirmVacancу" }, new InlineKeyboardButton { Text = "Заново", CallbackData = "AddContacts" } } ); var description = string.IsNullOrWhiteSpace(userState.Vacancy.Description) ? "" : $"{userState.Vacancy.Description}\n\n"; var requirements = string.IsNullOrWhiteSpace(userState.Vacancy.Requirements) ? "" : $"<b>Требования:</b>\n{userState.Vacancy.Requirements}\n"; var offered = string.IsNullOrWhiteSpace(userState.Vacancy.Offered) ? "" : $"<b>Что предлагаем</b>:\n{userState.Vacancy.Offered}\n"; var additionalComment = string.IsNullOrWhiteSpace(userState.Vacancy.AdditionalComment) ? "" : $"{userState.Vacancy.AdditionalComment}\n\n"; var messageText = $"<b>{userState.Vacancy.Header}</b>\n\n" + $"{description}" + $"<b>Что делать:</b>\n{userState.Vacancy.Responsibilities}\n" + $"{requirements}" + $"{offered}" + $"<b>Оплата:</b>\n{userState.Vacancy.PaymentOffers}\n\n" + $"{additionalComment}" + $"<b>Контакты:</b>\n{userState.Vacancy.Contacts}\n" + $"Что бы добавить ещё один пункт в \"Контакты\" отправте его новым сообщением.\n" + $"Что бы перейти к следующему шагу нажмите соответствующую кнопку.\n" + $"Что бы заполнить пункты \"Контакты\" заново нажмите кнопку \"Заново\""; await SendMessage(botClient, message, messageText, keyboard); } catch (Exception ex) { SendErrorMessage(ex, botClient, message); } }
public static async void AddBuildingName(TelegramBotClient botClient, TelegramContext db, Message message) { try { var building = new Building() { Name = message.Text, ParrentUserId = db.Users.Where(x => x.UserId == message.Chat.Id).Select(x => x.Id).SingleOrDefault() }; db.Buildings.Add(building); db.SaveChanges(); StateManager.StateUpdate(message.Chat.Id, (int)UserStatesEnum.AddBuildingAddress, building.Id); await botClient.SendTextMessageAsync(message.Chat.Id, "Введи адресу будівлі", Telegram.Bot.Types.Enums.ParseMode.Default, false, false, 0); } catch (Exception ex) { await botClient.SendTextMessageAsync(message.Chat.Id, "Ошибка: " + ex.Message, Telegram.Bot.Types.Enums.ParseMode.Default); } }
public static async void AddAdditionalComment(TelegramBotClient botClient, Message message, TelegramContext db) { try { var userState = db.UserStates.Include(x => x.User).Where(x => x.User.Id == message.Chat.Id).Include(x => x.Vacancy).SingleOrDefault(); userState.Vacancy.AdditionalComment = message.Text; db.UserStates.Update(userState); db.SaveChanges(); var keyboard = new InlineKeyboardMarkup( new InlineKeyboardButton[] { new InlineKeyboardButton { Text = "Подтвердить", CallbackData = "AddContacts" }, new InlineKeyboardButton { Text = "Изменить", CallbackData = "AddAdditionalComment" } } ); var description = string.IsNullOrWhiteSpace(userState.Vacancy.Description) ? "" : $"{userState.Vacancy.Description}\n\n"; var requirements = string.IsNullOrWhiteSpace(userState.Vacancy.Requirements) ? "" : $"<b>Требования:</b>\n{userState.Vacancy.Requirements}\n"; var offered = string.IsNullOrWhiteSpace(userState.Vacancy.Offered) ? "" : $"<b>Что предлагаем</b>:\n{userState.Vacancy.Offered}\n"; var additionalComment = string.IsNullOrWhiteSpace(userState.Vacancy.AdditionalComment) ? "" : $"{userState.Vacancy.AdditionalComment}\n\n"; var messageText = $"<b>{userState.Vacancy.Header}</b>\n\n" + $"{description}" + $"<b>Что делать:</b>\n{userState.Vacancy.Responsibilities}\n" + $"{requirements}" + $"{offered}" + $"<b>Оплата:</b>\n{userState.Vacancy.PaymentOffers}\n\n" + $"{additionalComment}" + $"Подтвердите дополнительный комментраий или измените его."; await SendMessage(botClient, message, messageText, keyboard); } catch (Exception ex) { SendErrorMessage(ex, botClient, message); } }
public static async void RemoveLastMessage(Telegram.Bot.TelegramBotClient botClient, int chatId) { using (TelegramContext db = new TelegramContext()) { try { var userState = db.UserStates.Where(x => x.User.Id == chatId).SingleOrDefault(); if (userState != null && userState.LastMessageId != null) { await botClient.DeleteMessageAsync(chatId, (int)userState.LastMessageId); userState.LastMessageId = null; db.UserStates.Update(userState); db.SaveChanges(); } } catch { } } }
private static async void AddOfferedCallback(TelegramBotClient botClient, Message message, TelegramContext db) { var userState = db.UserStates.Include(x => x.User).Where(x => x.User.Id == message.Chat.Id).Include(x => x.Vacancy).SingleOrDefault(); userState.Vacancy.Offered = ""; db.UserStates.Update(userState); db.SaveChanges(); var keyboard = new InlineKeyboardMarkup( new InlineKeyboardButton[] { new InlineKeyboardButton { Text = "Пропустить", CallbackData = "AddPaymentOffers" } } ); StateManager.StateUpdate(message.Chat.Id, (int)UserStatesEnum.AddOffered); var messageText = $"Введите список того, что вы предлагаете соискателю, кроме заработной платы, (меню \"Что предлагаем\"). Каждый пункт отправляйте отдельным сообщением." + $"\nЕсли хотите пропустить этот шаг нажмите кнопку \"Пропустить\"."; await VacanciesManager.SendMessage(botClient, message, messageText, keyboard); }
public void SaveChanges() { Context.SaveChanges(); }
internal void RemoveAccount(User user) { _context.Accounts.Remove(user); _context.SaveChanges(); }