public void removeTransaction() { using (MyDBContext db = new MyDBContext()) { db.Transactions.Attach(this); db.Transactions.Remove(this); db.SaveChanges(); } }
public void removeInvoice() { using (MyDBContext db = new MyDBContext()) { var transactions = db.Transactions.Where(x => x.invoiceId == invoiceId); db.Invoices.Attach(this); db.Invoices.Remove(this); db.SaveChanges(); foreach (var transaction in transactions) { transaction.removeTransaction(); } } }
public void removeCustomer() { using (MyDBContext db = new MyDBContext()) { var invoices = db.Invoices.Where(x => x.customerId == customerId); db.Customers.Attach(this); db.Customers.Remove(this); db.SaveChanges(); foreach (var invoice in invoices) { invoice.removeInvoice(); } } }
public ActionResult InvoiceList(int customerId) { List<InvoiceViewModel> invoiceList = new List<InvoiceViewModel>(); var dbInvoiceList = db.Invoices.Where(i => i.customerId == customerId); foreach (var invoice in dbInvoiceList) { using (MyDBContext dbCustomer = new MyDBContext()) { var customer = dbCustomer.Customers.Find(invoice.customerId); invoiceList.Add(new InvoiceViewModel { viewInvoiceId = invoice.invoiceId, viewCustomerName = customer.customerName, viewInvoiceDate = invoice.invoiceDate, viewCustomerAdress = customer.customerAdress, viewCustomerContact = customer.customerContact }); } } return PartialView("_invoiceList", invoiceList); }
public ActionResult InvoiceTransactions(int invoiceId) { List<Transaction> transactionList = db.Transactions.Where(t => t.invoiceId == invoiceId).ToList(); List<TransactionViewModel> viewTransactionList = new List<TransactionViewModel>(); foreach (var transaction in transactionList) { using (MyDBContext dbArticle = new MyDBContext()) { var article = dbArticle.Articles.Find(transaction.articleId); viewTransactionList.Add(new TransactionViewModel { viewTransactionId = transaction.transactionId, viewArticleName = article.articleName, viewPrice = article.articlePrice, quantity = transaction.quantity }); } } return PartialView("_invoiceTransactions", viewTransactionList); }