public ActionResult Index() { const string defaultWelcomeMessage = "Welcome to your support!\nWe never leave you alone😊"; var settingRepo = new SettingRepo(BotInstanceId); var supporters = new SupporterRepo(BotInstanceId).GetAll(); var subscribers = Subscribers .GroupJoin(supporters, subscriber => subscriber.ChatId, supporter => supporter.ChatId, (subscriber, thisSupporters) => new SubscriberViewModel { ChatId = subscriber.ChatId, Username = subscriber.Username, FirstName = subscriber.FirstName, LastName = subscriber.LastName, IsSupporter = thisSupporters.Any() } ) .ToList(); return(View(new HomeViewModel { Subscribers = subscribers, WelcomeMessage = settingRepo.GetWelcomeMessage() ?? defaultWelcomeMessage })); }
public ActionResult Settings() { var settingRepo = new SettingRepo(BotInstanceId, Db); var model = settingRepo.Load <Setting>(); return(View(model)); }
public HomePage_VM GetHomage_VM() { HomePage_VM vm = new HomePage_VM(); Setting st = new Setting(); try { st = SettingRepo.GetList().First(); } catch (Exception ex) { } vm.setting = st; List <Cause> CauseList = CauseRepo.GetList(); vm.FeaturedCauses = CauseList.Where(x => x.Featured == 2).ToList(); vm.FrontCauses = CauseList.Where(x => x.Featured == 1).ToList(); vm.HelpOptions = HelpOptionRepo.GetList(); vm.HomePageVideo = HomePageVideoRepo.GetList(); vm.Missions = MissionRepo.GetList(); vm.WhyUsList = WhyUsRepo.GetList(); return(vm); }
public StoreBotInstance(ITelegramBotClient telegramClient, SettingRepo settingRepo, StoreAdminRepo storeAdminRepo, Db db, ILogger <StoreBotInstance> logger) { TelegramClient = telegramClient; SettingRepo = settingRepo; StoreAdminRepo = storeAdminRepo; Db = db; Logger = logger; }
public ActionResult SetWelcomeMessage(string welcomeMessage) { var settingRepo = new SettingRepo(BotInstanceId); settingRepo.SetWelcomeMessage(welcomeMessage); return(Redirect(Request.Headers["Referer"].ToString())); }
public UnitOfWork(MsContext context) { _context = context; BuyRepository = new Repository <Buy>(_context); Setting = new SettingRepo(_context); BuyDetailRepository = new Repository <BuyDetail>(_context); Categorie = new Repository <Categorie>(_context); User = new UserRepository(_context); Product = new ProductRepository(_context); }
public ActionResult Settings(Setting setting) { var settingRepo = new SettingRepo(BotInstanceId, Db); settingRepo.Save(setting); TempData["Message"] = "تنظیمات جدید با موفقیت ثبت شد"; return(RedirectToAction("Settings")); }
public AccountController() { this.UserRepo = new UserRepository(); this.SettingRepo = new SettingRepository(); try { this.st = SettingRepo.GetList().First(); ViewBag.Layout = this.st; } catch (Exception ex) { ViewBag.Layout = new Setting(); } }
public BaseController() { this.SettingRepo = new SettingRepository(); this.Context = GlobalHost.ConnectionManager.GetHubContext <Notification>(); try { this.st = SettingRepo.GetList().First(); ViewBag.Layout = this.st; } catch (Exception ex) { ViewBag.Layout = new Setting(); } }
public void Update(Update update, SubscriberRecord subscriberRecord) { if (update.Type == UpdateType.CallbackQuery) { HandleCallbackQuery(update); return; } if (update.Type != UpdateType.Message) { return; } var isAdmin = StoreAdminRepo.GetAdmin(subscriberRecord.ChatId) != null; switch (update.Message.Text) { case StateManager.Keyboards.StartCommand: TelegramClient.SendTextMessageAsync(subscriberRecord.ChatId, SettingRepo.Load <Setting>().WelcomeMessage, parseMode: ParseMode.Markdown, replyMarkup: isAdmin ? StateManager.Keyboards.StartAdmin : StateManager.Keyboards.StartUser); break; case StateManager.Keyboards.NewProductCommand: if (!isAdmin) { TelegramClient.SendTextMessageAsync(update.Message.Chat.Id, "متاسفانه مجوز اجرای این دستور را ندارید."); return; } if (!NewProductStates.TryGetValue(subscriberRecord.ChatId, out _)) { NewProductStates.Add(subscriberRecord.ChatId, null); } NewProductStates[subscriberRecord.ChatId] = new NewProductInState(); NewProductStates[subscriberRecord.ChatId].ProductRecord.BotInstanceRecordId = BotInstanceId; HandleNewProductMessage(update, subscriberRecord); break; case StateManager.Keyboards.ListProductsCommand: using (var db = Db) { var products = db.StoreProductRecords.Include(x => x.ImageFileRecords).AsNoTracking().Where(x => x.BotInstanceRecordId == BotInstanceId); if (!products.Any()) { TelegramClient.SendTextMessageAsync(subscriberRecord.ChatId, "محصولی برای نمایش وجود ندارد."); return; } var i = 0; var productDetailTemplate = SettingRepo.Load <Setting>().ProductDetailTemplate; foreach (var product in products) { var detail = productDetailTemplate .Replace("[Index]", (++i).ToString()) .Replace("[Name]", product.Name) .Replace("[Code]", product.Code) .Replace("[Price]", product.Price.ToCurrency()) .Replace("[Description]", product.Description); var buttons = new List <List <InlineKeyboardButton> > { new List <InlineKeyboardButton> { InlineKeyboardButton.WithCallbackData($"تصاویر ({product.ImageFileRecords.Count})", "images:" + product.Id) } }; if (isAdmin) { buttons.Add(GetAdminRow(product)); } Task.Delay(i * 500) .ContinueWith(task => { TelegramClient.SendPhotoAsync( subscriberRecord.ChatId, product.ImageFileRecords.First().ImageFileId, detail, parseMode: ParseMode.Markdown, replyMarkup: new InlineKeyboardMarkup(buttons)); }) .ContinueWith(task => { Logger.LogError("Delayed Message Exception: {Message}", task.Exception?.GetBaseException().Message); }, TaskContinuationOptions.OnlyOnFaulted); } } break; case StateManager.Keyboards.CancelCommand: if (NewProductStates.TryGetValue(subscriberRecord.ChatId, out _)) { NewProductStates.Remove(subscriberRecord.ChatId); } TelegramClient.SendTextMessageAsync(subscriberRecord.ChatId, "عملیات فعلی لغو شد", replyMarkup: StateManager.Keyboards.StartAdmin); break; default: if (NewProductStates.TryGetValue(subscriberRecord.ChatId, out _)) { if (!isAdmin) { TelegramClient.SendTextMessageAsync(update.Message.Chat.Id, "متاسفانه مجوز اجرای این دستور را ندارید."); return; } HandleNewProductMessage(update, subscriberRecord); } else { TelegramClient.SendTextMessageAsync(subscriberRecord.ChatId, "متوجه پیام نشدم.."); } break; } }