public void SaveRso(SaveRsoRequest request) { ConnectionHelper conn = new ConnectionHelper(); SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@Name", request.Name), new SqlParameter("@Description", request.Description) }; int res = conn.ExecuteNonQuery("CreateRso", sqlParams); if (res > 0) { SqlParameter[] sqlParams2 = new SqlParameter[] { new SqlParameter("@RsoName", request.Name), }; int rsoId = -1; string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnection"].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = "GetRsoId"; command.Connection = connection; command.Parameters.AddRange(sqlParams2); try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { rsoId = reader.GetInt32(0); } } } catch (Exception ex) { } finally { connection.Close(); } } if (rsoId != -1) { SqlParameter[] sqlParams3 = new SqlParameter[] { new SqlParameter("@RsoId", rsoId), new SqlParameter("@StudentEmail", request.AdminEmail), new SqlParameter("@IsAdmin", 1) }; conn.ExecuteNonQuery("AddMemberToRso", sqlParams3); foreach (string m in request.Members) { SqlParameter[] sqlParams4 = new SqlParameter[] { new SqlParameter("@RsoId", rsoId), new SqlParameter("@StudentEmail", m), new SqlParameter("@IsAdmin", 0) }; conn.ExecuteNonQuery("AddMemberToRso", sqlParams4); } } } }