Exemple #1
0
        /// <summary>
        /// 试乘试驾预约时段列表查询接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <QueryResult <CrmEntity> > QueryReservationList(DriveReservationRequest request)
        {
            var userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);

            if (userInfo != null && !string.IsNullOrWhiteSpace(userInfo.mcs_dealerid))
            {
                // request.DealerId = Guid.Parse(userInfo.mcs_dealerid);
            }
            #region 查询结果集
            var fetchString = _driveRecordRepository.QueryReservationList(request);

            var fetchXdoc    = XDocument.Parse(fetchString);
            var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
            {
                EntityName  = "mcs_reservationconfiguration",
                FetchXml    = fetchXdoc,
                ProxyUserId = userInfo?.systemuserid
            };
            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;
            return(queryResult);

            #endregion
        }
Exemple #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;
            }
        }
Exemple #3
0
        /// <summary>
        /// 整车订单列表查询
        /// </summary>
        /// <param name="vehorderRequest"></param>
        /// <returns></returns>
        public async Task <QueryResult <CrmEntity> > GetVehorderList(VehorderRequest vehorderRequest)
        {
            try
            {
                var userInfo    = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
                var ProxyUserId = userInfo != null ? userInfo.systemuserid : null;

                var fetchString  = _vehorderRepository.GetVehorderList(vehorderRequest);
                var fetchXdoc    = XDocument.Parse(fetchString);
                var fetchRequest = new CrmRetrieveMultipleFetchRequestMessage()
                {
                    EntityName  = "mcs_vehorder",
                    FetchXml    = fetchXdoc,
                    ProxyUserId = ProxyUserId
                };
                var fetchResponse = await _crmService.Execute(fetchRequest);

                var fetchResponseResult = fetchResponse as CrmRetrieveMultipleFetchResponseMessage;

                var queryResult = new QueryResult <CrmEntity>();
                queryResult.Results     = fetchResponseResult.Value.Results;
                queryResult.CurrentPage = vehorderRequest.PageIndex;
                queryResult.TotalCount  = 0;
                return(queryResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #4
0
        public PAEntity QueryByID(string entityName, Guid id, params string[] columnNames)
        {
            var       orgService   = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService);
            ColumnSet columnSet    = new ColumnSet(columnNames);
            var       entityRecord = orgService.Retrieve(entityName, id, columnSet);

            return(entityRecord.ConvertToDomainEntity <PAEntity>());
        }
        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;
            }
        }
        public OptionMetadata[] GetOptionSet(string entityName, string fieldName)
        {
            var orgId = ContextContainer.GetValue <Guid>(ContextTypes.CurrentOrganization);

            return(_versionVisitor.GetSync((k) =>
            {
                return _paMetadataService.GetOptionSet(entityName, fieldName);
            }, $"{orgId.ToString()}_SOption_{entityName}_{fieldName}"));
        }
        public EntityMetadata GetEntityMetadata(int typeCode)
        {
            var orgId = ContextContainer.GetValue <Guid>(ContextTypes.CurrentOrganization);

            return(_versionVisitor.GetSync((k) =>
            {
                return _paMetadataService.GetEntityMetadata(typeCode);
            }, $"{orgId.ToString()}_TypeCode_{typeCode.ToString()}"));
        }
        public T Get <T>(object[] arguments, Type[] argumentTypes)
        {
            //var argumentTypes = arguments?.Select(a => a.GetType())?.ToArray();

            var factory         = ActivatorUtilities.CreateFactory(typeof(T), argumentTypes);
            var serviceProvider = ContextContainer.GetValue <IServiceProvider>(ContextTypes.ServiceProvider);

            return((T)factory(serviceProvider, arguments));
        }
        public object Get(Type serviceType, params object[] arguments)
        {
            var argumentTypes = arguments?.Select(a => a.GetType())?.ToArray();

            var factory         = ActivatorUtilities.CreateFactory(serviceType, argumentTypes ?? Type.EmptyTypes);
            var serviceProvider = ContextContainer.GetValue <IServiceProvider>(ContextTypes.ServiceProvider);

            return(factory(serviceProvider, arguments));
        }
Exemple #10
0
        public IDIContainer CreateContainer()
        {
            var serviceProvider = ContextContainer.GetValue <IServiceProvider>(ContextTypes.ServiceProvider);
            var scope           = serviceProvider.CreateScope();

            var newContainer = new DIContainerDefault(_serviceCollection, scope);

            return(newContainer);
        }
Exemple #11
0
        public void AddRole(PAUser user, EntityReferenceCollection roleIdList)
        {
            var          orgService       = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService);
            Relationship roleRelationShip = new Relationship("systemuserroles_association");

            if (roleIdList.Count > 0)
            {
                orgService.Associate("systemuser", user.EntityRecord.Id, roleRelationShip, roleIdList);
            }
        }
Exemple #12
0
        /// <summary>
        /// 获取当前环境中的DI容器接口
        /// </summary>
        /// <returns></returns>
        public static IDIContainer Get()
        {
            var di = ContextContainer.GetValue <IDIContainer>("DI");

            if (di == null)
            {
                di = DIContainerContainer.DIContainer;
            }

            return(di);
        }
Exemple #13
0
        /// <summary>
        /// 登陆日志
        /// </summary>
        /// <param name="model"></param>
        /// <param name="id"></param>
        /// <param name="type">1 成功;2失败</param>
        public void LoginLog(UserLoginRequest model, Guid userid, int type)
        {
            var  userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
            Guid logid    = Guid.NewGuid();
            var  entity   = new CrmExecuteEntity("mcs_userloginlog", logid);

            entity.Attributes.Add("mcs_userid", new CrmEntityReference(entityName, userid));
            entity.Attributes.Add("mcs_ip", model.ip);
            entity.Attributes.Add("mcs_loginresult", type);
            entity.Attributes.Add("mcs_logintime", DateTime.Now.ToUniversalTime());
            _crmService.Create(entity, userInfo?.systemuserid);
        }
        public string GenerateUserInfo()
        {
            //获取用户Id上下文信息
            var userID = ContextContainer.GetValue <string>(ContextTypes.CurrentUserId);

            if (userID == null)
            {
                return(string.Empty);
            }

            return(userID);
        }
Exemple #15
0
        public EntityReference GetAdministratorID()
        {
            var orgId = ContextContainer.GetValue <Guid>(ContextTypes.CurrentOrganization);

            var administratorID = _administratorIDCache.GetValue((key) =>
            {
                var configuration = _systemConfigurationRepositoryCacheProxy.QueryByName(SystemConfigurationNames.AdministratorID);
                var id            = configuration.GetConfigurationValue <Guid>();
                return(new EntityReference("systemuser", id));
            }, orgId.ToString());

            return(administratorID);
        }
        public async Task <CommonLogContent> Create(string actionName, string message)
        {
            CommonLogContent content = new CommonLogContent();

            content.ParentID         = ContextContainer.GetValue <Guid>(ContextExtensionTypes.ParentCommonLogID);
            content.ParentActionName = ContextContainer.GetValue <string>(ContextExtensionTypes.ParentCommonLogActionName);
            content.ActionName       = actionName;
            content.Message          = message;
            content.RequestBody      = string.Empty;
            content.ResponseBody     = string.Empty;
            content.RequestUri       = string.Empty;
            return(await Task.FromResult(content));
        }
Exemple #17
0
        public DBAllScope()
        {
            var dict = ContextContainer.GetValue <ConcurrentDictionary <string, object> >(ContextTypes.Dictionary.ToString());

            if (dict != null)
            {
                if (dict.TryGetValue("dball", out object obj))
                {
                    _preValue = obj;
                }
                dict["dball"] = "1";
            }
        }
Exemple #18
0
        public async Task <CommonLogRootContent> CreateFromHttpContext(HttpContext context)
        {
            CommonLogRootContent content = new CommonLogRootContent();

            content.ParentID         = ContextContainer.GetValue <Guid>(ContextExtensionTypes.ParentCommonLogID);
            content.ParentActionName = ContextContainer.GetValue <string>(ContextExtensionTypes.ParentCommonLogActionName);
            content.ActionName       = context.Request.Path;
            content.RequestUri       = context.Request.GetDisplayUrl();
            content.Message          = string.Empty;
            content.RequestBody      = string.Empty;
            content.ResponseBody     = string.Empty;

            return(await Task.FromResult(content));
        }
Exemple #19
0
        public static bool IsAll()
        {
            bool result = false;
            var  dict   = ContextContainer.GetValue <ConcurrentDictionary <string, object> >(ContextTypes.Dictionary.ToString());

            if (dict != null)
            {
                if (dict.TryGetValue("dball", out object obj))
                {
                    result = true;
                }
            }
            return(result);
        }
Exemple #20
0
        public string GenerateUserInfo()
        {
            var currentUserId = ContextContainer.GetValue <string>(ContextTypes.CurrentUserId);

            if (currentUserId == null)
            {
                return(string.Empty);
            }
            else

            {
                return(currentUserId);
            }
        }
Exemple #21
0
        public bool HasEntityPrivilege(PAUser user, EntityReference entityId, PrivilegeTypes privilegeType)
        {
            var metaDateType = _paMetadataServiceCacheProxy.GetEntityMetadata(entityId.LogicalName);

            if (metaDateType.OwnershipType.HasValue)
            {
                switch (metaDateType.OwnershipType.Value)
                {
                case Microsoft.Xrm.Sdk.Metadata.OwnershipTypes.UserOwned:

                    RetrievePrincipalAccessRequest request = new RetrievePrincipalAccessRequest();
                    request.Principal = new EntityReference("systemuser", user.EntityRecord.Id);
                    request.Target    = entityId;
                    IOrganizationService orgService = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService);
                    var response = (RetrievePrincipalAccessResponse)orgService.Execute(request);


                    if (response.AccessRights.HasFlag((AccessRights)(int)privilegeType))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                case Microsoft.Xrm.Sdk.Metadata.OwnershipTypes.OrganizationOwned:
                    var result = HasEntityPrivilege(user, entityId.LogicalName, privilegeType, PrivilegeDepths.Basic);
                    return(result);

                default:
                    return(false);
                }
            }
            else
            {
                var fragment = new TextFragment()
                {
                    Code = TextCodes.EntityNotCheckPrivilege,
                    DefaultFormatting = "实体{0}无法判断权限,它的OwnershipType为空",
                    ReplaceParameters = new List <object>()
                    {
                        entityId.LogicalName
                    }
                };

                throw new UtilityException((int)Errors.EntityNotCheckPrivilege, fragment);
            }
        }
Exemple #22
0
        public SystemConfiguration QueryByName(string name)
        {
            var orgService = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService);

            var strFetch = string.Format(@"<fetch version=""1.0"" output-format=""xml-platform"" mapping=""logical"" distinct=""false"">
                                <entity name=""{0}_systemconfiguration"">
                                    <attribute name=""{0}_content"" /> 
                                    <filter type=""and"">
                                        <condition attribute=""{0}_name"" operator=""eq"" value=""{1}"" />
                                    </filter>
                                </entity>
                            </fetch>", PASolutionInfomation.CommonEntityPrefix, name.ToXML());

            return(PAEntityQueryHelper.Retrive <SystemConfiguration>(strFetch));
        }
Exemple #23
0
        public async Task <CrmEntity> Retrieve(ICrmService crmService, string entityName, Guid id, Guid?userId = null)
        {
            var userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
            var dicHead  = new Dictionary <string, IEnumerable <string> >();

            dicHead.Add("Prefer", new List <string>()
            {
                "odata.include-annotations=\"*\""
            });
            CrmEntity entity = null;

            entity = await crmService.Retrieve(entityName, id, "", userInfo?.systemuserid, dicHead);

            return(entity);
        }
Exemple #24
0
        public OptionMetadata[] GetOptionSet(string optionSetName)
        {
            IOrganizationService orgService = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService);

            RetrieveOptionSetRequest retrieveOptionSetRequest = new RetrieveOptionSetRequest
            {
                Name = optionSetName
            };
            RetrieveOptionSetResponse retrieveOptionSetResponse = (RetrieveOptionSetResponse)orgService.Execute(retrieveOptionSetRequest);
            OptionSetMetadata         optionSetMetadata         = (OptionSetMetadata)retrieveOptionSetResponse.OptionSetMetadata;

            OptionMetadata[] optionList = optionSetMetadata.Options.ToArray();

            return(optionList);
        }
        public async Task <CrmEntity> QueryById(Guid entityId)
        {
            try
            {
                CrmEntity entity   = null;
                var       userInfo = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
                entity = await _crmService.Retrieve(EntityName, entityId, "", userInfo != null?userInfo.systemuserid : null);

                return(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #26
0
        public PAUserSetting GetSetting(PAUser user)
        {
            var defaultEntity = new Entity("usersettings");

            defaultEntity["uilanguageid"] = 2052;
            defaultEntity["timezonebias"] = -480;



            IOrganizationService orgService = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService);

            if (orgService == null)
            {
                return(defaultEntity.ConvertToDomainEntity <PAUserSetting>());
            }


            var strFetch = string.Format(@"<fetch version=""1.0"" output-format=""xml-platform"" mapping=""logical"" distinct=""false"">
                                <entity name=""usersettings"">
                                    <attribute name=""uilanguageid"" />
                                    <attribute name=""timezonebias"" />
                                    <attribute name=""timezonecode"" />
                                    <attribute name=""paginglimit"" />
                                    <attribute name=""numberseparator"" />
                                    <attribute name=""decimalsymbol"" />
                                    <attribute name=""numbergroupformat"" />
                                    <attribute name=""negativeformatcode"" />                  
                                    <attribute name=""dateseparator"" />
                                    <attribute name=""timeseparator"" />
                                    <attribute name=""timeformatstring"" />
                                    <attribute name=""dateformatstring"" />
                                    <filter type=""and"">
                                        <condition attribute=""systemuserid"" operator=""eq"" uitype=""systemuser"" value=""{0}"" />
                                    </filter>
                                </entity>
                            </fetch>", user.EntityRecord.Id.ToString());
            //Logger.WriteLog("orgService is null: " + (orgService==null).ToString(), System.Diagnostics.EventLogEntryType.Warning);
            var entityCollection = orgService.RetrieveMultiple(new FetchExpression(strFetch));

            if (entityCollection.Entities.Count > 0)
            {
                return(entityCollection.Entities[0].ConvertToDomainEntity <PAUserSetting>());
            }
            else
            {
                return(defaultEntity.ConvertToDomainEntity <PAUserSetting>());
            }
        }
Exemple #27
0
        public void Dispose()
        {
            var dict = ContextContainer.GetValue <ConcurrentDictionary <string, object> >(ContextTypes.Dictionary.ToString());

            if (dict != null)
            {
                if (_preValue != null)
                {
                    dict["dball"] = _preValue;
                }
                else
                {
                    dict.TryRemove("dball", out object v);
                }
            }
        }
Exemple #28
0
        /// <summary>
        /// 根据Fetch查询字符串获取Top记录
        /// </summary>
        /// <param name="strFetch"></param>
        /// <param name="size"></param>
        /// <param name="callBack"></param>
        public static void RetriveTop(string strFetch, int size, Action <Entity> callBack)
        {
            var doc = XDocument.Parse(strFetch);

            var orgService = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService);

            doc.Root.SetAttributeValue("count", size.ToString());

            FetchExpression fetchExpression = new FetchExpression(doc.ToString());
            var             queryResponse   = orgService.RetrieveMultiple(fetchExpression);

            foreach (var entityItem in queryResponse.Entities.ToList())
            {
                callBack(entityItem);
            }
        }
Exemple #29
0
        /// <summary>
        /// 根据Fetch查询字符串获取第一条记录
        /// </summary>
        /// <param name="strFetch">Fetch查询字符串</param>
        /// <returns></returns>
        public static T Retrive <T>(string strFetch)
        {
            var orgService = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService);

            FetchExpression fetch    = new FetchExpression(strFetch);
            var             response = orgService.RetrieveMultiple(fetch);

            if (response.Entities.Count > 0)
            {
                return(response.Entities[0].ConvertToDomainEntity <T>());
            }
            else
            {
                return(default(T));
            }
        }
Exemple #30
0
        /// <summary>
        /// 根据Fetch查询字符串获取第一条记录
        /// </summary>
        /// <param name="strFetch">Fetch查询字符串</param>
        /// <returns></returns>
        public static Entity Retrive(string strFetch)
        {
            var orgService = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService);

            FetchExpression fetch    = new FetchExpression(strFetch);
            var             response = orgService.RetrieveMultiple(fetch);

            if (response.Entities.Count > 0)
            {
                return(response.Entities[0]);
            }
            else
            {
                return(null);
            }
        }