public ActionResult Creat(Category category)
 {
     if (dataContextDB.Categorys.Any(x => x.Categury_Name == category.Categury_Name))
     {  //de bawzt fekrt el MVC
         ModelState.AddModelError("Categury_Name", "Name is rely esest");
     }
     dataContextDB.Categorys.Add(category);
     dataContextDB.SaveChanges();
     return(RedirectToAction("Index"));
 }
        public int AddCategory(Category category)
        {
            int result = -1;

            if (category != null)
            {
                dataContextDB.Categorys.Add(category);
                dataContextDB.SaveChanges();
                result = category.CareguryId;
            }
            return(result);
        }
        public ActionResult Edit(int?id)
        {
            DataContextDB dataContextDB = new DataContextDB();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var EdietProduct = dataContextDB.Products.Find(id);

            if (TryUpdateModel(EdietProduct, "",
                               new string[] { "Name", "Description", "Price" }))
            {
                try
                {
                    dataContextDB.SaveChanges();

                    return(RedirectToAction("Index", "Home"));
                }
                catch (RetryLimitExceededException)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }
            return(View(EdietProduct));
        }
        public ActionResult Delete(int id)
        {
            DataContextDB dataContextDB = new DataContextDB();
            Product       productdelet  = dataContextDB.Products.Single(cat => cat.ProductId == id);

            dataContextDB.Products.Remove(productdelet);
            dataContextDB.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Creat(Product product)
        {
            if (dataContextDB.Products.Any(x => x.Name == product.Name))
            {    //de bawzt fekrt el MVC
                ModelState.AddModelError("Name", "Name is rely esest");
            }


            dataContextDB.Products.Add(product);
            dataContextDB.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 6
0
        public ActionResult Add(int id)
        {
            if (ModelState.IsValid)
            {
                if (dataContextDB.Carts.Any(ac => ac.ProductId.Equals(id)))
                {
                    return(RedirectToAction("Index", "Home"));

                    ;
                }
                else
                {
                    Carts cartadd   = dataContextDB.Carts.FirstOrDefault(car => car.ProductId == id);
                    var   cartToAdd = new Carts()
                    {
                        ProductId = id
                    };
                    dataContextDB.Carts.Add(cartToAdd);
                    dataContextDB.SaveChanges();
                }
            }

            return(RedirectToAction("Index", "Carts"));
        }