public int ManufacturerDuplicationCheck(Manufacturer manufacturer) { List<Manufacturer> _manufacturer = (from m in db.Manufacturers where m.ManufacturerName == manufacturer.ManufacturerName select m).ToList(); return _manufacturer.Count; }
public ActionResult Create(Manufacturer manufacturer) { if (ModelState.IsValid) { //check if duplication exists int count = repo.ManufacturerDuplicationCheck(manufacturer); //if yes throw an error message if (count > 0) { ViewBag.DuplicateError = "Already Exists!!"; return View(manufacturer); } else { //else add new manufacturer and return to Index db.Manufacturers.Add(manufacturer); db.SaveChanges(); return RedirectToAction("Index"); } } return View(manufacturer); }
public void InsertBulk(FormCollection coll) { /* Manufacturer m = new Manufacturer(); m.ManufacturerName = coll["ManufacturerName"]; m.Description = coll["Description"]; db.Manufacturers.Add(m); db.SaveChanges(); */ string[] _name = coll["ManufacturerName"].Split(','); string[] _description = coll["Description"].Split(','); int count = _name.Count(); for (int i = 0; i < count; i++) { Manufacturer manu = new Manufacturer(); manu.ManufacturerName = _name[i]; manu.Description = _description[i]; db.Manufacturers.Add(manu); db.SaveChanges(); } /* By Dixanta sir * * foreach (var item in coll.Get("ManufacturerName").Split(",".ToArray())) { Response.Write(item); }*/ /*int count = coll.Count; if (count == 0) { return View("ChamForm", "Test"); } else { for (int i = 0; i < count; i++) { Manufacturer m = new Manufacturer(); m.ManufacturerName = coll["ManufacturerName[""]; m.Description = coll["Description[" + i + "]"]; db.Manufacturers.Add(m); db.SaveChanges(); } }*/ }
public ActionResult ChamForm() { Manufacturer m = new Manufacturer(); return View(m); }