Exemplo n.º 1
0
        public IActionResult Search([FromBody] MetadataSearch search, [FromQuery] bool incArchive = false)
        {
            string currentUser = HttpContext.User.Identity.Name;

            if (search == null)
            {
                return(_securityRepository.GateNotFound(currentUser, AccessLogAction.DocumentMetadataSearch, "Metadata", search.BusinessArea));
            }

            if (!_securityRepository.UserIsAuthorisedByBuisnessAreas(HttpContext, AuthActions.Return, search.BusinessArea))
            {
                return(_securityRepository.GateUnathorised(currentUser, AccessLogAction.DocumentMetadataSearch, "Metadata", search.BusinessArea));
            }

            var result = _metadataRepository.SearchByMetadataSearch(search, incArchive);

            _securityRepository.LogUserAction(currentUser, AccessLogAction.DocumentMetadataSearch, search.BusinessArea, "Metadata", true);

            _securityRepository.LogUserSearch(currentUser, search);

            _securityRepository.SaveChanges();

            return(Ok(result));
        }
Exemplo n.º 2
0
 public void LogUserSearch(string user, MetadataSearch search)
 {
     _context.SearchLogs.Add(new SearchLogEntity(user, search));
 }
Exemplo n.º 3
0
        public List <MetadataEntity> SearchByMetadataSearch(MetadataSearch search, bool incArchive)
        {
            var searchContext = _context.MetadataEntities.AsQueryable().Where(gg => gg.BuisnessArea == search.BusinessArea && gg.Archive.Is == incArchive);

            List <MetadataEntity> results = new List <MetadataEntity>();

            foreach (var item in search.Search)
            {
                switch (item.Type)
                {
                case "AllKeys":
                {
                    var keys = (SearchAllKeys)item;
                    var tmp  = searchContext.Where(gg => gg.Metadata.ContainsValue(keys.Value)).ToList();
                    if (search.Joiner == SearchJoin.And)
                    {
                        results.AddRange(tmp);
                    }
                    else
                    {
                        if (results.Count >= 1)
                        {
                            results.AddRange(tmp);
                        }
                        else
                        {
                            results.RemoveAll(it => tmp.Contains(it));
                        }
                    }
                    break;
                }

                case "Equality":
                {
                    var keys = (SearchEquality)item;
                    List <MetadataEntity> entities = new List <MetadataEntity>();
                    if (keys.Invert)
                    {
                        entities.AddRange(searchContext.Where(gg => gg.Metadata[keys.Key] != keys.Value).ToList());
                    }
                    else
                    {
                        entities.AddRange(searchContext.Where(gg => gg.Metadata[keys.Key] == keys.Value).ToList());
                    }

                    if (search.Joiner == SearchJoin.And)
                    {
                        results.AddRange(entities);
                    }
                    else
                    {
                        if (results.Count >= 1)
                        {
                            results.AddRange(entities);
                        }
                        else
                        {
                            results.RemoveAll(it => entities.Contains(it));
                        }
                    }
                    break;
                }

                case "Present":
                {
                    var keys = (SearchPresent)item;
                    List <MetadataEntity> entities = new List <MetadataEntity>();
                    if (keys.Invert)
                    {
                        entities.AddRange(searchContext.Where(gg => gg.Metadata.ContainsKey(keys.Key) == false).ToList());
                    }
                    else
                    {
                        entities.AddRange(searchContext.Where(gg => gg.Metadata.ContainsKey(keys.Key)).ToList());
                    }

                    if (search.Joiner == SearchJoin.And)
                    {
                        results.AddRange(entities);
                    }
                    else
                    {
                        if (results.Count >= 1)
                        {
                            results.AddRange(entities);
                        }
                        else
                        {
                            results.RemoveAll(it => entities.Contains(it));
                        }
                    }
                    break;
                }

                default:
                    throw new Exception("Unable to read Input SearchType");
                }
            }

            return(results);
        }