public int CreateCarType(RentalCarTypeCreateRequest request) { using (var con = GetConnection()) { var cmd = con.CreateCommand(); cmd.CommandText = "CarTypes_Insert"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CarType", request.CarType); cmd.Parameters.Add("@Id", SqlDbType.Int).Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); return((int)cmd.Parameters["@Id"].Value); } }
public HttpResponseMessage PostCreateCarType(RentalCarTypeCreateRequest rentalCarType) { if (rentalCarType == null) { ModelState.AddModelError("", "Missing body data"); } if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } int newCarTypeId = rentalCarsService.CreateCarType(rentalCarType); string statusMessage = "New Rental Car Type ID: " + newCarTypeId; return(Request.CreateResponse(HttpStatusCode.OK, statusMessage)); }