Beispiel #1
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"));
        }
Beispiel #2
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("ок");
        }
Beispiel #3
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"));
        }
 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();
     }
 }
Beispiel #5
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"));
     }
 }
Beispiel #6
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"));
 }
 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();
     }
 }
Beispiel #8
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"));
     }
 }
        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();
                }
            }
        }
Beispiel #10
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"));
     }
 }
Beispiel #11
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"));
            }
        }
Beispiel #12
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"));
            }
        }
Beispiel #13
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;
            }
        }