public ActionResult Create(ProductType producttype) { if (ModelState.IsValid) { producttypeRepository.InsertOrUpdate(producttype); producttypeRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(ProductType producttype) { if (producttype.Id == default(System.Guid)) { // New entity producttype.Id = Guid.NewGuid(); context.ProductTypes.Add(producttype); } else { // Existing entity context.Entry(producttype).State = EntityState.Modified; } }