Пример #1
0
        public ActionResult Create([Bind(Include = "ID,ManufacturerName,Description")] Manufacturer manufacturer)
        {
            if (ModelState.IsValid)
            {
                int count = repo.ManufacturerDuplicationCheck(manufacturer);

                if (count > 0)
                {
                    ViewBag.DuplicateError = "Already Exists!!";
                    return(View(manufacturer));
                }
                else
                {
                    db.Manufacturer.Add(manufacturer);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            return(View(manufacturer));
        }
        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));
        }