public static Respuesta CrearContactoCRM(string Nombres, string Apellidos, string Puesto, Guid EmpresaID, int MetodoContacto)
        {
            Respuesta resp = new Respuesta();

            try
            {
                using (SimpleConnection365 cnn = new SimpleConnection365(Constantes.ConnectionStringName))
                {
                    using (ContactoServicio contactoSvc = new ContactoServicio(cnn.ObtenerServicioConexion()))
                    {
                        Contacto con = new Contacto();
                        con.Nombres        = Nombres;
                        con.Apellidos      = Apellidos;
                        con.Puesto         = Puesto;
                        con.Cuenta         = new CrmLookup(EmpresaID, null, "account");
                        con.MetodoContacto = new CrmPicklist(MetodoContacto);

                        resp = contactoSvc.Guardar(con);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(resp);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            cnn = new SimpleConnection365("Dev00");
            if (cnn != null)
            {
                servicio = cnn.ObtenerServicioConexion();
            }

            columns = new ColumnSet(new string[] { "firstname", "lastname", "emailaddress1", "jobtitle", "companyname" });

            bool continuar = true;

            while (continuar)
            {
                Menu();
                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.D1:
                    // Obtener listado de Clientes potenciales.
                    GetLeads();
                    break;

                case ConsoleKey.D2:
                    // Crear Lead.
                    CreateLead();
                    break;

                case ConsoleKey.D3:
                    GetLead();
                    break;

                case ConsoleKey.D4:
                    UpdateLead();
                    break;

                case ConsoleKey.D5:
                    DeleteLead();
                    break;

                case ConsoleKey.D6:
                    GetSampleLeads();
                    break;

                case ConsoleKey.Q:
                    continuar = false;
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Opción inválida...");
                    PressEnter();
                    break;
                }
            }
        }
        public static Respuesta EliminarContacto(Guid ContactoID)
        {
            Respuesta resp = new Respuesta();

            using (SimpleConnection365 cnn = new SimpleConnection365(Constantes.ConnectionStringName))
            {
                using (ContactoServicio contactSvc = new ContactoServicio(cnn.ObtenerServicioConexion()))
                {
                    resp = contactSvc.Eliminar(ContactoID);
                }
            }

            return(resp);
        }
        public static List <Contacto> ObtenerContactos()
        {
            List <Contacto> list = null;

            using (SimpleConnection365 cnn = new SimpleConnection365(Constantes.ConnectionStringName))
            {
                using (ContactoServicio contactSvc = new ContactoServicio(cnn.ObtenerServicioConexion()))
                {
                    list = contactSvc.ObtenerContactos();
                }
            }

            return(list);
        }
Beispiel #5
0
 static void ConexionSimple()
 {
     using (SimpleConnection365 cnn = new SimpleConnection365(connectionStringName))
     {
         if (cnn != null)
         {
             CrmServiceClient crmSvc = cnn.ObtenerCrmServiceClient();
             if (crmSvc != null && crmSvc.IsReady)
             {
                 Console.WriteLine("Conectado a CRM! (Version{0}; Organization Unique Name: {1}, Organization Friendly Name: {2}, Endpoints: {3})", crmSvc.ConnectedOrgVersion, crmSvc.ConnectedOrgUniqueName, crmSvc.ConnectedOrgFriendlyName);
             }
         }
     }
 }
        public static List <CrmPicklist> ObtenerMetodosDeContacto()
        {
            List <CrmPicklist> list = null;

            try
            {
                using (SimpleConnection365 cnn = new SimpleConnection365(Constantes.ConnectionStringName))
                {
                    using (Metadata metadataSvc = new Metadata(cnn.ObtenerServicioConexion()))
                    {
                        list = metadataSvc.ObtenerOptionSetEntidad("contact", "preferredcontactmethodcode");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(list);
        }
        public static List <Cuenta> ObtenerCuentas()
        {
            List <Cuenta> list = null;

            try
            {
                using (SimpleConnection365 cnn = new SimpleConnection365(Constantes.ConnectionStringName))
                {
                    using (CuentaServicio cuentaSvc = new CuentaServicio(cnn.ObtenerServicioConexion()))
                    {
                        list = cuentaSvc.ObtenerCuentas();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(list);
        }
Beispiel #8
0
        public static Contacto ObtenerContactoPorID(Guid ContactoID)
        {
            Contacto con = null;

            try
            {
                using (SimpleConnection365 cnn = new SimpleConnection365(Constantes.ConnectionStringName))
                {
                    using (ContactoServicio contactoSvc = new ContactoServicio(cnn.ObtenerServicioConexion()))
                    {
                        con = contactoSvc.ObtenerContactoPorId(ContactoID);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(con);
        }
Beispiel #9
0
        public static RetrieveRecordListResponse GetLeads()
        {
            RetrieveRecordListResponse response = new RetrieveRecordListResponse();

            using (FileLog log = new FileLog())
            {
                try
                {
                    using (SimpleConnection365 cnn = new SimpleConnection365(Constantes.ConexionActual))
                    {
                        // Obtenemos el servicio de la organizacion.
                        IOrganizationService servicio = cnn.ObtenerServicioConexion();

                        // Validamos que el servicio haya sido obtenido.
                        if (servicio != null)
                        {
                            // 1. Definimos las columnas que serán consultadas de cada cliente potencial.
                            ColumnSet columns = new ColumnSet(new string[] { "fullname", "jobtitle", "emailaddress1", "companyname" });

                            // 2. Definimos las condiciones de búsqueda.
                            // TODO: Definir condiciones.

                            // 3. Definimos las opciones de filtrado.
                            // TODO: Asignar las condiciones de filtrado.

                            // 4. Creamos la consulta.
                            QueryExpression qe = new QueryExpression("lead");
                            qe.ColumnSet = columns;

                            // Ejecutamos la consulta.
                            EntityCollection collection = servicio.RetrieveMultiple(qe);

                            // Se valida que la colección no sea nula o vacía.
                            if (collection != null && collection.Entities != null && collection.Entities.Count > 0)
                            {
                                response.List          = collection.Entities.ToList();
                                response.WasSuccessful = true;
                            }
                        }
                        else
                        {
                            throw new OrganizationServiceNotFoundException();
                        }
                    }
                }
                catch (FaultException <OrganizationServiceFault> osFaultException)
                {
                    Guid errorID = Guid.NewGuid();
                    log.WriteError(osFaultException.Detail.Message, errorID.ToString());
                    response.ErrorMessage = "No fué posible obtener el listado. Proporcione el siguiente código de error al administrador del sistema. ErrorID: {0}".FormatWith(errorID);
                }
                catch (Exception ex)
                {
                    Guid errorID = Guid.NewGuid();
                    log.WriteError(ex.Message, errorID.ToString());
                    response.ErrorMessage = "No fué posible obtener el listado. Proporcione el siguiente código de error al administrador del sistema. ErrorID: {0}".FormatWith(errorID);
                }
            }

            return(response);
        }
        public static CreateEntityRecordResponse CreateLead(string Subject, string FirstName, string LastName, string Email)
        {
            CreateEntityRecordResponse response = new CreateEntityRecordResponse();

            using (FileLog log = new FileLog())
            {
                try
                {
                    if (Subject.IsNullOrEmpty())
                    {
                        throw new MissingParameterException("Subject", "CreateLead");
                    }

                    if (FirstName.IsNullOrEmpty())
                    {
                        throw new MissingParameterException("FirstName", "CreateLead");
                    }

                    if (LastName.IsNullOrEmpty())
                    {
                        throw new MissingParameterException("LastName", "CreateLead");
                    }


                    using (SimpleConnection365 cnn = new SimpleConnection365(Constantes.ConexionActual))
                    {
                        IOrganizationService servicio = cnn.ObtenerServicioConexion();

                        if (servicio != null)
                        {
                            Entity entity = new Entity("lead");
                            entity["subject"]       = Subject;
                            entity["firstname"]     = FirstName;
                            entity["lastname"]      = LastName;
                            entity["emailaddress1"] = Email;

                            servicio.Create(entity);
                            response.WasSuccessful = true;
                        }
                        else
                        {
                            throw new OrganizationServiceNotFoundException();
                        }
                    }
                }
                catch (FaultException <OrganizationServiceFault> osFaultException)
                {
                    Guid errorID = Guid.NewGuid();
                    log.WriteError(osFaultException.Detail.Message, errorID.ToString());
                    response.ErrorMessage = "No fué posible crear el registro. Proporcione el siguiente código de error al administrador del sistema. ErrorID: {0}".FormatWith(errorID);
                }
                catch (Exception ex)
                {
                    Guid errorID = Guid.NewGuid();
                    log.WriteError(ex.Message, errorID.ToString());
                    response.ErrorMessage = "No fué posible crear el registro. Proporcione el siguiente código de error al administrador del sistema. ErrorID: {0}".FormatWith(errorID);
                }
            }

            return(response);
        }