コード例 #1
0
        //form new car
        public ActionResult AddNewCarForm(Customer customer)
        {
            SingleCustomerCarViewModel viewModel = new SingleCustomerCarViewModel
            {
                GetCustomer = customer
            };

            return(View(viewModel));
        }
コード例 #2
0
        public ActionResult AddNewCarForm(ApplicationUser applicationUser)
        {
            SingleCustomerCarViewModel viewmodel = new SingleCustomerCarViewModel
            {
                GetCustomer = applicationUser
            };

            return(View(viewmodel));
        }
コード例 #3
0
        public ActionResult AddNewCar(SingleCustomerCarViewModel viewModel)
        {
            viewModel.GetCar.CustomerId = viewModel.GetCustomer.Id;
            var customer = _context.Customers.Find(viewModel.GetCustomer.Id);
            var car      = viewModel.GetCar;

            _context.Cars.Add(car);
            _context.SaveChanges();
            return(RedirectToAction("ViewCars", "Home", customer));
        }
コード例 #4
0
 public ActionResult Addnewcar(SingleCustomerCarViewModel viewmodel)
 {
     if (!ModelState.IsValid)
     {
         return(View("AddNewCarForm", viewmodel));
     }
     else
     {
         viewmodel.GetCar.ApplicationUserId = viewmodel.GetCustomer.Id;
         var customer = _context.Users.Find(viewmodel.GetCustomer.Id);
         var car      = viewmodel.GetCar;
         _context.Cars.Add(car);
         _context.SaveChanges();
         return(RedirectToAction("viewcars", "home", customer));
     }
 }