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)); }
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 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)); }
public ActionResult Andex() { CustomRoleProvider l = new CustomRoleProvider(); bool admin = l.IsUserInRole(User.Identity.Name, "Admin"); if (!admin) { return(RedirectToAction("Index", "Home")); } return(View()); }
public ActionResult AddElement() { CustomRoleProvider l = new CustomRoleProvider(); bool con = l.IsUserInRole(User.Identity.Name, "User"); if (!con) { return(View("Index", "Home")); } return(View()); }
public ActionResult Index() { List <PostViewModel> viewModel = new List <PostViewModel>(); if (User.Identity.IsAuthenticated) { List <Post> posts = new List <Post>(); posts = db.Posts.ToList(); foreach (var post in posts) { viewModel.Add(new PostViewModel { ImgPath = post.ImgPath, PublicationDate = post.PublicationDate, Text = post.Text, Title = post.Title }); } ViewData["Posts"] = viewModel; ViewData["IsAuthenticated"] = "Authenticated"; if (customRoleProvider.IsUserInRole(User.Identity.Name, "admin")) { ViewData["IsAdmin"] = "Admin"; } else { ViewData["IsAdmin"] = "NotAdmin"; } } else { ViewData["IsAuthenticated"] = "NotAuthenticated"; ViewData["IsAdmin"] = "NotAdmin"; } return(View(viewModel)); }
public ActionResult Login(LogInModel viewModel, string returnUrl) { if (ModelState.IsValid) { var provider = (CustomMembershipProvider)Membership.Provider; if (provider.ValidateUser(viewModel.Email, viewModel.Password)) { FormsAuthentication.SetAuthCookie(viewModel.Email, viewModel.RememberMe); if (Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } var roleProvider = new CustomRoleProvider(); return(roleProvider.IsUserInRole(viewModel.Email, "User") ? RedirectToAction("GetMyFiles", "File") : RedirectToAction("FindAllUsers", "Admin")); } ModelState.AddModelError("", "Incorrect email or password"); } return(View(viewModel)); }
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")); } } }
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")); } } }
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()); } }