public ActionResult Create(ProductView productView) { var dateNow = DateTime.Now; if (productView.Product.AanmaakDatum == DateTime.MinValue) { // AanmaakDatum Datetime is not set productView.Product.AanmaakDatum = dateNow; } // Set edit date equal to now productView.Product.WijziginsDatum = dateNow; //var product = productView.Product; //var product = new Product(); //product = productView.Product; //product.Btw = productView.Btw; if (_db.Producten.Any(o => o.Nummer == productView.Product.Nummer)) { //Number is already used var mod = ModelState.First(c => c.Key == "Product.Nummer"); mod.Value.Errors.Add("Dit nummer is al in gebruik!"); } if (!ModelState.IsValid) { return View(productView); } _db.Producten.Add(productView.Product); _db.SaveChanges(); return RedirectToAction("Index"); }
// GET: Product/Create public ActionResult Create() { var oReturn = new ProductView { Product = _productDal.GetNewProduct() }; return View(oReturn); }
// GET: Product/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var productview = new ProductView { Product = _db.Producten.Find(id) }; if (productview.Product == null) { return HttpNotFound(); } return View(productview); }
public ActionResult Edit(ProductView productView) { productView.Product.WijziginsDatum = DateTime.Now; if (_db.Producten.Any(o => o.Nummer == productView.Product.Nummer && o.Id != productView.Product.Id)) { // Number is already used var mod = ModelState.First(c => c.Key == "Product.Nummer"); mod.Value.Errors.Add("Dit nummer is al in gebruik!"); } if (!ModelState.IsValid) { // Model is not valid! return View(productView); } _db.Entry(productView.Product).State = EntityState.Modified; _db.SaveChanges(); return RedirectToAction("Index"); }
/// <summary> /// Returns e singel Product view /// </summary> /// <param name="productId"></param> /// <returns></returns> public ProductView GetSingleProductView(int? productId) { //write query to output window _db.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); try { var oProduct = _db.Producten.Find(productId); var oBtw = _db.Btws.Find(oProduct.BtwId); var oProductgroep = _db.ProductGroepen.Find(oProduct.ProductgroepId); var oLeverancier = _db.Leveranciers.Find(oProduct.LeveranciersId); var oReturn = new ProductView { Product = oProduct, Btw = oBtw, ProductGroep = oProductgroep, Leverancier = oLeverancier }; return oReturn; } // TODO do something with the exception catch (Exception) { return new ProductView(); } }