예제 #1
0
        private void SynchronizeProfile()
        {
            try
            {
                // Si esta conectado
                if (Connection.IsConnected)
                {
                    // Obtener el perfil remoto
                    CustomerClient customerClient = new CustomerClient(Connection.ServerBinding, new EndpointAddress(Connection.ServerUri + "Customer"));
                    CustomerEntity remoteCustomer = customerClient.GetCustomer(this.Customer.Id, true, Connection.Session);
                    // Y el perfil local
                    CustomerDataAccess customerDataAccess = new CustomerDataAccess();
                    CustomerEntity     localCustomer      = customerDataAccess.Load(this.Customer.Id, true);
                    // Si el perfil local es más nuevo que el remoto
                    if (localCustomer.Timestamp > remoteCustomer.Timestamp)
                    {
                        // Establecer los campos comunes
                        remoteCustomer.Name        = localCustomer.Name;
                        remoteCustomer.PhoneNumber = localCustomer.PhoneNumber;
                        remoteCustomer.Surname     = localCustomer.Surname;
                        remoteCustomer.UserName    = localCustomer.UserName;
                        remoteCustomer.Address     = localCustomer.Address;
                        // Establecer las preferencias
                        foreach (PreferenceEntity remotePreference in remoteCustomer.Preferences)
                        {
                            foreach (PreferenceEntity localPreference in localCustomer.Preferences)
                            {
                                if (remotePreference.IdCategory == localPreference.IdCategory)
                                {
                                    remotePreference.Active = localPreference.Active;
                                }
                            }
                        }

                        CustomerEntity returnCustomer = customerClient.Save(remoteCustomer, Connection.Session);
                        if (returnCustomer != null)
                        {
                            Debug.WriteLine("Internal application error saving remote customer.");
                        }
                        else
                        {
                            Debug.WriteLine("Remote customer updated.");
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Debug.WriteLine("Error synchronizing profile. " + error.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// Actualiza el perfil local y remoto del cliente.
        /// </summary>
        /// <param name="customer">Datos del cliente/usuario</param>
        /// <returns>Perfil del cliente como es validado por los metodos para guardarlo</returns>
        internal static CustomerEntity UpdateCustomerProfile(CustomerEntity customer)
        {
            CustomerEntity returnCustomer;

            if (UtnEmallClientApplication.IsOnline)
            {
                // Guardar el cliente remotamente si se esta en línea
                CustomerClient customerClient = new CustomerClient(ServiceClient.CreateDefaultBinding(), new System.ServiceModel.EndpointAddress(UtnEmall.Client.SmartClientLayer.Connection.ServerUri + "Customer"));
                returnCustomer = customerClient.Save(customer, UtnEmall.Client.SmartClientLayer.Connection.Session);
                if (returnCustomer != null)
                {
                    Debug.WriteLine("Internal application error saving remote customer.");
                }
            }
            // Siempre actualizar en la base local
            returnCustomer = new BusinessLogic.Customer().Save(customer);
            if (returnCustomer != null)
            {
                Debug.WriteLine("Internal application error saving local customer.");
            }
            return(returnCustomer);
        }
예제 #3
0
 public ActionResult Create(Customer obj)
 {
     db.Save(obj);
     return(RedirectToAction("Index"));
 }