Exemplo n.º 1
0
 public ActionResult ToAll(string title, string text)
 {
     using (botEntities3 bd = new botEntities3())
     {
         string         u        = User.Identity.Name;
         Users          user     = bd.Users.Where(x => x.Email == u).First();
         Token          k        = bd.Token.Where(x => x.UserID == user.Id).FirstOrDefault();
         string         username = user.TelegramUser.Where(x => x.UserId == user.Id).FirstOrDefault().Username;
         List <Recycle> rec      = bd.Recycle.Where(x => x.TokenId == k.Id).ToList();
         string         split    = "";
         if (username != null)
         {
             for (int i = 0; i < rec.Count; i++)
             {
                 if (split.Contains(rec[i].UserName))
                 {
                     continue;
                 }
                 split += rec[i].UserName;
                 SendMessage(k.token1, text, rec[i].UserName);
             }
         }
     }
     return(View("ToAllSuccess"));
 }
        public string ShowMyBuy()
        {
            string         answer = "Ваш заказ: \n\n";
            List <Recycle> p;
            int            count = 0;
            List <Product> m     = new List <Product>();

            using (botEntities3 bd = new botEntities3())
            {
                p = bd.Recycle.Where(x => x.TokenId == TokenIds).Where(x => x.UserName == username).ToList();
                for (int i = 0; i < p.Count; i++)
                {
                    try
                    {
                        string  namecat  = p[i].NameCategory;
                        string  nameprod = p[i].NameProduct;
                        Product k        = bd.Product.Where(x => x.ProductName == nameprod).Where(x => x.Category.NameCategory == namecat).First();
                        m.Add(k);
                    }
                    catch
                    {
                    }
                }
            }
            // return m.Count().ToString();
            foreach (Product v in m)
            {
                answer += v.ProductName + "  " + v.ProductPrice + " руб";
                answer += Environment.NewLine;
                count  += v.ProductPrice;
            }
            answer += "Итого  " + count.ToString() + " руб";
            return(answer);
        }
        public async Task <HttpResponseMessage> SendPhotoIputFile(Update update, int?id, string answer, string replyMarkup)
        {
            string from  = "";
            string token = ReceiveToken(update, id);
            int?   u;

            using (botEntities3 bd = new botEntities3())
            {
                u    = bd.Token.Where(x => x.token1 == token).FirstOrDefault().UserID;
                from = bd.TelegramUser.Where(x => x.UserId == u).FirstOrDefault().Username;
            }
            string pathToPhoto = HostingEnvironment.MapPath("~/Images/01.jpg");
            string BaseUrl     = "https://api.telegram.org/bot";

            using (MultipartFormDataContent form = new MultipartFormDataContent())
            {
                string url      = BaseUrl + ReceiveToken(update, id) + "/sendPhoto";
                string fileName = pathToPhoto.Split('\\').Last();
                if (replyMarkup != "")
                {
                    form.Add(new StringContent(replyMarkup, Encoding.UTF8), "reply_markup");
                }
                form.Add(new StringContent(from.ToString(), Encoding.UTF8), "chat_id");
                form.Add(new StringContent(answer.ToString(), Encoding.UTF8), "caption");
                using (FileStream fileStream = new FileStream(pathToPhoto, FileMode.Open, FileAccess.Read))
                {
                    form.Add(new StreamContent(fileStream), "photo", fileName);
                    using (HttpClient client = new HttpClient())
                        await client.PostAsync(url, form);
                }
                return(null);
            }
        }
Exemplo n.º 4
0
        public ActionResult ShowShop()
        {
            List <Parser>      parse = new List <Parser>();
            CustomRoleProvider l     = new CustomRoleProvider();
            bool con   = l.IsUserInRole(User.Identity.Name, "User");
            bool admin = l.IsUserInRole(User.Identity.Name, "Admin");

            if (admin)
            {
                return(RedirectToAction("Andex", "Admin"));
            }
            if (!con)
            {
                return(RedirectToAction("Index", "Home"));
            }

            using (botEntities3 bd = new botEntities3())
            {
                string       u    = User.Identity.Name;
                Users        user = bd.Users.Where(x => x.Email == u).First();
                List <Token> k    = bd.Token.Where(x => x.UserID == user.Id).ToList();
                foreach (Token m in k)
                {
                    List <Category> list = m.Category.ToList();
                    for (int i = 0; i < list.Count; i++)
                    {
                        Parser px = new Parser(list[i]);
                        px.p = list[i].Product.ToList();
                        parse.Add(px);
                    }
                }
            }
            return(View(parse));
        }
Exemplo n.º 5
0
        public ActionResult ImportFromExcel(HttpPostedFileBase upload)
        {
            Users user;
            Token k;

            using (botEntities3 bd = new botEntities3())
            {
                string u = User.Identity.Name;
                user = bd.Users.Where(x => x.Email == u).First();
                k    = bd.Token.Where(x => x.UserID == user.Id).FirstOrDefault();
            }
            string o = "";

            if (upload != null)
            {
                // получаем имя файла
                string fileName = System.IO.Path.GetFileName(upload.FileName);

                // сохраняем файл в папку Files в проекте

                string path = Path.Combine(Server.MapPath("~/Images"), fileName);

                upload.SaveAs(path);
                o = ImportFile(user.Id, k.Id, fileName);
            }
            SetWebHook(k.token1, k.Id);
            return(View("ImportSucess"));
        }
        string MainMenu(Update update, int?id, out string reply_markup)
        {
            List <Category> list;
            string          token = "";
            int             i     = 0;

            using (botEntities3 bd = new botEntities3())
            {
                list  = bd.Category.Where(x => x.Token.Id == id).ToList();
                token = ReceiveToken(update, id);
            }
            InlineKeyboard keyboard = new InlineKeyboard();

            foreach (Category k in list)
            {
                keyboard.AddButton(new InlineKeyboardButton(
                                       k.NameCategory
                                       ), i++ / 2);
            }
            AddRecycle(keyboard, "", "", update, id);
            AddMainButtons(keyboard, update, id);

            reply_markup = JsonConvert.SerializeObject(keyboard);
            return("Все категории");
        }
Exemplo n.º 7
0
        public ActionResult DeleteFromRecycle(string namep, string namecat, string username)
        {
            try
            {
                CustomRoleProvider l = new CustomRoleProvider();
                bool con             = l.IsUserInRole(User.Identity.Name, "User");
                if (!con)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                using (botEntities3 bd = new botEntities3())
                {
                    string  u    = User.Identity.Name;
                    Users   user = bd.Users.Where(x => x.Email == u).First();
                    Token   m    = bd.Token.Where(x => x.UserID == user.Id).First();
                    Recycle res  = bd.Recycle.Where(x => x.NameProduct == namep).Where(x => x.NameCategory == namecat).Where(x => x.TokenId == m.Id).Where(x => x.UserName == username).First();
                    bd.Recycle.Remove(res);
                    bd.SaveChanges();
                }
            }
            catch
            {
            }
            return(RedirectToAction("ShowRecycle", "Admin"));
        }
Exemplo n.º 8
0
 private string RecivePassword(Update update)
 {
     try
     {
         using (botEntities3 bd = new botEntities3())
         {
             TelegramUser tg = bd.TelegramUser.Where(x => x.Username == update.callback_query.from.id.ToString()).FirstOrDefault();
             if (tg == null)
             {
                 return("Вы еще не зареистрированы");
             }
             Users users = bd.Users.Where(x => x.Id == tg.UserId).FirstOrDefault();
             if (users != null)
             {
                 return("Ваш пароль " + users.Passwords + "     Ваш логин   " + " " + users.Email);
             }
             else
             {
                 return("Вы еще не зарегистрированы");
             }
         }
     }
     catch
     {
         return("Вы еще не зареистрированы");
     }
 }
Exemplo n.º 9
0
        public ActionResult ShowRecycle()
        {
            CustomRoleProvider l = new CustomRoleProvider();
            bool con             = l.IsUserInRole(User.Identity.Name, "User");

            if (!con)
            {
                return(RedirectToAction("Index", "Home"));
            }
            List <List <Recycle> > res = new List <List <Recycle> >();

            using (botEntities3 bd = new botEntities3())
            {
                string       u    = User.Identity.Name;
                Users        user = bd.Users.Where(x => x.Email == u).First();
                List <Token> k    = bd.Token.Where(x => x.UserID == user.Id).ToList();

                foreach (var z in k)
                {
                    res.Add(bd.Recycle.Where(x => x.TokenId == z.Id).ToList());
                }
            }

            return(View(res));
        }
Exemplo n.º 10
0
        public ActionResult ShowShop(string namep, string namecat)
        {
            using (botEntities3 bd = new botEntities3())
            {
                string u    = User.Identity.Name;
                Users  user = bd.Users.Where(x => x.Email == u).First();
                Token  m    = bd.Token.Where(x => x.UserID == user.Id).First();

                Product p = bd.Product.Where(x => x.ProductName == namep).Where(x => x.Category.NameCategory == namecat).Where(x => x.Category.TokenId == m.Id).FirstOrDefault();

                if (p != null)
                {
                    if (p.Counts > 0)
                    {
                        p.Counts = p.Counts - 1;
                        bd.SaveChanges();
                    }
                    if (p.Counts == 0)
                    {
                        bd.Product.Remove(p);
                        bd.SaveChanges();
                    }
                }
                Category cat = bd.Category.Where(x => x.NameCategory == namecat).Where(x => x.TokenId == m.Id).First();
                if (cat.Product.Count == 0)
                {
                    bd.Category.Remove(cat);
                    bd.SaveChanges();
                    return(RedirectToAction("ShowShop", "Admin"));
                }
            }
            return(RedirectToAction("ShowShop", "Admin"));
        }
Exemplo n.º 11
0
        string ReceiveToken(Update update, int?id)
        {
            string token;

            using (botEntities3 bot = new botEntities3())
                token = bot.Token.Where(x => x.Id == id).First().token1;
            return(token);
        }
Exemplo n.º 12
0
 public void DeleteElement(string category, string product)
 {
     using (botEntities3 bd = new botEntities3())
     {
         bd.Recycle.Remove(bd.Recycle.Where(x => x.NameProduct == product).Where(x => x.NameCategory == category).First());
         bd.SaveChanges();
     }
 }
Exemplo n.º 13
0
 public ActionResult DeleteMes(int id)
 {
     using (botEntities3 bd = new botEntities3())
     {
         Form k = bd.Form.Where(x => x.Id == id).FirstOrDefault();
         bd.Form.Remove(k);
         bd.SaveChanges();
     }
     return(RedirectToAction("ShowForm"));
 }
Exemplo n.º 14
0
 public ActionResult DeleteEmail(string email)
 {
     using (botEntities3 bd = new botEntities3())
     {
         Sub subscrib = bd.Sub.Where(x => x.Email == email).First();
         bd.Sub.Remove(subscrib);
         bd.SaveChanges();
         return(RedirectToAction("ShowSubscribers"));
     }
 }
Exemplo n.º 15
0
        public ActionResult Login(LoginModel model)
        {
            //if (User.Identity.IsAuthenticated)
            //{
            //    CustomRoleProvider l = new CustomRoleProvider();
            //    bool con = l.IsUserInRole(User.Identity.Name, "User");
            //    bool con2 = l.IsUserInRole(User.Identity.Name, "Admin");
            //    if (con)
            //    {
            //        return RedirectToAction("ShowShop", "Admin");
            //    }
            //    else
            //    {
            //        if (con2)
            //            return RedirectToAction("AShowShops", "Admin");
            //    }
            //}
            if (ModelState.IsValid)
            {
                // поиск пользователя в бд
                Users  user = null;
                string a;
                using (botEntities3 db = new botEntities3())
                {
                    user = db.Users.FirstOrDefault(u => u.Email == model.Name && u.Passwords == model.Password);
                    if (user == null)
                    {
                        return(View("LoginWrong", model));
                    }
                    a = user.Roles.Names;
                }
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(model.Name, true);

                    if (a == "User")
                    {
                        return(RedirectToAction("ShowShop", "Admin"));
                    }
                    else
                    {
                        if (a == "Admin")
                        {
                            return(RedirectToAction("AShowShops", "Admin"));
                        }
                    }
                }
                else
                {
                    return(View("LoginWrong", model));
                }
            }

            return(View("LoginWrong", model));
        }
Exemplo n.º 16
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 (botEntities3 bd = new botEntities3())
            {
                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));
                }
            }
            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, update, id);
            Product chooseProduct = p.Where(x => x.ProductName == nameProduct).First();

            if (chooseProduct.ProductPhoto == null)
            {
                chooseProduct.ProductPhoto = "";
            }
            answer = "Стоимость товара " + chooseProduct.ProductPrice + "руб" + Environment.NewLine + "Описание" + " " + chooseProduct.ProductDescription + chooseProduct.ProductPhoto;
            keyboard.AddButton(new InlineKeyboardButton("⬅️ Назад", "about"));
            AddMainButtons(keyboard, update, id);
            reply_markup = JsonConvert.SerializeObject(keyboard);
            return(answer);
        }
Exemplo n.º 17
0
        public string ChangeMyBuy(out string reply_markup)
        {
            reply_markup = "";
            List <Recycle> p;
            List <Product> m = new List <Product>();

            string[] ar;
            using (botEntities3 bd = new botEntities3())
            {
                p  = bd.Recycle.Where(x => x.TokenId == TokenIds).Where(x => x.UserName == username).ToList();
                ar = new string[p.Count];
                for (int i = 0; i < p.Count; i++)
                {
                    try
                    {
                        string  namecat  = p[i].NameCategory;
                        string  nameprod = p[i].NameProduct;
                        Product k        = bd.Product.Where(x => x.ProductName == nameprod).Where(x => x.Category.NameCategory == namecat).First();
                        ar[i] = k.Category.NameCategory;
                        m.Add(k);
                    }
                    catch
                    {
                    }
                }
            }

            if (m.Count == 0)
            {
                return("Выберете пункт меню");
            }
            InlineKeyboard keyboard = new InlineKeyboard();
            int            o        = 0;

            for (int i = 0; i < p.Count; i++)
            {
                try
                {
                    o++;
                    keyboard.AddButton(new InlineKeyboardButton("Удалить " + m[i].ProductName + "(" + ar[i] + ")" + " цена   " + m[i].ProductPrice +
                                                                "     1 шт", "корзина удалить " + ar[i] + " " + m[i].ProductName));
                }
                catch
                {
                }
            }
            this.Count = o;

            keyboard.AddButton(new InlineKeyboardButton("Оформить", "корзина оформить"));
            keyboard.AddButton(new InlineKeyboardButton("⬅️ Назад", "about"));
            reply_markup = JsonConvert.SerializeObject(keyboard);
            return("Изменение заказа");
        }
Exemplo n.º 18
0
        string ImportFile(int userId, int tokenID, string fileName)
        {
            try
            {
                var package = new ExcelPackage(new FileInfo(Path.Combine(Server.MapPath("~/Images"), fileName)));

                ExcelWorksheet workSheet = package.Workbook.Worksheets[1];


                for (int i = workSheet.Dimension.Start.Row + 2; i <= workSheet.Dimension.End.Row; i++)
                {
                    int j = workSheet.Dimension.Start.Column + 1;

                    ImportElement ie = new ImportElement();
                    ie.Category = workSheet.Cells[i, j].Value.ToString();
                    ie.Name     = workSheet.Cells[i, ++j].Value.ToString();
                    string s = workSheet.Cells[i, ++j].Value.ToString();
                    ie.Price       = int.Parse(s);
                    ie.Description = workSheet.Cells[i, ++j].Value.ToString();
                    ie.Photo       = workSheet.Cells[i, ++j].Value.ToString();
                    ie.Count       = int.Parse(workSheet.Cells[i, ++j].Value.ToString());


                    using (botEntities3 db = new botEntities3())
                    {
                        Users    user = db.Users.Where(x => x.Id == userId).First();
                        Token    k    = db.Token.Where(x => x.UserID == user.Id).FirstOrDefault();
                        Category c    = db.Category.Where(x => x.NameCategory == ie.Category).Where(x => x.TokenId == k.Id).FirstOrDefault();

                        if (c == null)
                        {
                            c = new Category()
                            {
                                NameCategory = ie.Category, CategoryId = user.Id, TokenId = tokenID
                            };
                            db.Category.Add(c);
                            db.SaveChanges();
                        }

                        db.Product.Add(new Product()
                        {
                            Category = c, CategoryId = user.Id, ProductDescription = ie.Description, ProductName = ie.Name, ProductPrice = ie.Price, ProductPhoto = ie.Photo, Counts = ie.Count
                        });
                        db.SaveChanges();
                    }
                }
            }
            catch
            {
            }
            return("ок");
        }
Exemplo n.º 19
0
 public void AddBuy(string NameCategorys, string NameProducts)
 {
     using (botEntities3 bd = new botEntities3())
     {
         bd.Recycle.Add(new Recycle()
         {
             NameCategory = NameCategorys,
             NameProduct  = NameProducts,
             TokenId      = TokenIds,
             UserName     = username, Dates = DateTime.Now.ToString()
         });
         bd.SaveChanges();
     }
 }
Exemplo n.º 20
0
 public TelegramRecycle(Update update, int?id)
 {
     if (update.callback_query == null)
     {
         this.username = update.message.from.id.ToString();
     }
     else
     {
         this.username = update.callback_query.from.id.ToString();
     }
     TokenIds = (int)id;
     using (botEntities3 bd = new botEntities3())
     {
         Count = bd.Recycle.Where(x => x.UserName == username).Where(x => x.TokenId == TokenIds).ToList().Count;
     }
 }
Exemplo n.º 21
0
 bool Checked(Update update)
 {
     using (botEntities3 bd = new botEntities3())
     {
         try
         {
             TelegramUser tg = bd.TelegramUser.Where(x => x.Username == update.callback_query.from.id.ToString()).First();
             if (tg != null)
             {
                 return(false);
             }
         }
         catch
         {
             return(true);
         }
         return(true);
     }
 }
Exemplo n.º 22
0
        public ActionResult ShowForm()
        {
            using (botEntities3 bd = new botEntities3())
            {
                bool con = false;
                //если это админ или обычный пользователь
                CustomRoleProvider l = new CustomRoleProvider();
                con = l.IsUserInRole(User.Identity.Name, "Admin");
                if (con)
                {
                    List <Form> mes = bd.Form.ToList();
                    return(View(mes));
                }

                else
                {
                    return(View("Index", "Home"));
                }
            }
        }
Exemplo n.º 23
0
        public ActionResult ShowSubscribers()
        {
            using (botEntities3 bd = new botEntities3())
            {
                bool con = false;
                //если это админ или обычный пользователь
                CustomRoleProvider l = new CustomRoleProvider();
                con = l.IsUserInRole(User.Identity.Name, "Users");
                if (!con)
                {
                    List <Sub> subcribers = bd.Sub.ToList();
                    return(View(subcribers));
                }

                else
                {
                    return(View("Index", "Home"));
                }
            }
        }
Exemplo n.º 24
0
 public ActionResult Subscr(Sub contact)
 {
     if (contact.Email == null)
     {
         return(RedirectToAction("Index", "Home"));
     }
     else
     {
         //beginform
         using (botEntities3 bd = new botEntities3())
         {
             Sub c = new Sub()
             {
                 Email = contact.Email
             };
             bd.Sub.Add(c);
             bd.SaveChanges();
         }
         return(RedirectToAction("Index", "Home"));
     }
 }
Exemplo n.º 25
0
        void SendMessageToAdmin(Update update, int?id)
        {
            string chat_id = "";
            string token   = ReceiveToken(update, id);
            int?   u;

            using (botEntities3 bd = new botEntities3())
            {
                u       = bd.Token.Where(x => x.token1 == token).FirstOrDefault().UserID;
                chat_id = bd.TelegramUser.Where(x => x.UserId == u).FirstOrDefault().Username;
            }
            string message = "Пользователь " + update.message.contact.first_name + " сделал заказ  " +
                             "его контактные данные " + update.message.contact.user_id + "его телефон " + update.message.contact.phone_number;
            string BaseUrl          = "https://api.telegram.org/bot";
            string address          = BaseUrl + ReceiveToken(update, id) + "/sendMessage";
            NameValueCollection nvc = new NameValueCollection();

            nvc.Add("chat_id", chat_id.ToString());
            nvc.Add("text", message);
            using (WebClient client = new WebClient())
                client.UploadValues(address, nvc);
            using (botEntities3 bd = new botEntities3())
            {
                List <Recycle> res = bd.Recycle.Where(x => x.Token.token1 == token).Where(x => x.UserName == update.message.contact.user_id.ToString()).ToList();
                for (int i = 0; i < res.Count; i++)
                {
                    OrderRecycle ord = new OrderRecycle()
                    {
                        Dates        = DateTime.Now.ToString(),
                        TokenId      = bd.Token.Where(x => x.token1 == token).FirstOrDefault().Id,
                        UserName     = update.message.contact.user_id.ToString(),
                        Token        = bd.Token.Where(x => x.token1 == token).FirstOrDefault(),
                        NameCategory = res[i].NameCategory,
                        NameProduct  = res[i].NameProduct
                    };
                    bd.OrderRecycle.Add(ord);
                    bd.SaveChanges();
                }
            }
        }
Exemplo n.º 26
0
 public ActionResult Subscribe(Form con)
 {
     if (con.Email == null || con.Mesages == null || con.Names == null || con.Titles == null)
     {
         return(RedirectToAction("Index", "Home"));
     }
     else
     {
         //beginform
         using (botEntities3 bd = new botEntities3())
         {
             Form form = new Form()
             {
                 Email   = con.Email,
                 Mesages = con.Mesages,
                 Names   = con.Names,
                 Titles  = con.Titles
             };
             bd.Form.Add(form);
             bd.SaveChanges();
         }
         return(RedirectToAction("Index", "Home"));
     }
 }
Exemplo n.º 27
0
        public ActionResult DeleteShop(string email)
        {
            using (botEntities3 bd = new botEntities3())
            {
                try
                {
                    List <Users>    users    = bd.Users.ToList();
                    List <Token>    tokens   = bd.Token.ToList();
                    List <Category> category = bd.Category.ToList();
                    List <Product>  product  = bd.Product.ToList();
                    List <Recycle>  recyc    = bd.Recycle.ToList();



                    Users user = bd.Users.Where(x => x.Email == email).FirstOrDefault();

                    Token token = bd.Token.Where(x => x.UserID == user.Id).FirstOrDefault();

                    TelegramUser        tguser = bd.TelegramUser.Where(x => x.UserId == user.Id).FirstOrDefault();
                    List <OrderRecycle> rs     = null;
                    try
                    {
                        OrderRecycle or = bd.OrderRecycle.Where(x => x.TokenId == token.Id).FirstOrDefault();
                        if (or != null)
                        {
                            rs = bd.OrderRecycle.Where(x => x.TokenId == token.Id).ToList();
                        }
                    }
                    catch
                    {
                    }
                    List <Category> category_remove = new List <Category>();
                    List <Product>  product_remove  = new List <Product>();

                    if (category != null)
                    {
                        try
                        {
                            foreach (Category i in category)
                            {
                                if (i.TokenId == token.Id)
                                {
                                    category_remove.Add(i);
                                    foreach (Product prod in product)
                                    {
                                        if (prod.CategoryId == i.CategoryId)
                                        {
                                            product_remove.Add(prod);
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }


                    if (product_remove != null)
                    {
                        try
                        {
                            foreach (Product prod in product_remove)
                            {
                                bd.Product.Remove(prod);
                            }
                        }
                        catch
                        {
                        }
                    }
                    if (category_remove != null)
                    {
                        try
                        {
                            foreach (Category cat in category_remove)
                            {
                                bd.Category.Remove(cat);
                            }
                        }
                        catch { }
                    }

                    if (recyc != null)
                    {
                        try
                        {
                            foreach (Recycle rec in recyc)
                            {
                                if (rec.TokenId == token.Id)
                                {
                                    bd.Recycle.Remove(rec);
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                    if (rs != null)
                    {
                        foreach (OrderRecycle j in rs)
                        {
                            bd.OrderRecycle.Remove(j);
                        }
                    }


                    if (tguser != null)
                    {
                        bd.TelegramUser.Remove(tguser);
                    }
                    if (token != null)
                    {
                        bd.Token.Remove(token);
                    }

                    bd.Users.Remove(user);

                    bd.SaveChanges();
                }
                catch
                {
                }
                return(RedirectToAction("AShowShops"));
            }
        }
Exemplo n.º 28
0
        public ActionResult AShowShops()
        {
            CustomRoleProvider l = new CustomRoleProvider();
            bool con             = l.IsUserInRole(User.Identity.Name, "Admin");

            if (!con)
            {
                return(View("Index", "Home"));
            }

            using (botEntities3 bd = new botEntities3())
            {
                try {
                    List <ShopsModel> shops = new List <ShopsModel>();

                    List <Users>    users    = bd.Users.ToList();
                    List <Token>    tokens   = bd.Token.ToList();
                    List <Category> category = bd.Category.ToList();
                    List <Product>  product  = bd.Product.ToList();

                    List <Category> category_list = new List <Category>();
                    List <Product>  product_list  = new List <Product>();

                    foreach (Users temp_user in users)
                    {
                        string k = null;
                        try
                        {
                            k = temp_user.TelegramUser.Where(x => x.UserId == temp_user.Id).FirstOrDefault().BotChannel;
                        }
                        catch
                        {
                            if (k == null)
                            {
                                k = " ";
                            }
                        }
                        if (k == null)
                        {
                            k = " ";
                        }
                        string name        = temp_user.Email;
                        string nameShop    = k;
                        Token  temp_tokens = new Token();
                        for (int i = 0; i < tokens.Count; i++)
                        {
                            if (temp_user.Id == tokens.ElementAt(i).UserID)
                            {
                                temp_tokens = tokens.ElementAt(i);
                                break;
                            }
                        }
                        category_list = new List <Category>();
                        product_list  = new List <Product>();
                        foreach (Category temp_category in category)
                        {
                            if (temp_tokens.Id == temp_category.TokenId)
                            {
                                foreach (Product prod in product)
                                {
                                    if (prod.CategoryId == temp_category.CategoryId)
                                    {
                                        product_list.Add(prod);
                                    }
                                }
                            }
                        }

                        shops.Add(new ShopsModel(nameShop, name, product_list));
                    }
                    return(View(shops));
                }
                catch
                {
                }
                return(View());
            }
        }
Exemplo n.º 29
0
        private string Register(Update update)
        {
            // поиск пользователя в бдhttp://botshop.azurewebsites.net/Account/Login
            Users  user   = null;
            string answer = "";

            using (botEntities3 db = new botEntities3())
            {
                try
                {
                    Token tok = db.Token.Where(x => x.token1 == update.message.text).FirstOrDefault();
                    if (tok != null)
                    {
                        return("Такой токен уже есть в нашей системе");
                    }
                    TelegramUser u = db.TelegramUser.Where(x => x.Username == update.message.from.id.ToString()).FirstOrDefault();
                    if (u != null)
                    {
                        user = db.Users.FirstOrDefault(x => x.Id == u.UserId);
                        return("У вас уже есть магазин");
                    }
                }
                catch
                {
                    user = null;
                }
            }
            if (user != null)
            {
                using (botEntities3 db = new botEntities3())
                {
                    Token t = new Token();
                    t.token1 = update.message.text;
                    t.UserID = user.Id;
                    db.Token.Add(t);
                    db.SaveChanges();
                }
                answer += "Магазин успешно добавлен";
                return(answer);
            }
            else
            {
                string em  = "";
                string pas = "";

                Random ran = new Random();
                for (int i = 0; i < 4; i++)
                {
                    em  += (char)ran.Next('a', 'z');
                    pas += (char)ran.Next('a', 'z');
                }
                try
                {
                    int count;
                    using (botEntities3 db = new botEntities3())
                    {
                        count = db.Users.Count() + 10;
                        em   += db.Users.Count().ToString() + "@bot.ru";
                        user  = new Users()
                        {
                            Email     = em,
                            RoleId    = 1,
                            Passwords = pas,
                            Id        = count
                        };
                        db.Users.Add(user);
                        db.SaveChanges();
                    }
                    using (botEntities3 db = new botEntities3())
                    {
                        TelegramUser t = new TelegramUser();
                        //  count = db.Users.Where(x => x.Id == count).First().;
                        t.UserId     = count;
                        t.Username   = update.message.from.id.ToString();
                        t.BotChannel = getBotInfo(update.message.text);
                        db.TelegramUser.Add(t);
                        db.SaveChanges();
                    }
                    using (botEntities3 db = new botEntities3())
                    {
                        Token k = new Token();
                        k.token1 = update.message.text;
                        k.UserID = count;
                        db.Token.Add(k);
                        db.SaveChanges();
                    }
                    return("Регистрация прошла успешно" + Environment.NewLine + "  Ваш логин:" + " " + em + " Ваш пароль " + pas + Environment.NewLine
                           + " Используйте эти данные для входа в систему " + @"http://botshop.azurewebsites.net/Account/Login");
                }
                catch
                {
                    return("Неверные входные данные");
                }
                //   answer = "Вы успешно зарегистрировались" + " " + "Ваш логин " + em;
            }
        }
Exemplo n.º 30
0
        public ActionResult AddElement(string category, string nameproduct, string description, string price, string count, HttpPostedFileBase upload)
        {
            Users user;
            Token k;

            using (botEntities3 bd = new botEntities3())
            {
                string u = User.Identity.Name;
                user = bd.Users.Where(x => x.Email == u).FirstOrDefault();
                k    = bd.Token.Where(x => x.UserID == user.Id).FirstOrDefault();
            }
            string o        = "";
            string path     = " ";
            string fileName = " ";
            string ps       = "";

            try
            {
                if (upload != null)
                {
                    // получаем имя файла


                    fileName = System.IO.Path.GetFileName(upload.FileName);
                    Random rnd = new Random();
                    ps = "";
                    for (int i = 0; i < 3; i++)
                    {
                        ps += (char)rnd.Next('a', 'z');
                    }
                    // сохраняем файл в папку Files в проекте
                    ps = ps + fileName;

                    path = Path.Combine(Server.MapPath("~/Images"), ps);

                    upload.SaveAs(path);
                }
                ;
                string path1 = $@"<a href=""http://botshop.azurewebsites.net/Images/{ps}""> </a>";
                using (botEntities3 db = new botEntities3())
                {
                    Category c = db.Category.Where(x => x.NameCategory == category).Where(x => x.TokenId == k.Id).FirstOrDefault();

                    if (c == null)
                    {
                        c = new Category()
                        {
                            NameCategory = category, CategoryId = user.Id, TokenId = k.Id
                        };
                        db.Category.Add(c);
                        db.SaveChanges();
                    }

                    db.Product.Add(new Product()
                    {
                        Category = c, CategoryId = user.Id, ProductDescription = description, ProductName = nameproduct, ProductPrice = int.Parse(price), ProductPhoto = path1, Counts = int.Parse(count)
                    });
                    db.SaveChanges();
                }
                return(View("AddElementS"));
            }
            catch
            {
                return(View("AddElementF"));
            }
        }