public ActionResult AddMotorcycle(NewMotorcycleModel model) { if (!model.ValidOtherBrand()) { ModelState.AddModelError("OtherBrand", "Please enter a new brand"); } if (ModelState.IsValid) { int id = ProductAddHelper.AddMotorcycleProduct(model); return Json(String.Format(PathConstants.Pages.ReviewPathWithProductId, "Index", id.ToString())); } List<string> engineTypes = ProductAddHelper.AllEngineTypes(); engineTypes.Insert(0, "Select"); ViewBag.EngineType = new SelectList(engineTypes, model); List<string> subcategories = ProductAddHelper.AllGearSubcategories(); subcategories.Insert(0, "Select"); ViewBag.Subcategories = new SelectList(subcategories, model.Subcategory); List<string> brands = ProductAddHelper.AllBrands("GEAR"); brands.Insert(0, "Select"); brands.Insert(brands.Count(), "Other.."); ViewBag.Brands = new SelectList(brands, model.Brand); throw new Exception("Errors occured while processing your form"); return View(model); }
internal static int AddMotorcycleProduct(NewMotorcycleModel model) { Data.Product dbProduct = ConvertNewGearToDbProduct(model, "MOTORCYCLE"); int id = MappingSearch.Data.Accessors.ProductsAccessor.AddNewGearProduct(dbProduct); Data.Motorcycle dbMotorcycle = ConvertNewMotorcycleToDbMotorcycle(model,id); MappingSearch.Data.Accessors.ProductsAccessor.AddNewMotorcycle(dbMotorcycle); return id; }
private static Motorcycle ConvertNewMotorcycleToDbMotorcycle(NewMotorcycleModel model, int id) { Motorcycle m = new Motorcycle(); m.Displacement = model.Displacement; m.EngineType = model.EngineType; m.Gears = model.Gears; m.TopSpeed = model.TopSpeed; m.Torque = model.Torque; m.ProductId = id; return m; }