public ActionResult Create([Bind(Include = "name")] Supplier supplier) { do { supplier.id = new Random().Next(); } while (db.Suppliers.Where(x => x.id == supplier.id).ToList().Count > 0); if (db.Suppliers.Any(x => x.name == supplier.name && x.id != supplier.id)) { ModelState.AddModelError("name", "Taki dostawca już istnieje"); } if (ModelState.IsValid) { db.Suppliers.Add(supplier); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
public void Insert(T obj) { table.Add(obj); _context.SaveChanges(); }