private static int AddOrderContact(int orderID, OrderContact contact, OrderContactType type) { contact.OrderContactId = SQLDataHelper.GetInt(SQLDataAccess.ExecuteScalar( @"INSERT INTO [Order].[OrderContact] ([Name],[Country],[Zone],[City],[Zip],[Address]) VALUES (@Name,@Country,@Zone,@City,@Zip,@Address); SELECT scope_identity();", CommandType.Text, new SqlParameter("@Name", contact.Name ?? string.Empty), new SqlParameter("@Country", contact.Country ?? string.Empty), new SqlParameter("@Zone", contact.Zone ?? string.Empty), new SqlParameter("@City", contact.City ?? string.Empty), new SqlParameter("@Zip", contact.Zip ?? string.Empty), new SqlParameter("@Address", contact.Address ?? string.Empty) )); UpdateOrderContactId(orderID, contact.OrderContactId, type); return contact.OrderContactId; }
public static void UpdateOrderContactId(int orderId, int contactId, OrderContactType type) { SQLDataAccess.ExecuteNonQuery( string.Format("UPDATE [Order].[Order] SET [{0}] = @ContactID WHERE [OrderID] = @OrderID", type == OrderContactType.ShippingContact ? "ShippingContactID" : "BillingContactID"), CommandType.Text, new SqlParameter("@OrderID", orderId), new SqlParameter("@ContactID", contactId)); }