public ActionResult Create() { var vehicleModel = new VehicleModel(); PopulateVehicleModel(vehicleModel); vehicleModel.Status = true; return View(vehicleModel); }
public ActionResult Create(VehicleModel model) { if (!ModelState.IsValid) { PopulateVehicleModel(model); return View(model); } try { var vehicle = ModelMapper.GetVehicle(model); vehicle.IsVehicle = Convert.ToBoolean(model.VehicleOrMachine); vehicleService.AddNewVehicle(vehicle); return RedirectToAction("Index"); } catch { PopulateVehicleModel(model); return View(model); } }
private VehicleModel PopulateVehicleModel(VehicleModel model) { var fuelTypes = vehicleService.GetAllFuelTypes(); var lubricantTypes = vehicleService.GetAllLubricantTypes(); var vehicleTypes = vehicleService.GetAllVehicleTypes(); model.AvailableFuel = ModelMapper.GetFuelModelList(fuelTypes); model.AvailableLubricants = ModelMapper.GetLubricantModelList(lubricantTypes); model.AvailableVehicleTypes = ModelMapper.GetVehicleTypeModelList(vehicleTypes); return model; }
public static Vehicle GetVehicle(VehicleModel model) { return new Vehicle() { Id = model.Id, VehicleNumber = model.VehicleNumber, CompanyCode = model.CompanyCode, VehicleTypeId = model.VehicleTypeId, VehicleTypeName = model.VehicleTypeName, Description = model.Description, DriverOperatorName = model.DriverOperatorName, FuelUsage = model.FuelUsage, FuelType = model.FuelTypeId, FuelTypeName = model.FuelTypeName, LubricantType = model.LubricantTypeId, LubricantTypeName = model.LubricantTypeName, IsHiredVehicle = model.IsHiredVehicle, HireRate = model.HireRate, OwnerName = model.OwnerName, IsVehicle = model.IsVehicle, Status = model.Status }; }