示例#1
0
        public IActionResult UpdateGraphs(GraphFilters filters)
        {
            if (!string.IsNullOrWhiteSpace(filters.ToString()))
            {
                _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email);
                var companyID = _user.CompanyID;

                //We need to build the datasets for the graphs into the viewbag
                var      articlesRead = _context.ArticleReporting.Where(m => m.CompanyID == companyID && m.SegmentName == filters.magazine);
                string[] articles     = articlesRead.Select(d => d.ArticleName).Distinct().ToArray();
                SetupViewsPerArticleReport(articlesRead);
                return(Json(articles));
            }
            return(null);
        }
示例#2
0
        private Func <T, bool> GetFilter(IDictionary <string, GraphFilter> filters)
        {
            Func <T, bool> func = new Func <T, bool>(item => true);

            if (filters == null || filters.Count == 0)
            {
                return(func);
            }

            var strExpression = "item => true";
            var globals       = new GraphFilters {
                Filters = filters
            };
            var options = ScriptOptions.Default
                          .AddImports("Newtonsoft.Json", "System.Collections.Generic", "System.Linq")
                          .AddReferences(typeof(Contract).Assembly, typeof(JsonConvert).Assembly, typeof(List <T>).Assembly);

            filters.ForAll(item => strExpression += $" && {GetFilterType(item.Key, filters)}");
            func = CSharpScript.EvaluateAsync <Func <T, bool> >(strExpression, options, globals).GetAwaiter().GetResult();

            return(func);
        }