public Car GetCarById(string id) { Car car = new Car(); int idConverted; bool success = int.TryParse(id, out idConverted); if (success == false) { throw new WebFaultException <string>("Please input a number instead ", HttpStatusCode.BadRequest); } try { car = dataBaseRepository.GetCarById(idConverted); } catch (Exception ex) { SaveException.Log("webErrors.txt", ex); throw new WebFaultException <string>("Sorry something went wrong when trying to get car from Database ", HttpStatusCode.InternalServerError); } if (car == null) { throw new WebFaultException <string>("Sorry no car found at positon" + id, HttpStatusCode.InternalServerError); } return(car); }
public Car GetCarById(int id) { Car car = dataBaseRepository.GetCarById(id); if (car == null) { throw new FaultException("Sorry no car found"); } return(car); }