private void AddVehicle() { Vehicle vehicle; var plate = _ioHelper.GetTextFromUser("Enter the licence plate"); if (_vehiclesService.FindByPlate(plate)) { _ioHelper.DisplayInfo("Vehicle with given plates number already exists!\n", MessageType.Error); return; } vehicle = new Vehicle() { Make = _ioHelper.GetTextFromUser("Enter vehicle\'s make"), Model = _ioHelper.GetTextFromUser("Enter vehicle\'s model"), Plate = plate, Capacity = _ioHelper.GetUintFromUser("Enter vehicle\'s capacity [kg]"), }; do { vehicle.UserId = _usersService.GetUserId(_ioHelper.GetTextFromUser("Enter courier\'s email")); } while (!_usersService.CheckIfValidCourier(vehicle.UserId) || vehicle.UserId == 0); _vehiclesService.Add(vehicle); _ioHelper.DisplayInfo("Vehicle added successfully!\n", MessageType.Success); }
public IActionResult CreateVehicle([FromBody] SaveVehicleResource saveVehicleResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var vehicle = Mapper.Map <Vehicle>(saveVehicleResource); _vehicles.Add(vehicle); _vehicles.Save(); var result = Mapper.Map <VehicleResource>(_vehicles.GetById(vehicle.Id)); return(Ok(result)); }
public StatusCodeResult Add(VehicleCreationRequest input) { return(_service.Add(input.ToDomain()) ? (StatusCodeResult)Ok() : BadRequest()); }