Esempio n. 1
0
 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));
 }
Esempio n. 2
0
        public SimplePartViewModel SetPartFormGetModel(int id)
        {
            SimplePartViewModel simplePartViewModel = new SimplePartViewModel
            {
                CarId = id
            };

            return(simplePartViewModel);
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public ActionResult AddPart(int id)
        {
            SimplePartViewModel simplePartViewModel = _partService.SetPartFormGetModel(id);

            return(View(simplePartViewModel));
        }