public async Task <IActionResult> AddOwner([Bind("UserName,FirstName, LastName, Email, Telephone")] Owner owner) { if (ModelState.IsValid) { _context.Add(owner); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(OwnerIndex))); } return(View(owner)); }
public async Task <IActionResult> Create([Bind("GarageId,GarageName,NumberOfParkingPlaces")] Garage garage) { if (ModelState.IsValid) { dbGarage.Add(garage); await dbGarage.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(garage)); }
public async Task <IActionResult> AddVehicle(int?id, [Bind("RegNum,Wheels,Model,Brand,ColorName,VehicleType")] AddVehicleViewModel viewModel) { if (ModelState.IsValid) { var vehicle = new Vehicle { RegNum = viewModel.RegNum.ToUpper(), Wheels = viewModel.Wheels, Model = viewModel.Model, Brand = viewModel.Brand }; int tempColorId = ColorSetup(viewModel.ColorName); vehicle.ColorId = tempColorId; vehicle.Color = _context.Colors.Find(tempColorId); int tempTypeId = VehicleTypeSetup(viewModel.VehicleType); vehicle.TypeID = tempTypeId; vehicle.VehicleType = _context.VehicleTypes.Find(tempTypeId); vehicle.MemberNumber = (int)id; vehicle.Owner = _context.Owners.Find((int)id); if (vehicle.Color != null && vehicle.VehicleType != null && vehicle.Owner != null) { _context.Add(vehicle); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } return(View(viewModel)); }