Example #1
0
        public string SaveCustomer(Customer customer)
        {
            try
            {
                using (var context = new BAPOCOs())
                {
                    context.ContextOptions.LazyLoadingEnabled = false;
                    //Add the customer graph into the context

                    context.Contacts.Attach(customer);

                    context.ObjectStateManager.ChangeObjectState(customer, StateHelpers.GetEquivalentEntityState(customer.State));

                    foreach (Reservation reservation in customer.Reservations.ToList())
                    {
                        context.ObjectStateManager.ChangeObjectState(reservation, StateHelpers.GetEquivalentEntityState(reservation.State));
                    }
                    context.SaveChanges();
                    return("OK");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Example #2
0
        public string SaveCustomer(Customer cust)
        {
            try
            {
                using (BAPOCOs context = new BAPOCOs())
                {
                    // context.ContextOptions.LazyLoadingEnabled = false;

                    context.Contacts.ApplyChanges(cust);
                    context.SaveChanges();
                    return("");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }