Пример #1
0
        /// <summary>
        /// Find a group or groups depending on the values supplied in the request.
        /// </summary>
        /// <param name="request">the request that will be used for finding (searching) the required group</param>
        /// <returns>The group or groups found, otherwise nothing.</returns>
        public object Any(FindResourceGroups request)
        {
            //return ExecuteFaultHandledMethod(() =>
            //{
            ResourceGroupsResponse response = new ResourceGroupsResponse();

            if (request != null)
            {
                Expression <Func <JarsResourceGroup, bool> > query = LinqExpressionBuilder.True <JarsResourceGroup>();

                if (!request.GroupName.IsNullOrEmpty())
                {
                    query = query.And(o => o.Name.Like($"%{request.GroupName}%"));
                }

                //IsActive
                if (request.IsActive.HasValue)
                {
                    query = query.And(o => o.IsActive == request.IsActive.Value);
                }

                //var _repository = _DataRepositoryFactory.GetDataRepository<IResourceGroupRepository>();
                var _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <JarsResourceGroup, IDataContextNhJars> >();
                var res         = _repository.Where(query, request.FetchEagerly).ToList();

                var resDto = res.ConvertAll(g => g.ConvertTo <ResourceGroupDto>());
                response.Groups = resDto;
            }
            return(response);
            //});
        }
Пример #2
0
        public MobileResourcesResponse Any(FindMobileResources request)
        {
            MobileResourcesResponse response = new MobileResourcesResponse();
            Expression <Func <JarsResource, bool> > query = LinqExpressionBuilder.True <JarsResource>();

            //default query for mobile resources
            query = query.And(o => o.IsMobileResource == true && o.IsActive == true);

            //Id
            if (request.Id != 0)
            {
                query = query.And(o => o.Id == request.Id);
            }

            //ExternalRef
            if (request.ExternalRef != null && request.ExternalRef != string.Empty)
            {
                query = query.And(j => j.ExtRef == request.ExternalRef);
            }

            //var _repository = _DataRepositoryFactory.GetDataRepository<IResourceRepository>();
            var _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <JarsResource, IDataContextNhJars> >();
            var res         = _repository.Where(query, false).ToList();
            var resDto      = res.ConvertAllTo <MobileResourceDto>().ToList();

            response.Resources = resDto;

            return(response);
        }
Пример #3
0
        public void LinqQueryBuilder_select_data_test_with_nHibernate_Eager()
        {
            JarsJob jj          = new JarsJob();
            var     _repository = _repFactory.GetDataRepository <IGenericEntityRepositoryBase <JarsJob, IDataContextNhJars> >();

            Expression <Func <JarsJob, bool> > query = null;
            bool hasWhere = false;

            int    Id       = 1;
            string ExtRefId = "11";


            //Id
            if (Id != 0)
            {
                query    = LinqExpressionBuilder.True <JarsJob>().And(j => j.Id == Id);
                hasWhere = true;
            }

            //ExtRefId
            if (ExtRefId != "0")
            {
                if (!hasWhere)
                {
                    query    = LinqExpressionBuilder.True <JarsJob>().And(j => j.ExtRefId == ExtRefId);
                    hasWhere = true;
                }
                else
                {
                    query.And(j => j.ExtRefId == ExtRefId);
                }
            }

            var res = _repository.Where(query, true);

            Assert.IsNotNull(res);

            int[] ids = new[] { 1, 2, 3 };
            query = LinqExpressionBuilder.True <JarsJob>().And(j => ids.ToList().Contains(j.Id));

            var rIn = _repository.Where(query, true);

            Assert.IsNotNull(rIn);

            string[] refs = new[] { "11", "33", "55" };
            query = LinqExpressionBuilder.True <JarsJob>().And(j => j.LineOfWork.Like("MU%"));

            var rLike = _repository.Where(query, true);

            Assert.IsNotNull(rLike);
        }
Пример #4
0
        public object Any(FindActivityLogs request)
        {
            return(ExecuteFaultHandledMethod(() =>
            {
                //IActivityLogRepository repository = _DataRepositoryFactory.GetDataRepository<IActivityLogRepository>();
                var repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <ActivityLog, IDataContextNhJars> >();
                //FindActivityLogsResponse response = new FindActivityLogsResponse();
                ActivityLogsResponse response = new ActivityLogsResponse();

                //var ret = response.Logs.AsQueryable();
                //ret.Where(a => a.Category == "");

                var query = LinqExpressionBuilder.True <ActivityLog>();//.And(a => a.Id != null);//QueryOver.Of<ActivityLog>();

                if (!request.Category.IsNullOrEmpty())
                {
                    query.And(a => a.Category == request.Category);
                }

                if (!request.LinkedId.IsNullOrEmpty())
                {
                    query.And(a => a.LinkedId == request.LinkedId);
                }

                if (request.ResourceId != 0)
                {
                    query.And(a => a.ResourceId == request.ResourceId);
                }

                if (!request.Name.IsNullOrEmpty())
                {
                    query.And(a => a.Name == request.Name);
                }

                if (request.StartDateTime.HasValue)
                {
                    query.And(a => a.StartDateTime >= request.StartDateTime);
                }

                if (request.EndDateTime.HasValue)
                {
                    query.And(a => a.EndDateTime >= request.EndDateTime);
                }

                response.Logs = repository.Where(query).ConvertAllTo <ActivityLogDto>().ToList();

                return response;
            }));
        }
Пример #5
0
        /// <summary>
        /// A helper method used for building the query, depending on if the LoadLazy option was set.
        /// </summary>
        /// <typeparam name="T">A query over object required by the QueryOver Method on the repository</typeparam>
        /// <param name="request">The same request passed into the service</param>
        /// <returns></returns>
        private Expression <Func <JarsJob, bool> > BuildQuery(FindJarsJobs request)
        {
            Expression <Func <JarsJob, bool> > query = LinqExpressionBuilder.True <JarsJob>();

            //Id
            if (request.Id != 0)
            {
                query = LinqExpressionBuilder.True <JarsJob>().And(j => j.Id == request.Id);
            }

            //ExtRefID
            if (request.ExtRefID != "0")
            {
                query = query.And(j => j.ExtRefId == request.ExtRefID);
            }

            //ResourceID
            if (request.ResourceId != 0)
            {
                query = query.And(j => j.ResourceId == request.ResourceId);
            }

            //Location
            if (request.Location != null)
            {
                query = query.And(j => j.Location == request.Location);
            }

            //CompletionDate
            if (request.ProgressStatus != null)
            {
                query = query.And(j => j.ProgressStatus == request.ProgressStatus);
            }

            //StartDateTime
            if (request.StartDate != DateTime.MinValue)
            {
                query = query.And(j => j.StartDate >= request.StartDate);
            }

            //EndDateTime
            if (request.EndDateTime != DateTime.MinValue)
            {
                query = query.And(j => j.EndDate <= request.EndDateTime);
            }

            return(query);
        }
Пример #6
0
        /// <summary>
        /// A helper method used for building the query, depending on if the LoadLazy option was set.
        /// </summary>
        /// <typeparam name="T">A query over object required by the QueryOver Method on the repository</typeparam>
        /// <param name="request">The same request passed into the service</param>
        /// <param name="hasWhere">a bool value indicating if there is a where string</param>
        /// <returns></returns>
        private Expression <Func <T, bool> > BuildQuery <T>(FindJarsRules request) where T : JarsRule
        {
            Expression <Func <T, bool> > query = LinqExpressionBuilder.True <T>();

            if (!request.TargetEntityTypeName.IsNullOrEmpty())
            {
                query = query.And(o => o.TargetTypeName == request.TargetEntityTypeName);
            }

            if (!request.SourceEntityTypeName.IsNullOrEmpty())
            {
                query = query.And(o => o.SourceTypeName == request.SourceEntityTypeName);
            }

            return(query);
        }
Пример #7
0
        /// <summary>
        /// Find a BOSRecord by specifying values for the properties available in the request.
        /// Date values: Start date will go from date forward, end date will be from end date back, and if both has values,
        /// it will be used as from (between) start to end
        /// </summary>
        /// <param name="request">The request used for building the find parameters</param>
        /// <returns>If LoadLazy was true, then a list of JarsBOSRecordBase items, otherwise a list of fully loaded JarsBOSRecords</returns>
        public virtual BOSEntitiesResponse Any(FindBOSEntities request)
        {
            BOSEntitiesResponse response = new BOSEntitiesResponse();

            if (request != null)
            {
                Expression <Func <BOSEntity, bool> > query = LinqExpressionBuilder.True <BOSEntity>();

                //Id
                if (request.ResourceId != null)
                {
                    query = query.And(a => a.ResourceId == int.Parse(request.ResourceId));
                }

                //StartDateTime
                if (request.StartDate.HasValue && request.StartDate != DateTime.MinValue)
                {
                    query = query.And(a => a.StartDate.Date >= request.StartDate.Value.Date);
                }

                //EndDateTime (unlike the mobile version we dont set the end date = start date if the end date is empty)
                if (request.EndDate.HasValue && request.EndDate != DateTime.MinValue)
                {
                    query = query.And(a => a.EndDate.Date <= request.EndDate.Value.Date);
                }


                //statuses
                if (!request.Statuses.IsNullOrEmpty())
                {
                    //if the status value contains a , then split it, otherwise just use as is
                    if (request.Statuses.Contains(','))
                    {
                        string[] arrStatus = request.Statuses.Split(new[] { ',' });
                        query = query.And(a => arrStatus.Contains(a.ProgressStatus));
                    }
                    else
                    {
                        query = query.And(a => a.ProgressStatus == request.Statuses);
                    }
                }

                IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> >();
                response.BOSEntities = _repository.Where(query, true).ConvertAllTo <BOSEntityDto>().ToList();
            }
            return(response);
        }
Пример #8
0
        /// <summary>
        /// A helper method used for building the query, depending on if the LoadLazy option was set.
        /// </summary>
        /// <typeparam name="T">A query over object required by the QueryOver Method on the repository</typeparam>
        /// <param name="request">The same request passed into the service</param>
        /// <param name="hasWhere">a bool value indicating if there is a where string</param>
        /// <returns></returns>
        private Expression <Func <ApptLabel, bool> > BuildQuery <T>(FindApptLabels request)
        {
            Expression <Func <ApptLabel, bool> > query = LinqExpressionBuilder.True <ApptLabel>();

            //DisplayName
            if (request.ViewType != null && request.ViewType != string.Empty)
            {
                query = query.And(j => j.ViewName == request.ViewType);
            }

            //IsActive
            if (request.LabelName != null && request.LabelName != string.Empty)
            {
                query = query.And(o => o.LabelName.Like($"{request.LabelName}%"));
            }

            return(query);
        }
Пример #9
0
        /// <summary>
        /// A helper method used for building the query, depending on if the LoadLazy option was set.
        /// </summary>
        /// <typeparam name="T">A query over object required by the QueryOver Method on the repository</typeparam>
        /// <param name="request">The same request passed into the service</param>
        /// <param name="hasWhere">a bool value indicating if there is a where string</param>
        /// <returns></returns>
        private Expression <Func <T, bool> > BuildQuery <T>(FindResources request) where T : Entities.JarsResource
        {
            Expression <Func <T, bool> > query = LinqExpressionBuilder.True <T>();

            //Id
            if (request.Id != 0)
            {
                query = query.And(o => o.Id == request.Id);
            }

            //ExternalRef
            if (request.ExternalRef != null && request.ExternalRef != string.Empty)
            {
                query = query.And(j => j.ExtRef == request.ExternalRef);
            }

            //ExternalRef1
            if (request.ExternalRef1 != null && request.ExternalRef1 != string.Empty)
            {
                query = query.And(O => O.ExtRef1 == request.ExternalRef1);
            }

            //ExternalRef2
            if (request.ExternalRef2 != null && request.ExternalRef2 != string.Empty)
            {
                query = query.And(O => O.ExtRef2 == request.ExternalRef2);
            }

            //DisplayName
            if (request.DisplayName != null && request.DisplayName != string.Empty)
            {
                query = query.And(j => j.DisplayName == request.DisplayName);
            }

            //IsActive
            if (request.IsActive.HasValue)
            {
                query = query.And(o => o.IsActive == request.IsActive.Value);
            }

            return(query);
        }
Пример #10
0
        public ApptStatusesResponse Any(FindApptStatuses request)
        {
            return(ExecuteFaultHandledMethod(() =>
            {
                ApptStatusesResponse response = new ApptStatusesResponse();
                if (request != null)
                {
                    Expression <Func <ApptStatus, bool> > query = LinqExpressionBuilder.True <ApptStatus>();

                    //DisplayName
                    if (!request.ViewType.IsNullOrEmpty())
                    {
                        query = query.And(j => j.ViewName == request.ViewType);
                    }

                    //IsActive
                    if (!request.StatusName.IsNullOrEmpty())
                    {
                        query = query.And(o => o.StatusName.Like($"{request.StatusName}%"));
                    }

                    //var _repository = _DataRepositoryFactory.GetDataRepository<IApptStatusRepository>();
                    var _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <ApptStatus, IDataContextNhJars> >();

                    IList <ApptStatus> resList = _repository.Where(query).ToList();
                    if (resList.Count == 0 && request.ViewType != "" && request.StatusName == null)
                    {
                        CreateDefaultRecord(request, _repository);
                        response.Statuses = _repository.Where(query).ToList().ConvertAll(s => s.ConvertTo <ApptStatusDto>());
                    }
                    else
                    {
                        response.Statuses = resList.ToList().ConvertAll(s => s.ConvertTo <ApptStatusDto>());
                    }

                    //call the extension method to remove any sub child parent references.
                    //response.UpdateChildReferences();
                }
                return response;
            }));
        }
Пример #11
0
        /// <summary>
        /// A helper method used for building the query, depending on if the LoadLazy option was set.
        /// </summary>
        /// <typeparam name="T">A query over object required by the QueryOver Method on the repository</typeparam>
        /// <param name="request">The same request passed into the service</param>
        /// <param name="hasWhere">a bool value indicating if there is a where string</param>
        /// <returns></returns>
        private Expression <Func <T, bool> > BuildQuery <T>(FindStandardAppointments request) where T : StandardAppointment
        {
            Expression <Func <T, bool> > query = LinqExpressionBuilder.True <T>();

            //the default value of loading recurring appointments will always be added.
            query = query.Or(a => a.RecurrenceInfo != null);

            //StartDateTime
            if (request.FromStartDate.HasValue && request.FromStartDate != DateTime.MinValue)
            {
                query = query.And(a => a.StartDate >= request.FromStartDate);
            }

            //EndDateTime
            if (request.ToEndDate.HasValue && request.ToEndDate != DateTime.MinValue)
            {
                query = query.And(a => a.EndDate <= request.ToEndDate);
            }

            //resourcelist
            if (!request.InCalendarForResources.IsNullOrEmpty())
            {
                string[] resIds = request.InCalendarForResources.Split(',');
                query = query.And(a => resIds.Contains(a.ResourceId.ToString()));
            }

            //with description like
            if (request.WithAppointmentDescription != null && request.WithAppointmentDescription != string.Empty)
            {
                query = query.And(a => a.Subject.Contains(request.WithAppointmentDescription) || a.Description.Contains(request.WithAppointmentDescription));
            }

            //Id
            if (request.Id != 0)
            {
                query = query.And(a => a.Id == request.Id);
            }

            return(query);
        }
        /// <summary>
        /// A helper method used for building the query, depending on if the LoadLazy option was set.
        /// </summary>
        /// <typeparam name="T">A query over object required by the QueryOver Method on the repository</typeparam>
        /// <param name="request">The same request passed into the service</param>
        /// <param name="hasWhere">a bool value indicating if there is a where string</param>
        /// <returns></returns>
        private Expression <Func <T, bool> > BuildQuery <T>(FindStandardAppointmentExceptions request) where T : StandardAppointmentException
        {
            Expression <Func <T, bool> > query = LinqExpressionBuilder.True <T>();

            //Id
            if (request.Id != 0)
            {
                query = query.And(a => a.Id == request.Id);
            }

            //StartDateTime
            if (request.FromStartDate != DateTime.MinValue)
            {
                query = query.And(a => a.StartDate >= request.FromStartDate);
            }

            //EndDateTime
            if (request.ToEndDate != DateTime.MinValue)
            {
                query = query.And(a => a.EndDate <= request.ToEndDate);
            }

            return(query);
        }
Пример #13
0
        /// <summary>
        /// Find a BOSRecord by specifying values for the properties available in the request.
        /// Date values: Start date will go from date forward, end date will be from end date back, and if both has values,
        /// it will be used as from (between) start to end
        /// </summary>
        /// <param name="request">The request used for building the find parameters</param>
        /// <returns>If LoadLazy was true, then a list of JarsBOSRecordBase items, otherwise a list of fully loaded JarsBOSRecords</returns>
        public virtual object Any(FindMobileBOSEntities request)
        {
            //https://github.com/ServiceStack/ServiceStack.Text#global-default-json-configuration

            MobileBOSEntitiesResponse response = new MobileBOSEntitiesResponse();

            if (request != null)
            {
                Expression <Func <BOSEntity, bool> > query = LinqExpressionBuilder.True <BOSEntity>();

                //Id
                if (request.ResourceId != null)
                {
                    query = query.And(a => a.ResourceId == int.Parse(request.ResourceId));
                }

                //StartDateTime
                if (request.StartDate.HasValue && request.StartDate != DateTime.MinValue)
                {
                    query = query.And(a => a.StartDate.Date >= request.StartDate.Value.Date);
                }

                //EndDateTime
                if (request.EndDate.HasValue && request.EndDate != DateTime.MinValue)
                {
                    query = query.And(a => a.EndDate.Date <= request.EndDate.Value.Date);
                }
                else
                {
                    //set end date to start date so that we only get one day by default
                    if (request.StartDate.HasValue && request.StartDate != DateTime.MinValue)
                    {
                        query = query.And(a => a.EndDate.Date <= request.StartDate.Value.Date);
                    }
                }

                //statuses
                if (!request.Statuses.IsNullOrEmpty())
                {
                    //if the status value contains a , then split it, otherwise just use as is
                    if (request.Statuses.Contains(','))
                    {
                        string[] arrStatus = request.Statuses.Split(new[] { ',' });
                        query = query.And(a => arrStatus.Contains(a.ProgressStatus));
                    }
                    else
                    {
                        query = query.And(a => a.ProgressStatus == request.Statuses);
                    }
                }

                IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <BOSEntity, IDataContextBOS> >();
                response.BOSEntities = _repository.Where(query, true).ConvertAllTo <MobileBOSEntityDto>().ToList();
            }

            return(new HttpResult(response)
            {
                ResultScope = () =>
                              JsConfig.With(new Config
                {
                    AssumeUtc = true,
                    DateHandler = DateHandler.ISO8601DateTime
                })
            });
            //using (JsConfig.With(new Config { DateHandler = DateHandler.ISO8601 }))
            //{
            //    return response;
            //}
        }