Ejemplo n.º 1
0
 /// <summary>
 /// Crm服务工厂实体的赋值
 /// </summary>
 /// <param name="whitelist"></param>
 /// <param name="reader"></param>
 /// <param name="prefix"></param>
 public static void SetCrmServiceFactorySelectFields(CrmServiceFactory factory, DbDataReader reader, string prefix)
 {
     factory.ID            = (Guid)reader[string.Format("{0}id", prefix)];
     factory.Name          = reader[string.Format("{0}name", prefix)].ToString();
     factory.Type          = reader[string.Format("{0}type", prefix)].ToString();
     factory.Configuration = reader[string.Format("{0}configuration", prefix)].ToString();
     factory.CreateTime    = (DateTime)reader[string.Format("{0}createtime", prefix)];
     factory.ModifyTime    = (DateTime)reader[string.Format("{0}modifytime", prefix)];
 }
Ejemplo n.º 2
0
        public async Task <CrmServiceFactory> QueryByName(string name)
        {
            CrmServiceFactory result = null;
            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _dbConnectionFactory.CreateReadForXrm(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }

                await using (SqlCommand commond = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    CommandText = string.Format(@"select {0} from CrmServiceFactory where [name]=@name", StoreHelper.GetCrmServiceFactorySelectFields(string.Empty)),
                    Transaction = sqlTran
                })
                {
                    var parameter = new SqlParameter("@name", SqlDbType.VarChar, 100)
                    {
                        Value = name
                    };
                    commond.Parameters.Add(parameter);

                    await commond.PrepareAsync();



                    SqlDataReader reader = null;


                    await using (reader = await commond.ExecuteReaderAsync())
                    {
                        if (await reader.ReadAsync())
                        {
                            result = new CrmServiceFactory();
                            StoreHelper.SetCrmServiceFactorySelectFields(result, reader, string.Empty);
                        }

                        await reader.CloseAsync();
                    }
                }
            });

            return(result);
        }
Ejemplo n.º 3
0
 public LeadDataService()
 {
     _organizationService = CrmServiceFactory.GetOrganizationService();
 }
Ejemplo n.º 4
0
        public Entity CreateContact(FreshdeskContactDto freshdeskContactDto)
        {
            Entity contact = new Entity("contact");

            contact["isw_freshdeskid"] = freshdeskContactDto.Id.ToString();

            if (freshdeskContactDto.CompanyId != null)
            {
                string[]            columns = { "accountid" };
                ConditionExpression ce      = new ConditionExpression("isw_freshdeskid", ConditionOperator.Equal, freshdeskContactDto.CompanyId.ToString());

                FilterExpression fe = new FilterExpression();
                fe.AddCondition(ce);

                var ec = CrmServiceFactory.RetrieveEntities("account", columns, fe, 1);

                if (ec.Entities.Count > 0)
                {
                    contact.Attributes["parentcustomerid"] = new EntityReference(ec.Entities[0].LogicalName, ec.Entities[0].Id);
                }
            }

            if (!string.IsNullOrEmpty(freshdeskContactDto.Email))
            {
                contact["emailaddress1"] = freshdeskContactDto.Email;
            }

            if (!string.IsNullOrEmpty(freshdeskContactDto.Name))
            {
                string[] nameSplit = freshdeskContactDto.Name.Split(' ');

                contact["firstname"] = nameSplit[0];

                if (nameSplit.Length > 1)
                {
                    contact["lastname"] = nameSplit[1];
                }
            }
            contact["telephone1"] = freshdeskContactDto.Phone;

            if (!string.IsNullOrEmpty(freshdeskContactDto.Description))
            {
                contact["description"] = freshdeskContactDto.Description;
            }
            if (!string.IsNullOrEmpty(freshdeskContactDto.Address))
            {
                contact["address1_line1"] = freshdeskContactDto.Address;
            }
            if (!string.IsNullOrEmpty(freshdeskContactDto.JobTitle))
            {
                contact["jobtitle"] = freshdeskContactDto.JobTitle;
            }
            if (!string.IsNullOrEmpty(freshdeskContactDto.Mobile))
            {
                contact["telephone2"] = freshdeskContactDto.Mobile;
            }
            if (!string.IsNullOrEmpty(freshdeskContactDto.Name))
            {
                contact["fullname"] = freshdeskContactDto.Name;
            }


            return(contact);
        }
Ejemplo n.º 5
0
 public ContactMapper()
 {
     service = CrmServiceFactory.GetOrganization();
 }
Ejemplo n.º 6
0
        public Entity CreateTicket(FreshdeskTicket ticket)
        {
            Entity ticketEntity = new Entity("incident");

            //requesterId => customerid
            try
            {
                string[]            columns = { "contactid" };
                ConditionExpression ce      = new ConditionExpression("isw_freshdeskid", ConditionOperator.Equal, ticket.RequesterId.ToString());

                FilterExpression fe = new FilterExpression();
                fe.AddCondition(ce);

                var ec = CrmServiceFactory.RetrieveEntities("contact", columns, fe, 1);

                if (ec.Entities.Count > 0)
                {
                    ticketEntity.Attributes["customerid"] = new EntityReference(ec.Entities[0].LogicalName, ec.Entities[0].Id);
                }
                else
                {
                    var r = _crmRepository.CreateContact(ticket.RequesterId);
                    if (r != null)
                    {
                        ticketEntity.Attributes["customerid"] = new EntityReference("contact", r.Value);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }

            //responder => ownerid
            try
            {
                string[]            columns = { "systemuserid" };
                ConditionExpression ce      = new ConditionExpression("isw_freshdeskid", ConditionOperator.Equal, ticket.ResponderId.ToString());

                FilterExpression fe = new FilterExpression();
                fe.AddCondition(ce);

                var ec = CrmServiceFactory.RetrieveEntities("systemuser", columns, fe, 1);

                if (ec.Entities.Count > 0)
                {
                    ticketEntity.Attributes["ownerid"]        = new EntityReference(ec.Entities[0].LogicalName, ec.Entities[0].Id);
                    ticketEntity.Attributes["isw_resolvedby"] = new EntityReference(ec.Entities[0].LogicalName, ec.Entities[0].Id);
                }
            }
            catch (Exception)
            {}

            if (!string.IsNullOrEmpty(ticket.Type))
            {
                try
                {
                    string[]            columns = { "isw_issueid" };
                    ConditionExpression ce      = new ConditionExpression("isw_name", ConditionOperator.Equal, ticket.Type);

                    FilterExpression fe = new FilterExpression();
                    fe.AddCondition(ce);

                    var ec = CrmServiceFactory.RetrieveEntities("isw_issue", columns, fe, 1);

                    if (ec.Entities.Count > 0)
                    {
                        ticketEntity.Attributes["isw_issue"] = new EntityReference(ec.Entities[0].LogicalName, ec.Entities[0].Id);
                    }
                }
                catch (Exception)
                {
                }
            }

            if (!string.IsNullOrEmpty(ticket.CustomFields.CfIssueSubCategory))
            {
                try
                {
                    string[]            columns = { "isw_issuesubcategoryid" };
                    ConditionExpression ce      = new ConditionExpression("isw_name", ConditionOperator.Equal, ticket.CustomFields.CfIssueSubCategory);

                    FilterExpression fe = new FilterExpression();
                    fe.AddCondition(ce);

                    var ec = CrmServiceFactory.RetrieveEntities("isw_issuesubcategory", columns, fe, 1);

                    if (ec.Entities.Count > 0)
                    {
                        ticketEntity.Attributes["isw_issuesubcategory"] = new EntityReference(ec.Entities[0].LogicalName,
                                                                                              ec.Entities[0].Id);
                    }
                }
                catch (Exception)
                {
                }
            }

            if (!string.IsNullOrEmpty(ticket.CustomFields.CfIssueCategory))
            {
                try
                {
                    string[]            columns = { "isw_issuecategoryid" };
                    ConditionExpression ce      = new ConditionExpression("isw_name", ConditionOperator.Equal,
                                                                          ticket.CustomFields.CfIssueCategory);

                    FilterExpression fe = new FilterExpression();
                    fe.AddCondition(ce);

                    var ec = CrmServiceFactory.RetrieveEntities("isw_issuecategory", columns, fe, 1);

                    if (ec.Entities.Count > 0)
                    {
                        ticketEntity.Attributes["isw_issuecategory"] = new EntityReference(ec.Entities[0].LogicalName,
                                                                                           ec.Entities[0].Id);
                    }
                }
                catch (Exception)
                {
                }
            }

            try
            {
                ticketEntity["prioritycode"] = new OptionSetValue(TicketPriority[ticket.Priority]);
            }
            catch (Exception)
            {}

            try
            {
                ticketEntity["caseorigincode"] = new OptionSetValue(TicketSource[ticket.Source]);
            }
            catch (Exception)
            { }

            if (!string.IsNullOrEmpty(ticket.Type))
            {
                ticketEntity["title"] = ticket.Type;
            }

            ticketEntity["isw_freshdeskid"] = ticket.Id.ToString();

            if (!string.IsNullOrEmpty(ticket.DescriptionText))
            {
                ticketEntity["description"] = ticket.Subject;
            }

            if (ticket.Stats.FirstRespondedAt != null)
            {
                ticketEntity["isw_firstresponseforautocreatedcases"] = ticket.Stats.FirstRespondedAt.Value.DateTime;
            }

            if (ticket.Stats.FirstRespondedAt != null)
            {
                ticketEntity["isw_firstresponseforautocreatedcases"] = ticket.Stats.FirstRespondedAt.Value.DateTime;
            }

            if (ticket.Stats.ResolvedAt != null)
            {
                ticketEntity["isw_actualresolvedate"] = ticket.Stats.ResolvedAt.Value.DateTime;
            }

            if (ticket.Stats.ReopenedAt != null)
            {
                ticketEntity["isw_reactivateddate"] = ticket.Stats.ReopenedAt.Value.DateTime;
            }

            return(ticketEntity);
        }
Ejemplo n.º 7
0
 public TicketMapper()
 {
     service        = CrmServiceFactory.GetOrganization();
     _crmRepository = new CrmRepository();
 }