public GenericGraphRepository(TContext db,
                               IHttpContextAccessor httpContextAccessor,
                               FillDataExtensions fillDataExtensions,
                               IConfiguration config,
                               IOptionsMonitor <SERGraphQlOptions> optionsDelegate)
 {
     _context             = db;
     _config              = config;
     _httpContextAccessor = httpContextAccessor;
     model               = typeof(T).Name;
     nameModel           = typeof(T).Name.ToSnakeCase().ToLower();
     _cache              = _httpContextAccessor.HttpContext.RequestServices.GetService <IMemoryCache>();
     _handleMsg          = _httpContextAccessor.HttpContext.RequestServices.GetService <IHandleMsg <T> >();
     _logger             = _httpContextAccessor.HttpContext.RequestServices.GetService <ILogger <GenericGraphRepository <T, TContext, TUser, TRole, TUserRole> > >();
     _fillDataExtensions = fillDataExtensions;
     _optionsDelegate    = optionsDelegate;
     _cRepositoryLog     = httpContextAccessor.HttpContext.RequestServices.GetService <AuditManager>();
 }
Beispiel #2
0
        public IObservable <T> Subscribe(IResolveEventStreamContext context)
        {
            Console.WriteLine($" User --------------------------- IsAuthenticated {_httpContextAccessor.HttpContext.User?.Identity?.IsAuthenticated}");

            if (_httpContextAccessor.HttpContext.User?.Identity == null || !_httpContextAccessor.HttpContext.User.Identity.IsAuthenticated)
            {
                context.Errors.Add(new ExecutionError($"Missing Bearer Token"));
                return(new List <T>().ToObservable());
            }

            string field       = context.GetArgument <string>("field");
            int    value       = context.GetArgument <int>("value");
            string stringValue = context.GetArgument <string>("string_value");

            IHandleMsg <T> service = (IHandleMsg <T>)_httpContextAccessor.HttpContext.RequestServices.GetService(typeof(IHandleMsg <T>));
            var            objs    = service.ObservableObj();

            if (!string.IsNullOrEmpty(field) && (value > 0 || !string.IsNullOrEmpty(stringValue)))
            {
                var pi = typeof(T).GetProperty(field);
                if (pi != null)
                {
                    if (!string.IsNullOrEmpty(stringValue))
                    {
                        return(objs.Where(x => (string)pi.GetValue(x) == stringValue));
                    }
                    return(objs.Where(x => (int)pi.GetValue(x) == value));
                }
                else
                {
                    context.Errors.Add(new ExecutionError($"Bad params"));
                    return(new List <T>().ToObservable());
                }
            }

            return(objs);
        }