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 #2
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 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 #4
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"));
        }
        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"));
        }
        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()
        {
            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 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"));
        }
        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"));
        }