public ContractDeleteResponse deleteContract(int id) { ContractDeleteResponse response = new ContractDeleteResponse(); using (var conn = createConnection()) { try { conn.Open(); using (var cmd = new NpgsqlCommand(new SQLStatements().deleteContract(id), conn)) using (var reader = cmd.ExecuteReader()) { response = validateDelete(reader, id); } } catch (Exception e) { var resp = new HttpResponseMessage(HttpStatusCode.BadRequest); resp.Content = new StringContent(e.Message); throw new HttpResponseException(resp); } } return(response); }
private ContractDeleteResponse validateDelete(NpgsqlDataReader reader, int contractId) { ContractDeleteResponse response = new ContractDeleteResponse(); if (reader.HasRows) { response.deleteSuccessful = true; response.deleteMessage = String.Format("Contract Id {0} deleted.", contractId); } else { var resp = new HttpResponseMessage(HttpStatusCode.BadRequest); resp.Content = new StringContent(String.Format("Error updating contract. {0}", contractId)); throw new HttpResponseException(resp); } return(response); }