示例#1
0
        public string About()
        {
            //List<string> tokens = new List<string>();
            //tokens.Add("513919028:AAH3YpNoZAeZwo5NItLEmIXUhobfR5ziSRU");
            //tokens.Add("523703359:AAHGsDDzW7ZS0iQXWsJ_g8X7DeldpFVy4qQ");
            ////SetWebHook("501412002:AAGLeNPhy3icrSfs4WbY0QhIRMwLULbmqDo");
            ////SetWebHook("523703359:AAHGsDDzW7ZS0iQXWsJ_g8X7DeldpFVy4qQ");
            //for (int i = 0; i < tokens.Count; i++)
            //{
            //    SetWebHook(tokens[i], i);
            //}
            string k = "1";

            using (botEntities2 bd = new botEntities2())
            {
                //Token a = new Token();
                //    a.token1 = "513919028:AAH3YpNoZAeZwo5NItLEmIXUhobfR5ziSRU";
                //    a.id = 1;
                //    bd.Token.Add(a);
                //    SetWebHook(a.token1, a.id);
                //    Token b = new Token();
                //     b.token1 = "523703359:AAHGsDDzW7ZS0iQXWsJ_g8X7DeldpFVy4qQ";
                //    bd.Token.Add(b);
                //    SetWebHook(b.token1, b.id);
                //    k = "12";

                //bd.SaveChanges();
                Token m = bd.Token.Where(x => x.Id == 1).First();
                SetWebHook(m.token1, m.Id);
                Token m2 = bd.Token.Where(x => x.Id == 3).First();
                SetWebHook(m2.token1, m2.Id);
            }
            return("Сработало" + k);
        }
示例#2
0
        string ReceiveToken(Update update, int?id)
        {
            string token;

            using (botEntities2 bot = new botEntities2())
                token = bot.Token.Where(x => x.Id == id).First().token1;
            return(token);
        }
示例#3
0
 public TelegramRecycle(Update update, int?id)
 {
     this.username = update.callback_query.from.id.ToString();
     TokenIds      = (int)id;
     using (botEntities2 bd = new botEntities2())
     {
         rec   = bd.Recycle.Where(x => x.UserName == username).Where(x => x.Id == id).ToList();
         Count = rec.Count;
     }
 }
示例#4
0
        public void AddBuy(string NameCategorys, string NameProducts)
        {
            using (botEntities2 bd = new botEntities2())
            {
                bd.Recycle.Add(new Recycle()
                {
                    NameCategory = NameCategorys,
                    NameProduct  = NameProducts,
                    TokenId      = TokenIds,
                    UserName     = username
                }

                               );
                bd.SaveChanges();
            }
        }
示例#5
0
        string MainMenu(Update update, int?id, out string reply_markup)
        {
            List <Category> list;
            string          token = "";
            int             i     = 0;

            using (botEntities2 bd = new botEntities2())
            {
                list  = bd.Category.Where(x => x.Token.Id == id).ToList();
                token = bd.Token.Where(x => x.Id == id).First().token1;
            }
            InlineKeyboard keyboard = new InlineKeyboard();

            foreach (Category k in list)
            {
                keyboard.AddButton(new InlineKeyboardButton(
                                       k.NameCategory
                                       ), i++ / 2);
            }
            AddMainButtons(keyboard);
            reply_markup = JsonConvert.SerializeObject(keyboard);
            return("Все категории");
        }
示例#6
0
        string Shop(string category, string nameProduct, Update update, int?id, out string reply_markup)
        {
            //string category = shop.Split(' ')[0];
            //string nameProduct = shop.Split(' ').Length < 2 ? "" : shop.Split(' ')[1];
            string answer = "Привет";

            reply_markup = "";
            List <Category> cat = null;
            List <Product>  p   = null;

            // SendMessage(update.callback_query.from.id, category , ReceiveToken(update, id));
            using (botEntities2 bd = new botEntities2())
            {
                try
                {
                    cat = bd.Category.Where(x => x.Token.Id == id).ToList();
                    p   = cat.Where(x => x.NameCategory == category).First().Product.ToList();
                    if (nameProduct == "")
                    {
                        nameProduct = p[0].ProductName;
                    }
                }
                catch
                {
                    //   SendMessage(update.callback_query.from.id, "БД УПало", ReceiveToken(update, id));
                }
            }

            //try
            //{
            //    SendMessage(update.callback_query.from.id, p.Count.ToString(), ReceiveToken(update, id));
            //}
            //catch
            //{
            //    SendMessage(update.callback_query.from.id, "равно 0", ReceiveToken(update, id));
            //}
            //list = cat.Where(x => x.NameCategory == category).First();
            //if (list == null)
            //{
            //    SendMessage(update.callback_query.from.id, "null", ReceiveToken(update, id));
            //}
            //else SendMessage(update.callback_query.from.id, list.Product.Count.ToString(), ReceiveToken(update, id));
            InlineKeyboard keyboard = new InlineKeyboard();
            int            i        = 0;

            foreach (Product k in p)
            {
                if (nameProduct == k.ProductName)
                {
                    continue;
                }
                keyboard.AddButton(new InlineKeyboardButton(

                                       k.ProductName, k.Category.NameCategory + " " + k.ProductName), i++ / 2);
            }
            AddRecycle(keyboard, category, nameProduct);
            Product chooseProduct = p.Where(x => x.ProductName == nameProduct).First();

            answer += chooseProduct.ProductPrice + Environment.NewLine + "  " + " " + chooseProduct.ProductDescription;
            keyboard.AddButton(new InlineKeyboardButton("Назад", "about"));
            AddMainButtons(keyboard);
            reply_markup = JsonConvert.SerializeObject(keyboard);
            return(answer);
        }