public List <Model.Common.Payment> GetPayment() { List <Model.Common.Payment> Items = new List <Model.Common.Payment>(); try { using (var dBContext = new CustomerReportContext()) { Model.Common.Payment Pay; foreach (var it in dBContext.TblPayment) { Pay = new Model.Common.Payment(); Pay.PaymentNo = it.PaymentNo; Pay.PaymentDate = it.PaymentDate; Pay.PaymentAmount = it.PaymentAmount; Pay.InvoiceNo = it.InvoiceNo; Items.Add(Pay); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(Items); }
public int AddPaymentData(Model.Common.Payment PaymentModel, string PaymentNo) { List <Payment> Items = new List <Payment>(); List <Invoice> InvItems = new List <Invoice>(); int returnVal = 0; try { using (var dBContext = new CustomerReportContext()) { Model.Common.Payment get; foreach (var it in dBContext.TblPayment) { get = new Model.Common.Payment(); get.PaymentNo = it.PaymentNo; get.InvoiceNo = it.InvoiceNo; get.PaymentDate = it.PaymentDate; get.PaymentAmount = it.PaymentAmount; Items.Add(get); } TblPayment Cust; //Add record Cust = new TblPayment(); Cust.PaymentNo = PaymentModel.PaymentNo; Cust.InvoiceNo = PaymentModel.InvoiceNo; Cust.PaymentDate = PaymentModel.PaymentDate; Cust.PaymentAmount = PaymentModel.PaymentAmount; dBContext.TblPayment.Add(Cust); PaymentNo = Cust.PaymentNo; bool Invoicexist = Items.Any(asd => asd.PaymentNo == PaymentNo); if (Invoicexist == true) { returnVal = -1; } else { returnVal = dBContext.SaveChanges(); } //using (var ddBContext = new CustomerReportContext()) //{ // Model.Common.Invoice Inv = new Model.Common.Invoice(); // foreach (var iit in ddBContext.TblInvoices) // { // Inv.InvoiceNo = iit.InvoiceNo; // Inv.InvoiceAmount = iit.InvoiceAmount; // Inv.InvoiceDate = iit.InvoiceDate; // Inv.PaymentDueDate = iit.PaymentDueDate; // InvItems.Add(Inv); // } // bool InvoicAmount = Items.Any(asd => asd.PaymentAmount > Inv.InvoiceAmount); // if (InvoicAmount == true) // { // returnVal = -2; // } //} //returnVal = dBContext.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(returnVal); }