// GET: Bil public ActionResult Index() { var model = new ViewModels.BilIndexViewModel(); var db = new Models.DBContext(); model.Cars.AddRange(db.GetAll().Select(r => new ViewModels.BilIndexViewModel.BilListViewModel { Manufacturer = r.Manufacturer, Model = r.Model, Year = r.Year, Id = r.Id })); return(View(model)); }
public ActionResult Search(string SearchManufacturer, string SearchYear) { var db = new Models.DBContext(); var model = new ViewModels.BilIndexViewModel { SearchManufacturer = SearchManufacturer, SearchYear = SearchYear }; model.Cars.AddRange(db.GetAll().Select(r => new ViewModels.BilIndexViewModel.BilListViewModel { Manufacturer = r.Manufacturer, Model = r.Model, Year = r.Year, Id = r.Id }).Where(c => Matches(c, SearchManufacturer, SearchYear) )); return(View("Index", model)); }
public ActionResult Create(ViewModels.BilCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var db = new Models.DBContext(); var newId = db.GetAll().Max(r => r.Id) + 1; var bil = new Models.Bil { Id = newId, Color = model.Color, Manufacturer = model.Manufacturer, Model = model.Modell, Year = model.Year }; db.AddBil(bil); return(RedirectToAction("Index")); }