public ActionResult Create(CarAdd newItem) { if (ModelState.IsValid) { var addedItem = m.AddCar(newItem); } else { return(View(newItem)); } return(RedirectToAction("index")); }
//adding method public CarFull AddCar(CarAdd newItem) { //New id int newId = (cars.Count > 0) ? newId = cars.Max(id => id.Id) + 1 : 1; //new item var addedItem = new CarFull { Id = newId, Manufacturer = newItem.Manufacturer, Model = newItem.Model, MSRP = newItem.MSRP, Year = newItem.Year }; //Add new item cars.Add(addedItem); //return value return(addedItem); }