使用索引添加多个记录设置属性

时间:2016-10-24 22:12:35

标签: c# jquery ajax entity-framework

我的桌子上装满了复选框,顶部有一个全选复选框。点击后,我正在进行一个ajax调用,该调用传入invoice_ids列表以及另一个表的check_run_id。我遇到的困难是根据发票清单的索引设置对象的属性。代码可能会更好地解释。谢谢你的帮助。

GoogleApiClient.connect();

以下是ajax调用以防万一:

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

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

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

            var invoice_to_save = context.vendor_invoices.Where(si => 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();
        }
    }

0 个答案:

没有答案