public ActionResult AddPart([Bind(Include = "Id,Name,Manufacturer,Price,PartBuyedFrom,DateOfPurchase,ExpectedDateOfDelivery,IsPartInstalled,CarId")] SimplePartViewModel simplePartViewModel) { if (ModelState.IsValid) { _partService.AddNewPart(simplePartViewModel); return(RedirectToAction("AddPart", "Part")); } return(View(simplePartViewModel)); }
public SimplePartViewModel SetPartFormGetModel(int id) { SimplePartViewModel simplePartViewModel = new SimplePartViewModel { CarId = id }; return(simplePartViewModel); }
public void AddNewPart(SimplePartViewModel simplePartViewModel) { var data = this.Context.Parts.ToArray(); //AutoMapper Mapped Part part = Mapper.Map <SimplePartViewModel, Part>(simplePartViewModel); this.Context.Parts.Add(part); this.Context.SaveChanges(); }
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 AddPart(int id) { SimplePartViewModel simplePartViewModel = _partService.SetPartFormGetModel(id); return(View(simplePartViewModel)); }