public Contacto ObtenerContactoPorId(Guid Id) { Contacto item = null; try { Entity entity = _servicio.Retrieve(_nombreEntidad, Id, new ColumnSet(_columnas)); if (entity != null) { item = new Contacto(); item.ContactoID = entity.Id; if (entity.Attributes.ContainsKey("firstname") && entity["firstname"] != null) { item.Nombres = entity["firstname"].ToString(); } if (entity.Attributes.ContainsKey("lastname") && entity["lastname"] != null) { item.Apellidos = entity["lastname"].ToString(); } if (entity.Attributes.ContainsKey("jobtitle") && entity["jobtitle"] != null) { item.Puesto = entity["jobtitle"].ToString(); } if (entity.Attributes.ContainsKey("parentcustomerid") && entity["parentcustomerid"] != null) { item.Cuenta = new CrmLookup((EntityReference)entity["parentcustomerid"]); } if (entity.Attributes.ContainsKey("preferredcontactmethodcode") && entity["preferredcontactmethodcode"] != null) { item.MetodoContacto = new CrmPicklist("preferredcontactmethodcode", entity); } } } catch (Exception ex) { throw ex; } return(item); }
public List <Contacto> ObtenerContactoPorNombres(string Nombres) { List <Contacto> list = null; try { //Definir las columnas. ColumnSet cols = new ColumnSet(_columnas); //Definir las condiciones. ConditionExpression condition = new ConditionExpression("firstname", ConditionOperator.Like, "%" + Nombres + "%"); //Agregacr las condiciones al filtro. FilterExpression filter = new FilterExpression(); filter.AddCondition(condition); //Construir el query. QueryExpression query = new QueryExpression(_nombreEntidad); query.ColumnSet = cols; query.Criteria = filter; //Realizar la consulta. EntityCollection collection = _servicio.RetrieveMultiple(query); //Mapear los datos. if (collection != null && collection.Entities != null && collection.Entities.Count > 0) { foreach (Entity ent in collection.Entities) { Contacto item = new Contacto(); if (ent.Attributes.ContainsKey("firstname") && ent["firstname"] != null) { item.Nombres = ent["firstname"].ToString(); } if (ent.Attributes.ContainsKey("lastname") && ent["lastname"] != null) { item.Apellidos = ent["lastname"].ToString(); } if (ent.Attributes.ContainsKey("jobtitle") && ent["jobtitle"] != null) { item.Puesto = ent["jobtitle"].ToString(); } if (ent.Attributes.ContainsKey("parentcustomerid") && ent["parentcustomerid"] != null) { item.Cuenta = new CrmLookup((EntityReference)ent["parentcustomerid"]); } if (ent.Attributes.ContainsKey("preferredcontactmethodcode") && ent["preferredcontactmethodcode"] != null) { item.MetodoContacto = new CrmPicklist("preferredcontactmethodcode", ent); } list.Add(item); } } } catch (Exception ex) { throw ex; } return(list); }