public HttpResponseMessage GetUserCars(string userId) { if (!isUserIdEqualToLoggedInUser(userId)) { var message = string.Format("Permission denied"); HttpError err = new HttpError(message); return(Request.CreateResponse(HttpStatusCode.Unauthorized, err)); } else { if (userBusiness.GetActiveUser(userId) == null) { var response = string.Format("User not found"); HttpError err = new HttpError(response); return(Request.CreateResponse(HttpStatusCode.NotFound, err)); } else { List <GetCarDto> usercars = new List <GetCarDto>(); foreach (Car car in carBusiness.GetAllUserCars(userId)) { GetCarDto getCarDto = new GetCarDto(car); usercars.Add(getCarDto); } return(Request.CreateResponse(HttpStatusCode.OK, usercars)); } } }