Ejemplo n.º 1
0
        public static async Task InsertNewOfferBankAsync(Offer offer, Bank bank)
        {
            using (var context = new BankLoansEntities())
            {
                //add instances to context
                context.Banks.Add(bank);
                context.Offers.Add(offer);

                // add instance to navigation property
                offer.Banks.Add(bank);

                //call SaveChanges from context to confirm inserts
                await context.SaveChangesAsync();
            }
        }
Ejemplo n.º 2
0
        public static async Task InsertExistingOfferBankAsync(int offerId, int bankId)
        {
            using (var context = new BankLoansEntities())
            {
                var offer = new Offer {
                    PK_OfferId = offerId
                };
                context.Offers.Add(offer);
                context.Offers.Attach(offer);

                var bank = new Bank {
                    PK_RegNumber = bankId
                };
                context.Banks.Add(bank);
                context.Banks.Attach(bank);

                offer.Banks.Add(bank);

                await context.SaveChangesAsync();
            }
        }