Exemple #1
0
        // GET: Discover
        public ActionResult Index()
        {
            ShopTymDBContext _context = new ShopTymDBContext();

            ViewBag.Products = _context.Products.ToList();
            return(View());
        }
Exemple #2
0
        public ActionResult Item(int id)
        {
            ShopTymDBContext _context = new ShopTymDBContext();

            ViewBag.Products = _context.Products.SingleOrDefault(p => p.ProductId == id);
            return(View());
        }
        public ActionResult Details(int id)
        {
            ShopTymDBContext context = new ShopTymDBContext();
            Product          product = context.Products.SingleOrDefault(p => p.ProductId == id);

            return(View(product));
        }
        public ActionResult Create(Categorie c)
        {
            bool flag = false;

            if (c.CategoryName == String.Empty || c.CategoryName == null)
            {
                TempData["CategoryErrorCssClass"] = "alert alert-danger";
                TempData["CategoryError"]         = "Category Name Can not empty.";
                flag = true;
            }
            else if (c.CategoryName != null && System.Text.RegularExpressions.Regex.IsMatch(c.CategoryName, @"\d"))
            {
                TempData["CategoryErrorCssClass"] = "alert alert-danger";
                TempData["CategoryError"]         = "Category Name Can not Contain Numbers.";
                flag = true;
            }
            if (!flag)
            {
                ShopTymDBContext context = new ShopTymDBContext();
                context.Categories.Add(c);
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Create"));
            }
        }
Exemple #5
0
        public ActionResult Search()
        {
            ShopTymDBContext _context = new ShopTymDBContext();
            string           key      = Request.Form["search"].ToLower();

            //ViewBag.Products = _context.Products.Where(p => p.CategoryName.ToLower().Contains( Request.Form["search"].ToLower())).ToList();
            ViewBag.Products = (from p in _context.Products where p.CategoryName.ToLower().Contains(key) || p.ProductName.ToLower().Contains(key) select p).ToList();
            return(View());
        }
        public ActionResult Delete_Confirm(int id)
        {
            ShopTymDBContext context = new ShopTymDBContext();
            Product          product = context.Products.SingleOrDefault(p => p.ProductId == id);

            context.Products.Remove(product);
            context.SaveChanges();
            return(RedirectToAction("Index", "Product"));
        }
Exemple #7
0
        public ActionResult Delete_P(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopTymDBContext context = new ShopTymDBContext();
            CustomerPurchase items   = context.CustomerPurchases.SingleOrDefault(s => s.PurchaseId == id);

            return(View(items));
        }
        public ActionResult Delete_Confirm(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopTymDBContext context   = new ShopTymDBContext();
            Categorie        categorie = context.Categories.SingleOrDefault(c => c.CategoryId == id);

            context.Categories.Remove(categorie);
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #9
0
        public ActionResult Delete_PP(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopTymDBContext context = new ShopTymDBContext();
            CustomerPurchase item    = context.CustomerPurchases.SingleOrDefault(s => s.PurchaseId == id);

            context.CustomerPurchases.Remove(item);
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: Product
        public ActionResult Index()
        {
            ShopTymDBContext context = new ShopTymDBContext();
            string           role    = context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Roles;

            if (role.ToUpper() == "ADMIN")
            {
                return(View(context.Products.ToList()));
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
Exemple #11
0
        public ActionResult SaveItems()
        {
            ShopTymDBContext context = new ShopTymDBContext();

            if (User.Identity.IsAuthenticated)
            {
                string role = context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Roles;
                if (role.ToUpper() != "USER")
                {
                    return(RedirectToAction("Login", "Login"));
                }
            }
            return(View(context.SaveItems.ToList()));
        }
        public ActionResult Edit(Categorie categorie)
        {
            ShopTymDBContext context = new ShopTymDBContext();

            //Categorie categorieToUpdate = context.Categories.SingleOrDefault(c => c.CategoryId == categorie.CategoryId);
            if (ModelState.IsValid)
            {
                //categorieToUpdate.CategoryName = categorie.CategoryName;
                context.Entry(categorie).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(categorie));
        }
        public ActionResult Create()
        {
            ShopTymDBContext context = new ShopTymDBContext();

            if (User.Identity.IsAuthenticated)
            {
                string role = context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Roles;
                if (role.ToUpper() != "ADMIN")
                {
                    return(RedirectToAction("Login", "Login"));
                }
            }
            ViewBag.Categories = context.Categories;
            return(View());
        }
Exemple #14
0
        public ActionResult Index()
        {
            ShopTymDBContext context = new ShopTymDBContext();

            if (User.Identity.IsAuthenticated)
            {
                string role = context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Roles;
                if (role.ToUpper() == "ADMIN")
                {
                    return(View(context.CustomerPurchases.ToList()));
                }
            }

            return(RedirectToAction("Login", "Login"));
        }
        public ActionResult Auth()
        {
            string userName = Request.Form["userName"];
            string password = Request.Form["password"];

            Response.Write(userName);
            if (userName == "")
            {
                TempData["LoginErrorCssClass"] = "alert alert-info";
                TempData["LoginError"]         = "Useer Name Field Can't Be Empty.";
                return(RedirectToAction("Login", ViewBag));
            }
            else if (password == "")
            {
                TempData["LoginErrorCssClass"] = "alert alert-info";
                TempData["LoginError"]         = "Password Field Can't Be Empty.";
                return(RedirectToAction("Login", ViewBag));
            }
            else
            {
                TempData["LoginErrorCssClass"] = "";
                TempData["LoginError"]         = "";
            }
            ShopTymDBContext context = new ShopTymDBContext();
            User             user    = (User)context.Users.SingleOrDefault(c => c.Email == userName && c.Password == password);

            if (user == null)
            {
                TempData["LoginErrorCssClass"] = "alert alert-danger";
                TempData["LoginError"]         = "Useer Name Or Password Is Incorrect.";
                return(RedirectToAction("Login", ViewBag));
            }
            else
            {
                FormsAuthentication.SetAuthCookie(user.Email, false);
                if (user.Roles.ToUpper() == "ADMIN")
                {
                    return(RedirectToAction("Index", "Categorie"));
                }
                else if (user.Roles.ToUpper() == "USER")
                {
                    Session["UserName"] = user.Email;
                    Session["UserId"]   = user.UserId;
                    return(RedirectToAction("Index", "User"));
                }
            }
            return(RedirectToAction("Login"));
        }
        public ActionResult _Create()
        {
            bool flag = false;

            if (Request["ProductName"] == String.Empty)
            {
                TempData["ProductErrorCssClass"] = "alert alert-danger";
                TempData["ProductError"]         = "Product Name Can Not Be Empty.";
                flag = true;
            }
            else if (!System.Text.RegularExpressions.Regex.IsMatch(Request["ProductPrice"], @"\d"))
            {
                TempData["ProductErrorCssClass"] = "alert alert-danger";
                TempData["ProductError"]         = "Latter Not Allowed.";
                flag = true;
            }
            else if (!System.Text.RegularExpressions.Regex.IsMatch(Request["ProductQuentity"], @"\d"))
            {
                TempData["ProductErrorCssClass"] = "alert alert-danger";
                TempData["ProductError"]         = "Latter Not Allowed.";
                flag = true;
            }
            if (!flag)
            {
                HttpPostedFileBase file = Request.Files["ProductImage"];
                string             path = Path.Combine(Server.MapPath("~/Image/"), file.FileName);

                var p = (Product) new Product();
                p.ProductName     = Request["ProductName"];
                p.ProductPrice    = Convert.ToDouble(Request["ProductPrice"]);
                p.ProductQuentity = Convert.ToInt32(Request["ProductQuentity"]);
                p.ProductImage    = file.FileName;
                p.Description     = Request["Description"];
                p.Features        = Request["Features"];
                p.CategoryName    = Request["CategoryName"];


                file.SaveAs(path);
                ShopTymDBContext context = new ShopTymDBContext();
                context.Products.Add(p);
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Create"));
            }
        }
        public ActionResult Delete(int id)
        {
            ShopTymDBContext context = new ShopTymDBContext();

            if (User.Identity.IsAuthenticated)
            {
                string role = context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Roles;
                if (role.ToUpper() != "ADMIN")
                {
                    return(RedirectToAction("Login", "Login"));
                }
            }
            Product product = context.Products.SingleOrDefault(p => p.ProductId == id);

            return(View(product));
        }
        public ActionResult Signup(User user)
        {
            HttpPostedFileBase file = Request.Files["Image"];

            user.Roles = "User";
            user.Dob   = Convert.ToDateTime(Request.Form["Dob"]);
            string imageName = user.UserName + file.FileName;

            user.Image = imageName;
            file.SaveAs(Path.Combine(Server.MapPath("~/Image/"), imageName));
            ShopTymDBContext context = new ShopTymDBContext();

            context.Users.Add(user);
            context.SaveChanges();
            return(RedirectToAction("Login", "Login"));
        }
Exemple #19
0
        public ActionResult BuyOrSave()
        {
            ShopTymDBContext context = new ShopTymDBContext();

            if (User.Identity.IsAuthenticated)
            {
                string role = context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Roles;
                if (role.ToUpper() != "USER")
                {
                    return(RedirectToAction("Login", "Login"));
                }
            }
            if (Request.Form["SaveItem"] != null)
            {
                var item = (SaveItem) new SaveItem();
                item.ProductId    = Convert.ToInt32(Request.Form["productId"]);
                item.SaveQuentity = Convert.ToInt32(Request.Form["Quentity"]);
                item.CustomerId   = Convert.ToInt32(Session["UserId"]);
                context.SaveItems.Add(item);
                context.SaveChanges();
            }
            else if (Request.Form["BuyItem"] != null)
            {
                int productId = Convert.ToInt32(Request.Form["productId"]);

                Product product = context.Products.SingleOrDefault(p => p.ProductId == productId);
                product.ProductQuentity -= Convert.ToInt32(Request.Form["Quentity"]);

                context.Products.Attach(product);
                context.Entry(product).Property(x => x.ProductQuentity).IsModified = true;
                context.SaveChanges();

                var customerPurchase = (CustomerPurchase) new CustomerPurchase();
                customerPurchase.ProductId       = productId;
                customerPurchase.ProductPrice    = product.ProductPrice;
                customerPurchase.ProductQuentity = Convert.ToInt32(Request.Form["Quentity"]);
                customerPurchase.PurchaseDate    = DateTime.Now;
                customerPurchase.UserId          = Convert.ToInt32(Session["UserId"]);

                context.CustomerPurchases.Add(customerPurchase);
                context.SaveChanges();
                return(RedirectToAction("Index", "User"));
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int?id)
        {
            ShopTymDBContext context = new ShopTymDBContext();

            if (User.Identity.IsAuthenticated)
            {
                string role = context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Roles;
                if (role.ToUpper() != "ADMIN")
                {
                    return(RedirectToAction("Login", "Login"));
                }
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Categorie categorie = context.Categories.SingleOrDefault(c => c.CategoryId == id);

            return(View(categorie));
        }
        public ActionResult Edit(int?id)
        {
            ShopTymDBContext context = new ShopTymDBContext();

            if (User.Identity.IsAuthenticated)
            {
                string role = context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Roles;
                if (role.ToUpper() != "ADMIN")
                {
                    return(RedirectToAction("Login", "Login"));
                }
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product product = context.Products.SingleOrDefault(p => p.ProductId == id);

            ViewBag.PImage = product.ProductImage;
            return(View(product));
        }
Exemple #22
0
        public ActionResult Delete(int?id)
        {
            ShopTymDBContext context = new ShopTymDBContext();

            if (User.Identity.IsAuthenticated)
            {
                string role = context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Roles;
                if (role.ToUpper() != "USER")
                {
                    return(RedirectToAction("Login", "Login"));
                }
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            SaveItem items = context.SaveItems.SingleOrDefault(s => s.SaveItemId == id);

            return(View(items));
        }
Exemple #23
0
        public ActionResult Me()
        {
            ShopTymDBContext context = new ShopTymDBContext();

            if (User.Identity.IsAuthenticated)
            {
                string role = context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Roles;
                if (role.ToUpper() != "USER")
                {
                    return(RedirectToAction("Login", "Login"));
                }
            }
            string uname = Session["UserName"].ToString();
            User   user  = context.Users.SingleOrDefault(u => u.Email == uname);

            ViewBag.Name    = user.UserName;
            ViewBag.Email   = user.Email;
            ViewBag.Address = user.Address;
            ViewBag.Phone   = user.Phone;
            ViewBag.Image   = user.Image;
            return(View());
        }
Exemple #24
0
        // GET: Home
        //[Authorize(Roles = "Admin")]
        public ActionResult Index()
        {
            ShopTymDBContext context = new ShopTymDBContext();

            if (User.Identity.IsAuthenticated)
            {
                string role = context.Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Roles;

                if (role.ToUpper() == "ADMIN")
                {
                    return(RedirectToAction("Index", "Categorie"));
                }
                else if (role.ToUpper() == "USER")
                {
                    return(RedirectToAction("Index", "User"));
                }
                //return RedirectToAction("Login", "Login");
            }

            ViewBag.Products = context.Products.ToList();
            return(View());
        }
        public ActionResult Index()
        {
            ShopTymDBContext context = new ShopTymDBContext();
            List <int>       list    = new List <int>();

            list = context.CustomerPurchases.GroupBy(p => p.ProductId).OrderByDescending(P => P.Count()).Select(p => p.Key).ToList();
            //return list[0].ToString();

            List <Product> tmp  = new List <Product>();
            List <int>     sumQ = new List <int>();

            for (int i = 0; i < list.Count; i++)
            {
                int id = Convert.ToInt32(list[i]);
                tmp.Add(context.Products.SingleOrDefault(p => p.ProductId == id));
            }

            ViewBag.MaxSell      = tmp;
            ViewBag.maxSellQ     = sumQ;
            ViewBag.LessQuantity = context.Products.Where(p => p.ProductQuentity < 4).ToList();

            return(View());
        }
        public ActionResult Edit(Product product)
        {
            ShopTymDBContext context = new ShopTymDBContext();

            Product productToUpdate = context.Products.SingleOrDefault(p => p.ProductId == product.ProductId);

            HttpPostedFileBase file = Request.Files["ProductImage"];
            string             path = Path.Combine(Server.MapPath("~/Image/"), file.FileName);

            productToUpdate.ProductName     = product.ProductName;
            productToUpdate.ProductPrice    = product.ProductPrice;
            productToUpdate.ProductQuentity = product.ProductQuentity;
            productToUpdate.ProductImage    = file.FileName;
            productToUpdate.Description     = product.Description;
            productToUpdate.Features        = product.Features;
            productToUpdate.CategoryName    = product.CategoryName;


            file.SaveAs(path);
            context.SaveChanges();

            return(RedirectToAction("Index"));
        }