public AllPartsViewModel ShowAllPartsForCarById(int id) { var data = this.Context.Parts.Where(x => x.Id == id).ToArray(); AllPartsViewModel allPartsViewModel = new AllPartsViewModel(); List <SimplePartViewModel> listOfPartViewModels = new List <SimplePartViewModel>(); foreach (var item in data) { //AutoMapper map our ViewModel to Entity SimplePartViewModel simplePartViewModel = Mapper.Map <Part, SimplePartViewModel>(item); listOfPartViewModels.Add(simplePartViewModel); } allPartsViewModel.AllParts = listOfPartViewModels; return(allPartsViewModel); }
public ActionResult ShowAllParts(int id) { AllPartsViewModel allPartsViewModel = _partService.ShowAllPartsForCarById(id); return(View(allPartsViewModel)); }