Example #1
0
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <QueryResult <CrmEntity> > getlist(VehlisenseListRequest request)
        {
            try
            {
                var fetchXdoc = _Repository.GetListFetchXml(request);

                var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName = "mcs_vehlisense",
                    FetchXml   = fetchXdoc.Result
                };
                var fetchResponse = await _crmService.Execute(fetchRequest);

                var fetchResponseResult = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
                var queryResult         = new QueryResult <CrmEntity>();
                queryResult.Results     = fetchResponseResult.Value.Results;
                queryResult.CurrentPage = request.PageSize;
                queryResult.TotalCount  = 0;
                return(queryResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <QueryResult <CrmEntity> > getlist(ActivityRequest request)
        {
            var userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);

            try
            {
                var fetchXdoc    = _Repository.GetListFetchXml(request);
                var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName  = "mcs_activity",
                    FetchXml    = fetchXdoc.Result,
                    ProxyUserId = userInfo?.systemuserid
                };
                var fetchResponse = await _crmService.Execute(fetchRequest);

                var fetchResponseResult = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
                var queryResult         = new QueryResult <CrmEntity>();
                queryResult.Results     = fetchResponseResult.Value.Results;
                queryResult.CurrentPage = request.PageSize;
                queryResult.TotalCount  = 0;
                return(queryResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        public async Task <QueryResult <CrmEntity> > QueryListByPage(int orderstauts = 0, string searchkey = "", int pageSize = 10, int pageNum = 1, string sort = "", string token = "")
        {
            try
            {
                string filterstr = "";
                if (orderstauts > 0)
                {
                    filterstr += $"<condition attribute='mcs_orderstatus' operator='eq' value='{orderstauts}' />";
                }

                if (!string.IsNullOrEmpty(searchkey))
                {
                    filterstr += $"<filter type='or' >";
                    filterstr += $"<condition attribute='mcs_name' operator='like' value='%{searchkey}%' />";
                    filterstr += $"<condition attribute='mcs_title' operator='like' value='%{searchkey}%' />";
                    filterstr += $"</filter>";
                }

                var       fetchxml = string.Format($@"<fetch version=""1.0"" output-format=""xml-platform"" mapping=""logical"" distinct=""false"" count=""{pageSize}"" page=""{pageNum}"">
                                <entity name = ""mcs_supportorder"" >
                                    <attribute name = ""mcs_supportorderid"" />
                                    <attribute name = ""mcs_name"" />
                                    <attribute name = ""mcs_repairdate"" />
                                    <attribute name = ""mcs_orderstatus"" />
                                    <attribute name = ""mcs_title"" />    
                                <filter type = ""and"" >
                                  <condition attribute='statecode' operator='eq' value='0' />
                                  {filterstr}
                               </filter>
                                </entity>
                            </fetch>");
                XDocument xmlDoc   = XDocument.Parse(fetchxml);

                var userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
                var request  = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName  = EntityName,
                    FetchXml    = xmlDoc,
                    ProxyUserId = userInfo != null ? userInfo.systemuserid : null
                };
                var crmResponse = await _crmService.Execute(request);

                CrmRetrieveMultipleFetchResponseMessage response = crmResponse as CrmRetrieveMultipleFetchResponseMessage;

                QueryResult <CrmEntity> queryResult = new QueryResult <CrmEntity>();
                if (response.Value != null)
                {
                    queryResult.Results     = response.Value.Results;
                    queryResult.TotalCount  = response.Value.Count;
                    queryResult.CurrentPage = pageNum;
                }
                return(queryResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
0
        public async Task <QueryResult <JObject> > QueryUserList(int pageindex, string search)
        {
            #region 组装filter
            var filter = string.Empty;
            if (!string.IsNullOrEmpty(search))
            {
                filter += $"<filter type='or'>";
                filter += $"<condition attribute='mcs_name' operator='like' value='%{search}%' />";
                filter += $"<condition attribute='mcs_phone' operator='like' value='%{search}%' />";
                filter += $"<condition attribute='mcs_cardid' operator='like' value='%{search}%' />";
                filter += $"</filter>";
            }

            if (!string.IsNullOrEmpty(filter))
            {
                filter = "<filter type='and'>" + filter;
                filter = filter + "</filter>";
            }
            #endregion

            #region 组装FetchXml
            var xDoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = string.Empty;
                fetchXml     = $@"
            <fetch version='1.0' output-format='xml-platform' mapping='logical' count='{pageCount}' page='{pageindex}' >
              <entity name='mcs_user'>
                  {filter}
              </entity>
            </fetch>";
                return(XDocument.Parse(fetchXml));
            });;
            #endregion

            #region 获取记录结果集
            var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_user",
                FetchXml   = xDoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            var fetchResponse = await _crmService.Execute(fetchRequest);

            var resultsList = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion ;

            #region 组装数据返回
            var result = new QueryResult <JObject>();
            foreach (var entity in resultsList.Value.Results)
            {
                result.Results.Add(entity.Attributes);
            }
            return(result);

            #endregion
        }
Example #5
0
        /// <summary>
        /// 获取用户标签
        /// </summary>
        /// <param name="userDetailRequest"></param>
        /// <returns></returns>
        public async Task <UserTagListResponse> getusertag(UserDetailRequest userDetailRequest)
        {
            try
            {
                var response         = new UserTagListResponse();
                var crmRequestHelper = new CrmRequestHelper();
                var fetchRequest     = new CrmRetrieveCollectionAttributeRequestMessage()
                {
                    EntityName      = "mcs_user",
                    EntityId        = Guid.Parse(userDetailRequest.id),
                    AttributeName   = "mcs_mcs_user_mcs_usertag",
                    QueryExpression = "$select=mcs_name"
                };
                fetchRequest.Headers.Add("Prefer", dicHead["Prefer"]);
                var crmResponseMessage = await _crmService.Execute(fetchRequest);

                var entities = crmResponseMessage as CrmRetrieveCollectionAttributeResponseMessage;
                response.tags = entities.Value.Results;
                return(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #6
0
    /// <summary>
    /// Retrieve Entity from ICrmservice
    /// </summary>
    /// <param name="iservice">ICrmService</param>
    /// <param name="entityName">Entity Name</param>
    /// <param name="entityGuid">Entity Guid(Guid)</param>
    /// <param name="retrieveAllColumns">True to retrieve all columns </param>
    /// <returns></returns>
    public static DynamicEntity RetriveDynamicEntity(this ICrmService iservice, String entityName, Guid entityGuid, Boolean retrieveAllColumns)
    {
        // Create/Set the Target object.
        TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic
        {
            EntityName = entityName,
            EntityId   = (entityGuid)
        };

        // Create/Set the Retrieve object.
        RetrieveRequest retrieve = new RetrieveRequest();

        retrieve.Target = targetRetrieve;
        if (retrieveAllColumns == true)
        {
            retrieve.ColumnSet = new AllColumns();
        }                                          //// Indicate to retrieve all columns
        retrieve.ReturnDynamicEntities = true;     // Indicate that the BusinessEntity should be retrieved as a DynamicEntity.

        // Execute the request.
        RetrieveResponse retrieved = (RetrieveResponse)iservice.Execute(retrieve);
        // Extract the DynamicEntity from the request.
        DynamicEntity retriveEntity = (DynamicEntity)retrieved.BusinessEntity;

        return(retriveEntity);
    }
Example #7
0
        public async Task <CrmEntityCollection> ExecuteAsync(ICrmService crmService, string entityName, XDocument document, Guid?userId = null)
        {
            try
            {
                var userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
                var dicHead  = new Dictionary <string, IEnumerable <string> >();
                dicHead.Add("Prefer", new List <string>()
                {
                    "odata.include-annotations=\"*\""
                });
                var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName  = entityName,
                    FetchXml    = document,
                    ProxyUserId = userInfo?.systemuserid
                };
                fetchRequest.Headers.Add("Prefer", dicHead["Prefer"]);
                var crmResponseMessage = await crmService.Execute(fetchRequest);

                var resultsList = crmResponseMessage as CrmRetrieveMultipleFetchResponseMessage;
                return(resultsList.Value);
            }
            catch (Exception ex)
            {
                return(new CrmEntityCollection());
            }
        }
Example #8
0
        public async Task <QueryResult <CrmEntity> > QueryList(int pageindex, string search, string dealeridGuid)
        {
            #region 获取记录结果集
            var filter = await GetQueryListFilter(search, dealeridGuid);

            var fetchXdoc = await GetQueryListFetchXml(pageindex, filter);

            var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_vehowner",
                FetchXml   = fetchXdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            var fetchResponse = await _crmService.Execute(fetchRequest);

            var resultsList = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion ;

            #region 组装返回结果集
            var queryResult = new QueryResult <CrmEntity>();
            queryResult.Results     = resultsList.Value.Results;
            queryResult.CurrentPage = pageindex;
            queryResult.TotalCount  = resultsList.Value.Results.Count;
            return(queryResult);

            #endregion
        }
Example #9
0
        /// <summary>
        /// 用户车辆列表查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <QueryResult <CrmEntity> > QueryList(UserCarInfoListRequest request)
        {
            try
            {
                var fetchString = _usercarinfoRepository.QueryList(request);

                var fetchXdoc    = XDocument.Parse(fetchString);
                var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName = "mcs_usercarinfo",
                    FetchXml   = fetchXdoc
                };
                var fetchResponse = await _crmService.Execute(fetchRequest);

                var fetchResponseResult = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;

                var queryResult = new QueryResult <CrmEntity>();
                queryResult.Results     = fetchResponseResult.Value.Results;
                queryResult.CurrentPage = request.PageIndex;
                queryResult.TotalCount  = 0;
                return(queryResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #10
0
        public async Task <QueryResult <CrmEntity> > GetUserNotices(UserNoticeRequest request)
        {
            try
            {
                var fetchString = _repository.GetUserNotices(request);

                var fetchXdoc    = XDocument.Parse(fetchString);
                var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName = "mcs_user_msg",
                    FetchXml   = fetchXdoc,
                };
                fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
                var fetchResponse = await _crmService.Execute(fetchRequest);

                var fetchResponseResult = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;

                var queryResult = new QueryResult <CrmEntity>();
                queryResult.Results     = fetchResponseResult.Value.Results;
                queryResult.CurrentPage = request.PageIndex;
                queryResult.TotalCount  = 0;

                //更新消息为已读
                //if (queryResult.Results!=null && queryResult.Results.Count>0)
                //{
                //    foreach (var item in queryResult.Results)
                //    {
                //        if (int.Parse(item.Attributes["mcs_readstatus"].ToString()) ==0)
                //        {
                //            await UpdateUserNoticeReadStatus(new UserNoticeRequest() {
                //                Id= item.Id.ToString(),
                //                mcs_readstatus=1
                //            });;
                //        }
                //    }
                //}
                return(queryResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #11
0
    /// <summary>
    /// Sets the state for the record
    /// </summary>
    /// <param name="dynamicEntityObject"></param>
    /// <param name="service">CrmService</param>
    /// <param name="status">status code</param>
    /// <param name="state">Status text</param>
    public static void SetState(this DynamicEntity dynamicEntityObject, ICrmService service, int status, String state)
    {
        try
        {
            SetStateDynamicEntityRequest setInactiveRequest = new SetStateDynamicEntityRequest();

            Key     recordGuid    = (Key)dynamicEntityObject[dynamicEntityObject.Name + "id"];
            Moniker entityMoniker = new Moniker(dynamicEntityObject.Name, recordGuid.Value);
            setInactiveRequest.Entity = entityMoniker;
            setInactiveRequest.Status = status;
            setInactiveRequest.State  = state;

            SetStateDynamicEntityResponse setInactiveResponse =
                (SetStateDynamicEntityResponse)service.Execute(setInactiveRequest);
        }
        catch (System.Web.Services.Protocols.SoapException)
        {
            throw;
        }
    }
Example #12
0
    //Set inactive ICrmService
    /// <summary>
    /// Set a record inactive
    /// </summary>
    /// <param name="dynamicEntityObject">Entity</param>
    /// <param name="service">CrmService</param>
    public static void SetActive(this DynamicEntity dynamicEntityObject, ICrmService service)
    {
        try
        {
            SetStateDynamicEntityRequest setInactiveRequest = new SetStateDynamicEntityRequest();

            Key     recordGuid    = (Key)dynamicEntityObject[dynamicEntityObject.Name + "id"];
            Moniker entityMoniker = new Moniker(dynamicEntityObject.Name, recordGuid.Value);
            //HACK: Might not work always since the status are different for quite a few entities
            setInactiveRequest.Entity = entityMoniker;
            setInactiveRequest.Status = 1;
            setInactiveRequest.State  = "Active";

            SetStateDynamicEntityResponse setInactiveResponse =
                (SetStateDynamicEntityResponse)service.Execute(setInactiveRequest);
        }
        catch (System.Web.Services.Protocols.SoapException)
        {
            throw;
        }
    }
Example #13
0
    //ops
    /// <summary>
    /// Retrieve Entity from ICrmservice
    /// </summary>
    /// <param name="iservice">ICrmService</param>
    /// <param name="entityName">Entity Name</param>
    /// <param name="entityGuid">Entity Guid(String)</param>
    /// <returns></returns>
    public static DynamicEntity RetriveDynamicEntity(this ICrmService iservice, String entityName, String entityGuid)
    {
        // Create/Set the Target object.
        TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic
        {
            EntityName = entityName,
            EntityId   = new Guid(entityGuid)
        };

        // Create/Set the Retrieve object.
        RetrieveRequest retrieve = new RetrieveRequest
        {
            Target = targetRetrieve,
            //ColumnSet = new AllColumns(),
            ReturnDynamicEntities = true          // Indicate that the BusinessEntity should be retrieved as a DynamicEntity.
        };

        // Execute the request.
        RetrieveResponse retrieved = (RetrieveResponse)iservice.Execute(retrieve);
        // Extract the DynamicEntity from the request.
        DynamicEntity retriveEntity = (DynamicEntity)retrieved.BusinessEntity;

        return(retriveEntity);
    }
Example #14
0
        public async Task <JObject> QueryCepconfig(string key)
        {
            var xdoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = string.Empty;
                fetchXml     = $@"
            <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' >
              <entity name='mcs_cepconfig'>
                <filter type='and'>
                <condition attribute='mcs_name' operator='eq' value='{key}' />
                </filter>
              </entity>
            </fetch>";
                return(XDocument.Parse(fetchXml));
            });

            var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_cepconfig",
                FetchXml   = xdoc
            };

            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            var fetchResponse = await _crmService.Execute(fetchRequest);

            var response = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;

            if (response.Value.Results.Count > 0)
            {
                return(response.Value.Results[0].Attributes);
            }
            else
            {
                return(null);
            }
        }
Example #15
0
        public async Task <ProducListResponse> QueryProductList(ProducListRequest request)
        {
            var producListResponse = new ProducListResponse();
            var dicProduct         = new Dictionary <Guid, Product>();
            var dicRightspackage   = new Dictionary <Guid, Rightspackage>();
            var dicRights          = new Dictionary <Guid, JObject>();

            #region 查询所有商品
            var xdoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = $@"
                <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                    <entity name='mcs_tc_product'>
                        <order attribute='createdon' descending='true' />
                        <filter type='and'>
                            <condition attribute='mcs_type' operator='in'>
                                <value>7</value>
                                <value>2</value>
                                <value>1</value>
                            </condition>
                            <condition attribute='mcs_state' operator='eq' value='2' />
                        </filter>
                    </entity>
                </fetch>";
                return(XDocument.Parse(fetchXml));
            });

            var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_tc_product",
                FetchXml   = xdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            var fetchResponse = await _crmService.Execute(fetchRequest);

            var procudtResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询商品的图片
            xdoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = $@"
                <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                    <entity name='mcs_tc_productimage'>
                        <attribute name='mcs_tc_productimageid' />
                        <attribute name='mcs_imagetype' />
                        <attribute name='mcs_imagename' />
                        <attribute name='mcs_product' />
                        <order attribute='createdon' descending='true' />
                        <filter type='and'>
                            <condition attribute='statecode' operator='eq' value='0' />
                            <condition attribute='mcs_product' operator='not-null' />
                        </filter>
                    </entity>
                </fetch>";
                return(XDocument.Parse(fetchXml));
            });


            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_tc_productimage",
                FetchXml   = xdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var productImageResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询商品的规格型号
            xdoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = $@"
                <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                    <entity name='mcs_tc_productspecification'>
                        <attribute name='mcs_tc_productspecificationid' />
                        <attribute name='mcs_attributegroupname' />
                        <attribute name='mcs_attributename' />
                        <attribute name='mcs_attributevalue' />
                        <attribute name='mcs_product' />
                        <attribute name='mcs_attributegroupindex' />
                        <order attribute='createdon' descending='true' />
                        <filter type='and'>
                            <condition attribute='statecode' operator='eq' value='0' />
                            <condition attribute='mcs_product' operator='not-null' />
                        </filter>
                    </entity>
                </fetch>";
                return(XDocument.Parse(fetchXml));
            });


            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_tc_productspecification",
                FetchXml   = xdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var productSpecificationResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询商品的订购属性
            xdoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = $@"
                <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                    <entity name='mcs_tc_productorderingattribute'>
                        <filter type='and'>
                          <condition attribute='statecode' operator='eq' value='0' />
                          <condition attribute='mcs_product' operator='not-null' />
                        </filter>
                    </entity>
                </fetch>";
                return(XDocument.Parse(fetchXml));
            });



            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_tc_productorderingattribute",
                FetchXml   = xdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var productOrderingattributeResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询商品的SKU
            xdoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = $@"
                <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                    <entity name='mcs_tc_productprice'>
                        <order attribute='createdon' descending='true' />
                        <filter type='and'>
                            <condition attribute='statecode' operator='eq' value='0' />
                            <condition attribute='mcs_product' operator='not-null' />
                        </filter>
                    </entity>
                </fetch>";
                return(XDocument.Parse(fetchXml));
            });


            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_tc_productprice",
                FetchXml   = xdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var productPriceResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询商品SKU的订购关系(弃用)
            //xdoc = await Task<XDocument>.Run(() =>
            //{
            //    var fetchXml = $@"
            //    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
            //        <entity name='mcs_tc_skuattr'>
            //            <order attribute='createdon' descending='true' />
            //        </entity>
            //    </fetch>";
            //    return XDocument.Parse(fetchXml);
            //});


            //fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            //{
            //    EntityName = "mcs_tc_skuattr",
            //    FetchXml = xdoc
            //};
            //fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            //fetchResponse = await _crmService.Execute(fetchRequest);
            //var skuattrResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询商品的关联关系
            xdoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = $@"
                <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                    <entity name='mcs_tc_productrelated'>
                        <order attribute='createdon' descending='true' />
                        <filter type='and'>
                            <condition attribute='statecode' operator='eq' value='0' />
                            <condition attribute='mcs_product' operator='not-null' />
                        </filter>
                        <link-entity name='mcs_tc_productprice' from='mcs_tc_productpriceid' to='mcs_relatedproductsku' link-type='outer' alias='a' visible='false'>
                            <all-attributes/>
                        </link-entity>
                    </entity>
                </fetch>";
                return(XDocument.Parse(fetchXml));
            });


            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_tc_productrelated",
                FetchXml   = xdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var productrElatedArrayResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询权益包
            xdoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = $@"
                <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                    <entity name='mcs_rc_rightspackage'>
                        <order attribute='createdon' descending='true' />
                    </entity>
                </fetch>";
                return(XDocument.Parse(fetchXml));
            });

            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_rc_rightspackage",
                FetchXml   = xdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var rightspackageArrayResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询权益项
            xdoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = $@"
                <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                    <entity name='mcs_rc_rights'>
                        <order attribute='createdon' descending='true' />
                    </entity>
                </fetch>";
                return(XDocument.Parse(fetchXml));
            });


            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_rc_rights",
                FetchXml   = xdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var rightsArrayResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询权益包与权益项的关系
            xdoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = $@"
                <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                    <entity name='mcs_rc_rightspackagedetail'>
                        <order attribute='createdon' descending='true' />
                    </entity>
                </fetch>";
                return(XDocument.Parse(fetchXml));
            });

            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_rc_rightspackagedetail",
                FetchXml   = xdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var rightspackagedetailArrayResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询权益包与商品的关系
            xdoc = await Task <XDocument> .Run(() =>
            {
                var fetchXml = $@"
                <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                    <entity name='mcs_rc_rightspackageproduct'>
                        <order attribute='createdon' descending='true' />
                    </entity>
                </fetch>";
                return(XDocument.Parse(fetchXml));
            });

            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_rc_rightspackageproduct",
                FetchXml   = xdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var rightspackageproductArrayResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 组装商品
            foreach (var entity in procudtResponse.Value.Results)
            {
                var product = new Product();
                product.ProductInfo = entity.Attributes;
                dicProduct.Add(entity.Id, product);
            }
            #endregion

            #region 组装商品图片
            var host = "https://ceo-oss.oss-cn-hangzhou.aliyuncs.com/";
            foreach (var entity in productImageResponse.Value.Results)
            {
                var productGuid = Guid.Parse(entity.Attributes.Value <string>("_mcs_product_value"));
                entity.Attributes.Add("ext_fullurl", host + entity.Attributes.Value <string>("mcs_imagename"));
                if (dicProduct.ContainsKey(productGuid))
                {
                    dicProduct[productGuid].ProductImageArray.Add(entity.Attributes);
                }
            }
            #endregion

            #region 组装商品规格型号
            foreach (var entity in productSpecificationResponse.Value.Results)
            {
                var productGuid = Guid.Parse(entity.Attributes.Value <string>("_mcs_product_value"));
                if (dicProduct.ContainsKey(productGuid))
                {
                    dicProduct[productGuid].ProductSpecificationArray.Add(entity.Attributes);
                }
            }
            #endregion

            #region 组装商品的订购属性
            foreach (var entity in productOrderingattributeResponse.Value.Results)
            {
                var productGuid = Guid.Parse(entity.Attributes.Value <string>("_mcs_product_value"));
                if (dicProduct.ContainsKey(productGuid))
                {
                    dicProduct[productGuid].ProductOrderingattributeArray.Add(entity.Attributes);
                }
            }
            #endregion

            #region 组装商品的关联关系
            foreach (var entity in productrElatedArrayResponse.Value.Results)
            {
                var productGuid = Guid.Parse(entity.Attributes.Value <string>("_mcs_product_value"));
                if (dicProduct.ContainsKey(productGuid))
                {
                    dicProduct[productGuid].ProductRelatedArray.Add(entity.Attributes);
                }
            }
            #endregion

            #region 组装商品SKU订购关系Map (弃用)
            //var skuattrMap = new Dictionary<string, JObject>();
            //foreach (var entity in skuattrResponse.Value.Results)
            //{
            //    var key = entity.Attributes.Value<string>("_mcs_sku_value");
            //    if (!skuattrMap.ContainsKey(key))
            //    {
            //        skuattrMap.Add(key, new JObject());
            //    }
            //    skuattrMap[key].Add(entity.Attributes.Value<string>("_mcs_attr_value"), new JObject());
            //}
            #endregion

            #region 组装商品的SKU
            foreach (var entity in productPriceResponse.Value.Results)
            {
                var productGuid = Guid.Parse(entity.Attributes.Value <string>("_mcs_product_value"));
                //var key = entity.Id.ToString();

                //if (skuattrMap.ContainsKey(key))
                //{
                //    entity.Attributes.Add("skuattr", skuattrMap[key]);
                //}
                //else
                //{
                //    entity.Attributes.Add("skuattr", new JObject());
                //}
                if (dicProduct.ContainsKey(productGuid))
                {
                    dicProduct[productGuid].ProductPriceArray.Add(entity.Attributes);
                }
            }
            #endregion

            #region 组装权益包
            foreach (var entity in rightspackageArrayResponse.Value.Results)
            {
                var rightspackage = new Rightspackage();
                rightspackage.RightspackageInfo = entity.Attributes;
                dicRightspackage.Add(entity.Id, rightspackage);
            }
            #endregion

            #region 组装权益项
            foreach (var entity in rightsArrayResponse.Value.Results)
            {
                var rights = new JObject();
                rights = entity.Attributes;
                dicRights.Add(entity.Id, rights);
            }
            #endregion

            #region 组装权益包与权益项的关系
            foreach (var entity in rightspackagedetailArrayResponse.Value.Results)
            {
                var rightsGuid        = Guid.Parse(entity.Attributes.Value <string>("_mcs_rights_value"));
                var rightspackageGuid = Guid.Parse(entity.Attributes.Value <string>("_mcs_rightspackage_value"));
                if (dicRights.ContainsKey(rightsGuid) && dicRightspackage.ContainsKey(rightspackageGuid))
                {
                    dicRightspackage[rightspackageGuid].RightsArray.Add(dicRights[rightsGuid]);
                }
            }
            #endregion

            #region 组装权益包与商品的关系
            foreach (var entity in rightspackageproductArrayResponse.Value.Results)
            {
                var productGuid = Guid.Parse(entity.Attributes.Value <string>("_mcs_product_value"));
                if (entity.Attributes.Value <string>("_mcs_rightspackage_value") != null)
                {
                    var rightspackageGuid = Guid.Parse(entity.Attributes.Value <string>("_mcs_rightspackage_value"));
                    if (dicProduct.ContainsKey(productGuid) && dicRightspackage.ContainsKey(rightspackageGuid))
                    {
                        dicProduct[productGuid].ProductRightspackageArray.Add(dicRightspackage[rightspackageGuid]);
                    }
                }
            }
            #endregion

            #region 返回对象组装
            foreach (var kv in dicProduct)
            {
                producListResponse.ProductList.Add(kv.Value);
            }
            #endregion

            return(producListResponse);
        }
Example #16
0
        /// <summary>
        /// 预约列表查询
        /// </summary>
        /// <param name="filterstr"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageNum"></param>
        /// <returns></returns>
        public async Task <AppointmentInfoListResponse <CrmEntity> > QueryListByPage(AppointmentInfoRequest filterstr)
        {
            try
            {
                var userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
                #region 查询结果集
                var fetchString = _appointmentInfoRepository.QueryListByPage(filterstr);

                var fetchXdoc    = XDocument.Parse(fetchString);
                var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName  = "mcs_appointmentinfo",
                    FetchXml    = fetchXdoc,
                    ProxyUserId = userInfo?.systemuserid
                };
                fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
                var fetchResponse = await _crmService.Execute(fetchRequest);

                var fetchResponseResult = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
                #endregion

                #region 查询总条数
                var status = 0;
                var fetchAllTotalCountString = _appointmentInfoRepository.QueryListByCount(filterstr, status);
                var fetchAllTotalXdoc        = XDocument.Parse(fetchAllTotalCountString);
                fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName  = "mcs_appointmentinfo",
                    FetchXml    = fetchAllTotalXdoc,
                    ProxyUserId = userInfo?.systemuserid
                };
                fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
                fetchResponse = await _crmService.Execute(fetchRequest);

                var allTotalCountResults = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
                #endregion

                #region 查询待跟进总条数
                status = 10;
                var fetchFollowingCountString = _appointmentInfoRepository.QueryListByCount(filterstr, status);
                var fetchFollowingXdoc        = XDocument.Parse(fetchFollowingCountString);
                fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName  = "mcs_appointmentinfo",
                    FetchXml    = fetchFollowingXdoc,
                    ProxyUserId = userInfo?.systemuserid
                };
                fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
                fetchResponse = await _crmService.Execute(fetchRequest);

                var FollowingCountResults = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
                #endregion

                #region 查询已跟进总条数
                status = 20;
                var fetchFollowedCountString = _appointmentInfoRepository.QueryListByCount(filterstr, status);
                var fetchFollowedXdoc        = XDocument.Parse(fetchFollowedCountString);
                fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName  = "mcs_appointmentinfo",
                    FetchXml    = fetchFollowedXdoc,
                    ProxyUserId = userInfo?.systemuserid
                };
                fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
                fetchResponse = await _crmService.Execute(fetchRequest);

                var FollowedCountResults = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
                #endregion

                var queryResult = new AppointmentInfoListResponse <CrmEntity>();
                queryResult.Results        = fetchResponseResult.Value.Results;
                queryResult.CurrentPage    = filterstr.page;
                queryResult.ALLTotalCount  = (int)allTotalCountResults.Value.Results[0].Attributes["count"];
                queryResult.FollowingCount = (int)FollowingCountResults.Value.Results[0].Attributes["count"];
                queryResult.FollowedCount  = (int)FollowedCountResults.Value.Results[0].Attributes["count"];
                return(queryResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #17
0
        /// <summary>
        /// 查询故障类别代码
        /// </summary>
        /// <param name="malFunctionTypeRequest"></param>
        /// <returns></returns>
        public async Task <QueryResult <CrmEntity> > QueryMalFunctionType(MalFunctionTypeRequest malFunctionTypeRequest)
        {
            try
            {
                var fetchString = _baseDataRepository.QueryMalFunctionType(malFunctionTypeRequest);

                var fetchXdoc    = XDocument.Parse(fetchString);
                var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName = "mcs_malfunctiontype",
                    FetchXml   = fetchXdoc
                };
                var fetchResponse = await _crmService.Execute(fetchRequest);

                var fetchResponseResult = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;

                var queryResult = new QueryResult <CrmEntity>();
                queryResult.Results     = fetchResponseResult.Value.Results;
                queryResult.CurrentPage = malFunctionTypeRequest.page;
                queryResult.TotalCount  = 0;
                return(queryResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #18
0
        public async Task <CustomerQueryListResponse <CrmEntity> > QueryList(int type, int pageindex, string search)
        {
            #region 获取记录结果集
            var filter = await GetQueryListFilter(type, search);

            var fetchXdoc = await GetGetQueryListFetchXml(1, pageindex, filter);

            var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_carserviceadvisor",
                FetchXml   = fetchXdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            var fetchResponse = await _crmService.Execute(fetchRequest);

            var resultsList = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion ;

            #region 查询总记录数
            filter = await GetQueryListFilter(1, search);

            fetchXdoc = await GetGetQueryListFetchXml(2, pageindex, filter);

            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_carserviceadvisor",
                FetchXml   = fetchXdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var allTotalCountResults = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询保修到期
            filter = await GetQueryListFilter(2, search);

            fetchXdoc = await GetGetQueryListFetchXml(2, pageindex, filter);

            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_carserviceadvisor",
                FetchXml   = fetchXdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var wrrantyTotalCountResults = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 查询保险到期
            filter = await GetQueryListFilter(3, search);

            fetchXdoc = await GetGetQueryListFetchXml(3, pageindex, filter);

            fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_carserviceadvisor",
                FetchXml   = fetchXdoc
            };
            fetchRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            fetchResponse = await _crmService.Execute(fetchRequest);

            var insuranceTotalCountResults = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;
            #endregion

            #region 组装返回结果集
            var queryResult = new CustomerQueryListResponse <CrmEntity>();
            queryResult.Results             = resultsList.Value.Results;
            queryResult.CurrentPage         = pageindex;
            queryResult.ALLTotalCount       = (int)allTotalCountResults.Value.Results[0].Attributes["count"];
            queryResult.WarrantyTotalCount  = (int)wrrantyTotalCountResults.Value.Results[0].Attributes["count"];;
            queryResult.InsuranceTotalCount = (int)insuranceTotalCountResults.Value.Results[0].Attributes["count"];;
            return(queryResult);

            #endregion
        }
Example #19
0
        /// <summary>
        /// 综合订单取消
        /// </summary>
        /// <param name="mcs_name"></param>
        /// <param name="mcs_paystatus"></param>
        /// <returns></returns>
        public async Task <ValidateResult <CrmEntity> > CancelOrder(CancelOrderRequest cancelOrder)
        {
            var validateResult = new ValidateResult <CrmEntity>();

            var fetchOrder        = QueryOrder(cancelOrder.OrderCode);
            var fetchXdocOrder    = XDocument.Parse(fetchOrder);
            var fetchOrderRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName = "mcs_tc_order",
                FetchXml   = fetchXdocOrder
            };

            fetchOrderRequest.Headers.Add(dicHeadKey, dicHead[dicHeadKey]);
            var fetchResponse = await _crmService.Execute(fetchOrderRequest);

            var orderResponse = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;

            if (orderResponse.Value.Results.Count == 0)
            {
                validateResult.Data        = null;
                validateResult.Result      = false;
                validateResult.Description = "订单记录不存在";
                return(validateResult);
            }
            CrmEntity order = orderResponse.Value.Results[0];

            if (!order.Attributes.ContainsKey("mcs_paystatus"))
            {
                validateResult.Data        = order;
                validateResult.Result      = false;
                validateResult.Description = "订单记录支付状态为空";
                return(validateResult);
            }

            var upOrder   = new CrmExecuteEntity(order.EntityName, order.Id);
            var paystatus = order.Attributes.Value <int>("mcs_paystatus");

            if (paystatus == (int)PayStatus.NoNeedPay || paystatus == (int)PayStatus.ToBePay)
            {
                upOrder.Attributes.Add("mcs_state", (int)Tc_OrderState.Cancel);
            }
            if (paystatus == (int)PayStatus.Paid)
            {
                if (order.Attributes.ContainsKey("staterecord.createdon"))
                {
                    var date    = DateTime.Now;
                    var paydate = order.Attributes.Value <DateTime>("staterecord.createdon");
                    if (paydate.AddDays(7) < date)
                    {
                        validateResult.Data        = order;
                        validateResult.Result      = false;
                        validateResult.Description = "订单已支付7天,不予许退订了";
                        return(validateResult);
                    }
                }
                upOrder.Attributes.Add("mcs_state", (int)Tc_OrderState.Refunding);
            }
            await _crmService.Update(upOrder);

            validateResult.Data        = order;
            validateResult.Result      = true;
            validateResult.Description = "操作成功";
            return(validateResult);
        }