Add multiple records setting properties using an index
<p>I have a table full of checkboxes, and at the top there's a select all checkbox.  Once clicked, I am making an ajax call that passes in a list of invoice_ids as well as the check_run_id of another table. What I'm having difficulty with is setting the property of an object based on the index of the list of invoices. The code will probably explain better. Thanks for any help. </p>

<pre><code>public static void SaveInvoicesForPayment(List&lt;int&gt; invoiceIDs, int checkRunID)
    {
        using (MiniProfiler.Current.Step("SaveInvoices()"))
        using (var context = rempscoDataContext.CreateContext())
        {
            toSave = invoiceIDs.Where(i =&gt; i &gt; 0);
            var toDelete = invoiceIDs.Where(i =&gt; i &lt; 0).Select(i =&gt; -i);
            toSave = toSave.Where(i =&gt; !toDelete.Contains(i));

            var db_invoice_to_update = context.vendor_invoices.Where(si =&gt; toDelete.Contains(si.invoice_id));
            var db_check_run_details_to_delete = context.check_run_details.Where(crd =&gt; crd.check_run_id == checkRunID);

            db_invoice_to_update.ToList().ForEach(vi =&gt; { vi.check_run_id = null; });
            db_check_run_details_to_delete.ToList().ForEach(crd =&gt; {
                crd.bank_draft_id = null;
                crd.is_active = false;
            });

            var invoice_to_save = context.vendor_invoices.Where(si =&gt; toSave.Contains(si.invoice_id)).ToList();
            foreach (var crd in invoice_to_save)
            {
                context.check_run_details.InsertOnSubmit(new check_run_detail
                {
                    invoice_id = crd.invoice_id,
                    check_run_id = checkRunID,
                    add_user = Security.CurrentUser,
                    add_date = DateTime.Now,
                    edit_user = Security.CurrentUser,
                    edit_date = DateTime.Now,
                    invoice_amount = **invoice_to_save[index??],**
                    is_active = true,

                });
            }

            context.SubmitChanges();
        }
    }
</code></pre>

<p>Here's the ajax call as well just in case: </p>

<pre><code>function doSaveInvoices($parent, checked) {
var $invoiceCheckBoxes = $parent.find('input.invoice[type="checkbox"]');
var checkRunID = $("#checkRunID").val();
var invoiceIDs = [];
if (checked) {
    $invoiceCheckBoxes.each(function (i, c) {
        var $checkbox = $(this);
        invoiceIDs.push($checkbox.attr('invoice_id'));
        $checkbox.attr('checked', true);

    });
}
else {
    $invoiceCheckBoxes.each(function (i, c) {
        var $checkbox = $(this);
        invoiceIDs.push(-$checkbox.attr('invoice_id'));
        $checkbox.attr('checked', false);
    });
}

var js = JSON.stringify({ invoiceIDs: invoiceIDs, checkRunID: checkRunID });

$.ajax({
    url: './PayInvoicesWS.asmx/SaveInvoices',
    data: js,
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    type: "POST",
    success: function (data) {
        calculateTotal();
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        sendErrorEmail(window.location.href, 'SaveInvoices', XMLHttpRequest);;
    }
});
</code></pre>