public void Update(Shipping_Catalog_ProductsViewModel product) { if (!UpdateDatabase) { var target = One(e => e.ProductID == product.ProductID); if (target != null) { target.ProductID = product.ProductID; target.ProductName = product.ProductName; target.AreaID = product.AreaID; target.WOrder = product.WOrder; target.TIDSerie = product.TIDSerie; target.WKRMSerie = product.WKRMSerie; target.ProductType = product.ProductType; } } else { var entity = new Shipping_Catalog_Products(); entity.ProductID = product.ProductID; entity.ProductName = product.ProductName; entity.AreaID = product.AreaID; entity.WOrder = product.WOrder; entity.TIDSerie = product.TIDSerie; entity.WKRMSerie = product.WKRMSerie; entity.ProductType = product.ProductType; entities.Shipping_Catalog_Products.Attach(entity); entities.Entry(entity).State = EntityState.Modified; entities.SaveChanges(); } }
public void Create(Shipping_Catalog_ProductsViewModel product) { if (!UpdateDatabase) { var first = Read().OrderByDescending(s => s.ProductID).FirstOrDefault(); var id = (first != null) ? first.ProductID : 0; product.ProductID = id + 1; GetAll().Insert(0, product); } else { var entity = new Shipping_Catalog_Products(); entity.ProductID = product.ProductID; entity.ProductName = product.ProductName; entity.AreaID = product.AreaID; entity.WOrder = product.WOrder; entity.WKRMSerie = product.WKRMSerie; entity.TIDSerie = product.TIDSerie; entity.ProductType = product.ProductType; entities.Shipping_Catalog_Products.Add(entity); entities.SaveChanges(); //product.ProductID = entity.ProductID; } }
public ActionResult Create([Bind(Include = "AreaID,ProductName,WOrder,WKRMSerie,TIDSerie,ProductType")] Shipping_Catalog_ProductsViewModel Products) { if (Products.ProductName != null && Products.ProductType != null) { _shipping.Create(Products); ModelState.Clear(); ViewBag.showMs = 1; return(View("Index")); } else { ViewBag.showMs = 2; return(View("Index", Products)); } }
public ActionResult Update([DataSourceRequest] DataSourceRequest request, Shipping_Catalog_ProductsViewModel Products) { try { if (ModelState.IsValid) { _Service.Update(Products); } } catch (Exception ex) { if (ex.InnerException.InnerException.Message.Contains("UNIQUE KEY constraint")) { } else { ModelState.AddModelError("", ex.Message); } } return(Json(new[] { Products }.ToDataSourceResult(request, ModelState))); }