private void SavePayPalInvoice(Guid reconnectToOurBuyer, PayPal.Api.Payments.Payment createdInvoice) { // we will retrieve this so that PayPal can apply, // i.e., "execute", the invoice that the customer // has approved. For this example, we are using // Entity Framework 6.0.2 with Code First. TinyInvoice invoiceToSave = new TinyInvoice(); invoiceToSave.ReconnectToOurBuyer = reconnectToOurBuyer; invoiceToSave.PayPalPayment_Identifier = createdInvoice.id; using (ArgumentsPlus.Controllers.ArgumentPlusContext argumentsPlusDb = new ArgumentPlusContext()) { argumentsPlusDb.TinyInvoices.Add(invoiceToSave); argumentsPlusDb.SaveChanges(); } }
private PayPal.Api.Payments.Payment GetSavedPayPalInvoice(string id) { Guid savedInvoiceKey = new Guid(); // will be all zeros try { savedInvoiceKey = new Guid(id); } catch (Exception) // could happen; probability low { // todo for now ignore ==> TIMTOWTDI } // PayPal.Api.Payments.Payment createdInvoice = new PayPal.Api.Payments.Payment(); // scope outside using // ................................ using (ArgumentsPlus.Controllers.ArgumentPlusContext argumentsPlusDb = new ArgumentPlusContext()) { var approvedPayPalPayment = argumentsPlusDb.TinyInvoices// define the query .Where(guid => guid.ReconnectToOurBuyer == savedInvoiceKey); var getOnePayPalPendingPayment = approvedPayPalPayment.ToList(); // .ToList() will force the query to hit the database Int32 numberOfInvoices = getOnePayPalPendingPayment.Count; // should be ZERO or ONE if (numberOfInvoices == 1) { createdInvoice.id = getOnePayPalPendingPayment[0].PayPalPayment_Identifier; } // if (numberOfInvoices == 1) else // should ALWAYS be ONE !!!!!!!!! { throw new NotImplementedException(); // todo "well, this is embarrassing" } } return createdInvoice; }