public CarPartsAllViewModel GetAllCarsById(int id) { CarPartsAllViewModel cpvm = new CarPartsAllViewModel(); var item = this.Context.Cars.Where(s => s.Id == id).First(); CarPartsViewModel model = new CarPartsViewModel() { Id = item.Id, Make = item.Make, Model = item.Model, TravellDistance = item.TravelledDistance, //SHould set Parts }; foreach (var i in item.Parts) { PartsViewModel view = new PartsViewModel() { Name = i.Name, Price = i.Price }; model.Parts.Add(view); } cpvm.CarParts = model; return(cpvm); }
public ActionResult CarParts(int id) { CarPartsAllViewModel cpavm = this.carsService.GetAllCarsById(id); return(this.View(cpavm)); }