Example #1
0
        public IQueryable <Gln> GetGlnsByQueryChildrenOnly(IQueryable <Gln> query, GlnQuery queryObj)
        {
            var getParent = IGlnRegistryDb.Glns.Include(p => p.Children)
                            .FirstOrDefault(p => p.OwnGln == queryObj.ParentGln);

            if (!Equals(getParent, null))
            {
                ChildGlnIds = GetGlnIdsOfParentsChildren(getParent.Id);
                query       = query.Where(g => ChildGlnIds.Contains(g.Id));

                if (!string.IsNullOrWhiteSpace(queryObj.SearchTerm))
                {
                    if (SearchTermIsGlnNumber(queryObj))
                    {
                        query = query.Where(g => ChildGlnIds.Contains(g.Id) && g.Assigned &&
                                            (g.OwnGln.Contains(queryObj.SearchTerm)));
                    }
                    else
                    {
                        query = query.Where(g => g.Assigned &&
                                            (g.FriendlyDescriptionPurpose.Contains(queryObj.SearchTerm) ||
                                             g.TruthDescriptionPurpose.Contains(queryObj.SearchTerm)));
                    }
                }
            }

            return(query);
        }
        public void GetGlnsByQuery_SearchTermIncluded()
        {
            // If search term included then returned GLN's should be ordered by parent description
            // Arrange
            var gln = _dbContext.Glns.SingleOrDefault(g => g.OwnGln == "tier1");

            GenerateFiveTierFamily();
            RenameGlnsFriendlyDescriptions();

            var query = new GlnQuery()
            {
                ParentGln    = gln.OwnGln,
                ChildrenOnly = false,
                SearchTerm   = "tier",
                Functional   = false,
                Legal        = false,
                Digital      = false,
                Physical     = false,
                Private      = false,
                Public       = false,
                AllStatus    = false
            };

            // Act
            var result = _glnRepository.GetGlnsByQuery(query);

            // Assert
        }
Example #3
0
        // Get gln digital type ids
        private static List <int> DigitalIdsFilter(this IQueryable <Gln> query, GlnQuery queryObj)
        {
            if (!queryObj.Digital)
            {
                return(new List <int>());
            }

            var glnIds = query.Where(g => g.DigitalType).Select(g => g.Id).ToList();

            return(glnIds);
        }
Example #4
0
        private GlnQuery ConfigureForSearchTerm(GlnQuery queryObj)
        {
            if (!string.IsNullOrWhiteSpace(queryObj.SearchTerm))
            {
                queryObj.SortBy = "parentDescription";
            }
            else
            {
                queryObj.SortBy = "friendlyDescriptionPurpose";
            }

            return(queryObj);
        }
Example #5
0
        public IQueryable <Gln> GetGlnsByQueryAll(IQueryable <Gln> query, GlnQuery queryObj)
        {
            var getParent = IGlnRegistryDb.Glns.FirstOrDefault(p => p.OwnGln == queryObj.ParentGln);
            var ids       = new List <int>();

            if (!Equals(getParent, null))
            {
                ids = GetGlnIdsForEntireFamily(getParent.Id, ids);
            }

            if (SearchTermIsGlnNumber(queryObj))
            {
                query = query.Where(g => ids.Contains(g.Id) && g.Assigned &&
                                    g.OwnGln.Contains(queryObj.SearchTerm));
            }
            else
            {
                query = query.Where(g => ids.Contains(g.Id) && g.Assigned &&
                                    (g.FriendlyDescriptionPurpose.Contains(queryObj.SearchTerm) ||
                                     g.TruthDescriptionPurpose.Contains(queryObj.SearchTerm)));
            }

            return(query);
        }
Example #6
0
        public IHttpActionResult GetGlnByQuery([FromBody] GlnQuery filterResource)
        {
            var queryResult = _unitOfWork.Glns.GetGlnsByQuery(filterResource);

            return(Ok(queryResult));
        }
Example #7
0
        public static IQueryable <Gln> ApplyGlnFiltering(this IQueryable <Gln> query, GlnQuery queryObj)
        {
            // If parent GLN supplied only return children of parent
            if (!string.IsNullOrWhiteSpace(queryObj.ParentGln) && string.IsNullOrWhiteSpace(queryObj.SearchTerm))
            {
                query = query.Where(gln => gln.ParentGln == queryObj.ParentGln);
            }

            if (queryObj.MatchAllTypes)
            {
                query = MatchAllTypesFilter(query, queryObj);
            }
            else
            {
                if (queryObj.Physical || queryObj.Functional || queryObj.Legal || queryObj.Digital)
                {
                    var physicalIds   = PhysicalIdsFilter(query, queryObj);
                    var functionalIds = FunctionalIdsFilter(query, queryObj);
                    var legalIds      = LegalIdsFilter(query, queryObj);
                    var digitalIds    = DigitalIdsFilter(query, queryObj);
                    // TODO: union all id and then query

                    var combinedIds = physicalIds.Union(functionalIds);
                    combinedIds = combinedIds.Union(legalIds);
                    combinedIds = combinedIds.Union(digitalIds);

                    query = query.Where(g => combinedIds.Contains(g.Id));
                }
            }

            query = ApplyStatusFilter(query, queryObj);
            query = PublicPrivateFilter(query, queryObj);

            return(query);
        }
Example #8
0
        private static List <Gln> GetAllGlnsStartingFromSpecifiedParent(List <Gln> query, GlnQuery queryObj)
        {
            var newListGln = query.ToList();

            foreach (var child in newListGln)
            {
                var children = query.Where(gln => gln.ParentGln == queryObj.ParentGln).ToList();

                if (children.Any())
                {
                    newListGln.AddRange(children);
                }
            }

            return(newListGln);
        }
Example #9
0
        public static IQueryable <Gln> MatchAllTypesFilter(this IQueryable <Gln> query, GlnQuery queryObj)
        {
            if (queryObj.MatchAllTypes)
            {
                query = query.Where(gln => gln.PhysicalType == queryObj.Physical &&
                                    gln.FunctionalType == queryObj.Functional &&
                                    gln.DigitalType == queryObj.Digital &&
                                    gln.LegalType == queryObj.Legal);
            }

            return(query);
        }
Example #10
0
        public static IQueryable <Gln> PublicPrivateFilter(this IQueryable <Gln> query, GlnQuery queryObj)
        {
            // If public and private are the same no filter applied
            if ((queryObj.Public && !queryObj.Private) || (!queryObj.Public && queryObj.Private))
            {
                query = query.Where(gln => gln.Public == queryObj.Public);
            }

            return(query);
        }
Example #11
0
        public static IQueryable <Gln> ApplyStatusFilter(this IQueryable <Gln> query, GlnQuery queryObj)
        {
            if (!queryObj.AllStatus)
            {
                query = query.Where(gln => gln.TrustActive == queryObj.TrustActive);
            }

            return(query);
        }
Example #12
0
 private bool SearchTermIsGlnNumber(GlnQuery queryObj)
 {
     // Check first three digits of search term if all are numbers then assume they are searching by GLN
     return(queryObj.SearchTerm.Take(3).All(char.IsNumber));
 }
Example #13
0
        public QueryResult <GlnDto> GetGlnsByQuery(GlnQuery queryObj)
        {
            queryObj = ConfigureForSearchTerm(queryObj);

            var query = IGlnRegistryDb.Glns.AsQueryable();

            query = query.Where(g => g.Assigned);

            var result = new QueryResult <GlnDto>();

            if (!queryObj.ChildrenOnly)
            {
                query = GetGlnsByQueryChildrenOnly(query, queryObj);
            }
            else
            {
                if (string.IsNullOrWhiteSpace(queryObj.SearchTerm))
                {
                    query = GetGlnsByQueryChildrenOnly(query, queryObj);
                }
                else
                {
                    query = GetGlnsByQueryAll(query, queryObj);
                }
            }

            if (!Equals(queryObj.TagTypeIds, null))
            {
                query = GetGlnByTagTypes(query, queryObj.TagTypeIds);
            }

            query = query.ApplyGlnFiltering(queryObj);

            var columnsMap = new Dictionary <string, Expression <Func <Gln, object> > >()
            {
                ["friendlyDescriptionPurpose"] = gln => gln.FriendlyDescriptionPurpose,
                ["parentDescription"]          = gln => gln.ParentDescriptionPurpose,
                ["addressLineTwo"]             = gln => gln.Address.AddressLineTwo,
                ["department"] = gln => gln.Department,
                ["function"]   = gln => gln.Function,
                ["level"]      = gln => gln.TierLevel,
            };

            query = query.ApplyingOrdering(queryObj, columnsMap);

            result.TotalItems = query.Count();

            if (string.IsNullOrWhiteSpace(queryObj.SearchTerm))
            {
                query = query.ApplyPaging(queryObj);
                result.CurrentPage = queryObj.Page;
                result.TotalPages  = Math.Ceiling((double)result.TotalItems / queryObj.PageSize);
            }
            else
            {
                result.CurrentPage = 1;
                result.TotalPages  = 1;
            }

            result.Items = query.Select(DtoHelper.CreateGlnIncludeChildrenDto);

            return(result);
        }