public IActionResult Create(Product product) { dbContext.Products.Add(product); dbContext.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Product product) { if (this.ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); } return(Redirect("/")); }
public IActionResult Create(Product product) { if (ModelState.IsValid) { dbContext.Add(product); dbContext.SaveChanges(); return(Redirect("/")); } return(View(product)); }
public ActionResult Create(Product product) { //TODO: Implement me ... if (this.ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(Redirect("/")); } return(View(product)); }
public ActionResult EditConfirm(int?id, Product productModel) { using (var db = new ShoppingListDbContext()) { var product = db.Products.Find(id); if (product == null) { return(Redirect("/")); } db.Products.Remove(product); product = productModel; if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(Redirect("/")); } return(Redirect("/")); } }
public ActionResult EditConfirm(int?id, Product productModel) { if (id == null) { return(HttpNotFound()); } if (!ModelState.IsValid) { return(View(productModel)); } using (var db = new ShoppingListDbContext()) { Product product = db.Products.Find(id); if (product == null) { return(RedirectToAction("Index")); } product.Priority = productModel.Priority; product.Name = productModel.Name; product.Quantity = productModel.Quantity; product.Status = productModel.Status; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult EditConfirm(int?id, Product productModel) { using (var db = new ShoppingListDbContext()) { var productFromDb = db.Products.Find(id); if (productFromDb == null) { return(HttpNotFound()); } if (ModelState.IsValid) { productFromDb.Priority = productModel.Priority; productFromDb.Name = productModel.Name; productFromDb.Quantity = productModel.Quantity; productFromDb.Status = productModel.Status; db.SaveChanges(); return(Redirect("/")); } return(View("Edit", productModel)); } }
public ActionResult EditConfirm(int?id, Product productModel) { using (var db = new ShoppingListDbContext()) { var product = db.Products.Find(id); if (product == null) { return(RedirectToAction("Index")); } if (string.IsNullOrWhiteSpace(product.Priority.ToString()) || string.IsNullOrWhiteSpace(product.Name) || string.IsNullOrWhiteSpace(product.Quantity.ToString()) || string.IsNullOrWhiteSpace(product.Status)) { return(RedirectToAction("Index")); } product.Priority = productModel.Priority; product.Name = productModel.Name; product.Quantity = productModel.Quantity; product.Status = productModel.Status; db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult EditConfirm(int?id, Product productModel) { using (var db = new ShoppingListDbContext()) { var product = db.Products .FirstOrDefault(p => p.Id == id); if (product == null) { return(RedirectToAction("Index")); } if (ModelState.IsValid) { product.Name = productModel.Name; product.Priority = productModel.Priority; productModel.Quantity = productModel.Quantity; product.Status = productModel.Status; db.SaveChanges(); return(RedirectToAction("Index")); } return(View("Edit", productModel)); } }
public ActionResult Edit(int?id, Product productModel) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var db = new ShoppingListDbContext()) { Product product = db.Products.Where(p => p.Id == id) .First(); if (product == null) { return(HttpNotFound()); } if (!ModelState.IsValid) { return(View(productModel)); } product.Name = productModel.Name; product.Priority = productModel.Priority; product.Quantity = productModel.Quantity; product.Status = productModel.Status; db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Edit(int?id, Product productModel) { using (var db = new ShoppingListDbContext()) { var product = db.Products.Find(id); if (product == null) { return(RedirectToAction("Index")); } if (string.IsNullOrWhiteSpace(productModel.Name) || string.IsNullOrWhiteSpace(productModel.Status) || productModel.Priority == null || productModel.Quantity == null) { ViewBag.message = "Попълни полетата!"; return(View(product)); } product.Name = productModel.Name; product.Priority = productModel.Priority; product.Quantity = productModel.Quantity; product.Status = productModel.Status; db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult EditConfirm(int?id, Product productModel) { if (id == null) { return(HttpNotFound()); } if (ModelState.IsValid) { using (var database = new ShoppingListDbContext()) { Product productFromDb = database.Products.Find(id); if (productFromDb == null) { return(RedirectToAction("Index")); } productFromDb.Name = productModel.Name; productFromDb.Priority = productModel.Priority; productFromDb.Quantity = productModel.Quantity; productFromDb.Status = productModel.Status; database.SaveChanges(); } } return(RedirectToAction("Index")); }
public ActionResult EditConfirm(int?id, Product productModel) { using (var database = new ShoppingListDbContext()) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } Product taskFromDB = database.Products.Find(productModel.Id); if (taskFromDB == null) { return(new HttpNotFoundResult($"Cannot find Task with ID {id}")); } taskFromDB.Priority = productModel.Priority; taskFromDB.Name = productModel.Name; taskFromDB.Quantity = productModel.Quantity; taskFromDB.Status = productModel.Status; database.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Create(Product product) { if (this.ModelState.IsValid) { Product currentProduct = new Product(); currentProduct.Name = product.Name; currentProduct.Priority = product.Priority; currentProduct.Quantity = product.Quantity; currentProduct.Status = "not bought"; db.Products.Add(currentProduct); db.SaveChanges(); return(Redirect("/")); } return(View()); }
public ActionResult Create(Product product) { using (var db = new ShoppingListDbContext()) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Create(Product product) { if (ModelState.IsValid) { using (var database = new ShoppingListDbContext()) { database.Products.Add(product); database.SaveChanges(); } } return(RedirectToAction("Index")); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { using (var db = new ShoppingListDbContext()) { db.Products.Add(product); db.SaveChanges(); return(Redirect("/")); } } return(View("Create")); }
public ActionResult EditConfirm(int?id, Product productModel) { if (ModelState.IsValid) { using (var db = new ShoppingListDbContext()) { var product = productModel; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); }
public ActionResult Create(Product product) { if (!ModelState.IsValid) { return(View()); } using (var db = new ShoppingListDbContext()) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Create(Product product) { if (ModelState.IsValid) { using (var db = new ShoppingListDbContext()) { var creteProduct = product; db.Products.Add(creteProduct); db.SaveChanges(); } } return(RedirectToAction("Index")); }
public ActionResult EditConfirm(int?id, Product productModel) { using (var db = new ShoppingListDbContext()) { Product currentProduct = db.Products.Find(id); currentProduct.Priority = productModel.Priority; currentProduct.Name = productModel.Name; currentProduct.Quantity = productModel.Quantity; currentProduct.Status = productModel.Status; db.SaveChanges(); return(Redirect("/")); } }
public ActionResult EditConfirm(int?id, Product productModel) { using (var db = new ShoppingListDbContext()) { Product product = db.Products.Where(x => x.Id == id).First(); product.Name = productModel.Name; product.Priority = productModel.Priority; product.Quantity = productModel.Quantity; product.Status = productModel.Status; db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Create(Product product) { if (product == null) { return(RedirectToAction("Index", "Product")); } if (ModelState.IsValid) { using (var db = new ShoppingListDbContext()) { db.Products.Add(product); db.SaveChanges(); } return(RedirectToAction("index", "Product")); } return(RedirectToAction("Create", "Product")); }
public ActionResult Create(Product product) { if (product.Priority < 1 || string.IsNullOrWhiteSpace(product.Name) || product.Quantity < 1) { return(Redirect("create")); } using (var db = new ShoppingListDbContext()) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Create(Product product) { if (product == null) { return(RedirectToAction("Index")); } if (string.IsNullOrWhiteSpace(product.Name) || string.IsNullOrWhiteSpace(product.Status) || product.Priority == null || product.Quantity == null) { ViewBag.message = "Попълни полетата!"; return(View(product)); } using (var db = new ShoppingListDbContext()) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult EditConfirm(int?id, Product productModel) { if (ModelState.IsValid) { using (ShoppingListDbContext db = new ShoppingListDbContext()) { Product productFromDb = db.Products.Find(productModel.Id); if (productFromDb != null) { productFromDb.Priority = productModel.Priority; productFromDb.Name = productModel.Name; productFromDb.Quantity = productModel.Quantity; productFromDb.Status = productModel.Status; db.SaveChanges(); } } } return(RedirectToAction("Index")); }
public ActionResult EditConfirm(int?id, Product productModel) { if (!ModelState.IsValid) { return(View(productModel)); } using (var db = new ShoppingListDbContext()) { var productFromDb = db.Products.Find(productModel.Id); if (productFromDb != null) { productFromDb.Priority = productModel.Priority; productFromDb.Quantity = productModel.Quantity; productFromDb.Name = productModel.Name; db.SaveChanges(); } } return(Redirect("/")); }
public ActionResult EditConfirm(int?id, Product productModel) { if (!ModelState.IsValid) { return(RedirectToAction("Create")); } using (var db = new ShoppingListDbContext()) { var product = db.Products.First(p => p.Id == id); product.Name = productModel.Name; product.Priority = productModel.Priority; product.Quantity = productModel.Quantity; product.Status = productModel.Status; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult EditConfirm(int?id, Product productModel) { if (ModelState.IsValid) { using (var db = new ShoppingListDbContext()) { var product = db.Products.Find(id); if (product == null) { return(RedirectToAction("index", "Product")); } product.Name = productModel.Name; product.Priority = productModel.Priority; product.Quantity = productModel.Quantity; product.Status = productModel.Status; db.SaveChanges(); } return(RedirectToAction("index", "Product")); } return(RedirectToAction("Edit", "Product")); }