public CustomerInfo GetCustomer(CustomerRequest customerRequest) { var customer = dataBaseRepository.GetCustomer(customerRequest); if (customer == null) { throw new FaultException("Sorry no car customer found"); } return(customer); }
public CustomerInfo GetCustomer(string customerId, string license) { int id; bool success = int.TryParse(customerId, out id); if (success == false) { throw new WebFaultException <string>("Please input a number instead ", HttpStatusCode.BadRequest); } CustomerInfo customerInfo = new CustomerInfo(); CustomerRequest customerRequest = new CustomerRequest(); customerRequest.LicenseKey = license; customerRequest.CustomerId = id; try { customerInfo = dataBaseRepository.GetCustomer(customerRequest); } catch (FaultException ex) { throw new WebFaultException <string>(ex.Reason.ToString(), HttpStatusCode.BadRequest); } catch (Exception ex) { SaveException.Log("webErrors.txt", ex); throw new WebFaultException <string>("Sorry something went wrong when trying to get customer from Database ", HttpStatusCode.InternalServerError); } if (customerInfo == null) { throw new WebFaultException <string>("Sorry no customer found at position " + customerId, HttpStatusCode.InternalServerError); } return(customerInfo); }