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 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")); }