In my application, I'm trying to edit items of an invoice. Due to a complication I elected to remove the original items from the many to many table and re-insert the updated items.
In my code, I have two objects, the original invoice and the updated invoice. Both are identical because they are both from the same ViewState object. When I to edit the updated invoice object, I find out that the original invoice object was updated as well.
Note that the invoice object and the item objects are both serialize capeable so I can use them in the ViewState.
Is my visual studio acting up or is there a logic behind this?
EDIT
BankCheque originalCheque = (BankCheque)ViewState["OriginalCheque"];
BankCheque cheque = (BankCheque)ViewState["OriginalCheque"];
cheque.chequeCode = tb_chequeCode.Text;
cheque.client = new Client();
cheque.client.clientID = hidden_clientId.Value;
cheque.chequeIssueDate = DateTime.Parse(tb_issueDate.Text);
cheque.chequePaymentDate = DateTime.Parse(tb_paymentDate.Text);
cheque.chequeAmount = float.Parse(tb_chequeValue.Text);
if (cb_chequePaid.Checked)
{
cheque.paid = 1;
}
else
{
cheque.paid = 0;
}
cheque.invoices = getNewInvoicesList();
cheque = addPaymentsToCheque(cheque);
The getNewInvoicesList method is
private List<ClientInvoice> getNewInvoicesList()
{
DataTable dt = (DataTable)ViewState["invoicesDt"];
List<ClientInvoice> invoices = new List<ClientInvoice>();
ClientInvoice invoice;
foreach (DataRow row in dt.Rows)
{
invoice = new ClientInvoice();
invoice.invoiceID = Convert.ToInt32(row[0].ToString());
invoices.Add(invoice);
}
return invoices;
}