public MembershipCreateStatus UpdateCustomer(ExtendedCustomer customer) { try { using (var db = new JONEntities()) { var existingCustomer = db.usr_CUSTOMERS.Where(x => x.email == customer.Email).SingleOrDefault(); var source = new MergeExistingCustomerAndExtendedCustomer(); source.First = existingCustomer; source.Second = customer; var customerdto = mapper.Map <MergeExistingCustomerAndExtendedCustomer, usr_CUSTOMERS>(source); db.usr_CUSTOMERS.Detach(existingCustomer); db.usr_CUSTOMERS.Attach(customerdto); db.ObjectStateManager.ChangeObjectState(customerdto, EntityState.Modified); // db.usr_CUSTOMERS.AddObject(customerdto); db.SaveChanges(); return(MembershipCreateStatus.Success); } } catch (Exception ex) { return(MembershipCreateStatus.ProviderError); } }
public MembershipCreateStatus UpdateCustomer(ExtendedCustomer customer) { try { using (var db = new JONEntities()) { var existingCustomer = db.usr_CUSTOMERS.Where(x => x.email == customer.Email).SingleOrDefault(); var source = new MergeExistingCustomerAndExtendedCustomer(); source.First = existingCustomer; source.Second = customer; var customerdto = mapper.Map<MergeExistingCustomerAndExtendedCustomer, usr_CUSTOMERS>(source); db.usr_CUSTOMERS.Detach(existingCustomer); db.usr_CUSTOMERS.Attach(customerdto); db.ObjectStateManager.ChangeObjectState(customerdto, EntityState.Modified); // db.usr_CUSTOMERS.AddObject(customerdto); db.SaveChanges(); return MembershipCreateStatus.Success; } } catch (Exception ex) { return MembershipCreateStatus.ProviderError; } }