Exemplo n.º 1
0
    protected virtual IQueryable <TEntity> BuildQuery(EntitySelectQuery <TReadModel> request, IQueryable <TEntity> query)
    {
        if (request is null)
        {
            throw new ArgumentNullException(nameof(request));
        }
        if (query is null)
        {
            throw new ArgumentNullException(nameof(query));
        }

        var entitySelect = request?.Select;

        // build query from filter
        if (entitySelect?.Filter != null)
        {
            query = query.Filter(entitySelect.Filter);
        }

        // add raw query
        if (!string.IsNullOrEmpty(entitySelect?.Query))
        {
            query = query.Where(entitySelect.Query);
        }

        return(query);
    }
Exemplo n.º 2
0
        public async Task <ActionResult <IReadOnlyCollection <TemplateEditorModel> > > Get(CancellationToken cancellationToken)
        {
            var command = new EntitySelectQuery <TemplateEditorModel>(User, new EntitySelect());
            var result  = await Mediator.Send(command, cancellationToken);

            return(Ok(result));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync()
        {
            var select = new EntitySelect();

            select.Filter = CreateFilter();
            select.Sort   = new List <EntitySort>
            {
                new EntitySort {
                    Name = nameof(TopicListModel.CalendarYear)
                },
                new EntitySort {
                    Name = nameof(TopicListModel.TargetMonth)
                },
                new EntitySort {
                    Name = nameof(TopicListModel.Title)
                }
            };

            var query = new EntitySelectQuery <TopicListModel>(User, select);

            var topics = await Mediator.Send(query);

            var fileName = $"Topics-{DateTime.Now:yyyy-MM-dd-HH-mm-ss}.csv";

            return(Export(topics, fileName));
        }
Exemplo n.º 4
0
        protected virtual async Task <IReadOnlyCollection <TReadModel> > SelectQuery(EntitySelect entitySelect, CancellationToken cancellationToken = default)
        {
            var command = new EntitySelectQuery <TReadModel>(User, entitySelect);
            var result  = await Mediator.Send(command, cancellationToken);

            return(result);
        }
Exemplo n.º 5
0
        public async Task EntitySelectQueryDeleteNested()
        {
            var mediator = ServiceProvider.GetService <IMediator>();

            mediator.Should().NotBeNull();

            var mapper = ServiceProvider.GetService <IMapper>();

            mapper.Should().NotBeNull();

            var filter = new EntityFilter
            {
                Filters = new List <EntityFilter>
                {
                    new EntityFilter {
                        Name = "IsDeleted", Value = true
                    },
                    new EntityFilter {
                        Name = "StatusId", Value = StatusConstants.NotStarted.Id
                    }
                }
            };


            var select      = new EntitySelect(filter);
            var selectQuery = new EntitySelectQuery <TaskReadModel>(MockPrincipal.Default, select);

            var selectResult = await mediator.Send(selectQuery).ConfigureAwait(false);

            selectResult.Should().NotBeNull();
        }
    protected virtual IReadOnlyCollection <TReadModel> QueryList(EntitySelectQuery <TReadModel> request, IQueryable <TEntity> query, CancellationToken cancellationToken)
    {
        var results = query
                      .Sort(request?.Select?.Sort)
                      .ToList();

        return(Mapper.Map <IList <TEntity>, IReadOnlyCollection <TReadModel> >(results));
    }
Exemplo n.º 7
0
 protected virtual async Task <IReadOnlyCollection <TReadModel> > QueryList(EntitySelectQuery <TReadModel> request, IQueryable <TEntity> query, CancellationToken cancellationToken)
 {
     return(await query
            .Sort(request?.Select?.Sort)
            .ProjectTo <TReadModel>(Mapper.ConfigurationProvider)
            .ToListAsync(cancellationToken)
            .ConfigureAwait(false));
 }
Exemplo n.º 8
0
        private async Task LoadRoles()
        {
            var command = new EntitySelectQuery <RoleReadModel>(User, new EntitySelect());
            var roles   = await Mediator.Send(command);

            Roles = roles
                    .OrderBy(m => m.Name)
                    .ToList();
        }
Exemplo n.º 9
0
        protected virtual IQueryable <TEntity> BuildQuery(EntitySelectQuery <TReadModel> request, IQueryable <TEntity> query)
        {
            // build query from filter
            if (request?.Select?.Filter != null)
            {
                query = query.Filter(request.Select.Filter);
            }

            return(query);
        }
Exemplo n.º 10
0
        protected override async Task <IReadOnlyCollection <TEntityModel> > Process(
            EntitySelectQuery <TEntityModel> request,
            CancellationToken cancellationToken,
            RequestHandlerDelegate <IReadOnlyCollection <TEntityModel> > next)
        {
            // add tenant filter
            request.Filter = await RewriteFilter(request.Filter, request.Principal).ConfigureAwait(false);

            // continue pipeline
            return(await next().ConfigureAwait(false));
        }
Exemplo n.º 11
0
    protected virtual async Task <IReadOnlyCollection <TReadModel> > QueryList(EntitySelectQuery <TReadModel> request, IQueryable <TEntity> query, CancellationToken cancellationToken)
    {
        if (request is null)
        {
            throw new ArgumentNullException(nameof(request));
        }

        var results = await query
                      .Sort(request.Select?.Sort)
                      .ToListAsync(cancellationToken)
                      .ConfigureAwait(false);

        return(Mapper.Map <IList <TEntity>, IReadOnlyCollection <TReadModel> >(results));
    }
Exemplo n.º 12
0
        private async Task LoadAttendances()
        {
            var filter = new EntityFilter
            {
                Operator = EntityFilterOperators.Equal,
                Name     = nameof(AttendanceSessionModel.SessionId),
                Value    = Id
            };
            var select  = new EntitySelect(filter);
            var command = new EntitySelectQuery <AttendanceSessionModel>(User, select);
            var results = await Mediator.Send(command);

            Attendances = results.ToList();
        }
Exemplo n.º 13
0
        protected override async Task <IReadOnlyCollection <TReadModel> > Process(EntitySelectQuery <TReadModel> request, CancellationToken cancellationToken)
        {
            var query = DataContext
                        .Set <TEntity>()
                        .AsNoTracking();

            // build query from filter
            query = BuildQuery(request, query);

            // page the query and convert to read model
            var result = await QueryList(request, query, cancellationToken)
                         .ConfigureAwait(false);

            return(result);
        }
 public static TObject GetModel <TObject>(TObject workingObject, EntitySelectQuery selectQuery)
     where TObject : class, IEntityObject, IEntityObject <TObject>
 {
     using (var context = new ModelsDbContext())
     {
         context.Configuration.ProxyCreationEnabled = false;
         try
         {
             return(EntitySelectQuery.GetQueryable(workingObject, selectQuery, context).FirstOrDefault());
         }
         catch (Exception ex)
         {
             throw new Exception("Failed To Get Object From Db", ex);
         }
     }
 }
Exemplo n.º 15
0
        private async Task <List <SignUpTopicReadModel> > LoadSignUpTopics()
        {
            var filter = new EntityFilter
            {
                Name     = nameof(SignUpTopicReadModel.SignUpId),
                Value    = Id,
                Operator = EntityFilterOperators.Equal
            };
            var select  = new EntitySelect(filter);
            var command = new EntitySelectQuery <SignUpTopicReadModel>(User, select);
            var result  = await Mediator.Send(command);

            return(result
                   .OrderBy(p => p.TopicCalendarYear)
                   .ThenBy(p => p.TopicTargetMonth)
                   .ThenBy(p => p.TopicTitle)
                   .ToList());
        }
    protected virtual IQueryable <TEntity> BuildQuery(EntitySelectQuery <TReadModel> request, IQueryable <TEntity> query)
    {
        var entitySelect = request?.Select;

        // build query from filter
        if (entitySelect?.Filter != null)
        {
            query = query.Filter(entitySelect.Filter);
        }

        // add raw query
        if (!string.IsNullOrEmpty(entitySelect?.Query))
        {
            query = query.Where(entitySelect.Query);
        }

        return(query);
    }
    protected override Task <IReadOnlyCollection <TReadModel> > Process(EntitySelectQuery <TReadModel> request, CancellationToken cancellationToken)
    {
        if (request is null)
        {
            throw new ArgumentNullException(nameof(request));
        }

        var query = Repository.All();

        // build query from filter
        query = BuildQuery(request, query);

        // page the query and convert to read model
        var result = QueryList(request, query, cancellationToken);

        //TODO make async?
        return(Task.FromResult(result));
    }
    protected override async Task <IReadOnlyCollection <TEntityModel> > Process(EntitySelectQuery <TEntityModel> request, CancellationToken cancellationToken, RequestHandlerDelegate <IReadOnlyCollection <TEntityModel> > next)
    {
        if (request is null)
        {
            throw new ArgumentNullException(nameof(request));
        }

        if (next is null)
        {
            throw new ArgumentNullException(nameof(next));
        }

        // add delete filter
        request.Select.Filter = RewriteFilter(request.Select?.Filter, request.Principal);

        // continue pipeline
        return(await next().ConfigureAwait(false));
    }
Exemplo n.º 19
0
        private async Task <IReadOnlyCollection <TopicReadModel> > LoadTopics()
        {
            var filter = new EntityFilter
            {
                Name     = nameof(TopicReadModel.CalendarYear),
                Value    = DateTime.Now.Year,
                Operator = EntityFilterOperators.GreaterThanOrEqual
            };
            var select  = new EntitySelect(filter);
            var command = new EntitySelectQuery <TopicReadModel>(User, select);
            var result  = await Mediator.Send(command);

            return(result
                   .OrderBy(p => p.CalendarYear)
                   .ThenBy(p => p.TargetMonth)
                   .ThenBy(p => p.Title)
                   .ToList());
        }
 public static EList <TObject> GetModels <TObject>(TObject workingObject, EntitySelectQuery selectQuery)
     where TObject : class, IEntityObject, IEntityObject <TObject>
 {
     using (var context = new ModelsDbContext())
     {
         context.Configuration.ProxyCreationEnabled = false;
         try
         {
             var query = EntitySelectQuery.GetQueryable(workingObject, selectQuery, context);
             var eList = new EList <TObject>();
             eList.AddRange(query.ToList());
             return(eList);
         }
         catch (Exception ex)
         {
             throw new Exception("Failed To Get Object From Db", ex);
         }
     }
 }
Exemplo n.º 21
0
    protected override async Task <IReadOnlyCollection <TReadModel> > Process(EntitySelectQuery <TReadModel> request, CancellationToken cancellationToken)
    {
        if (request is null)
        {
            throw new ArgumentNullException(nameof(request));
        }

        var cosmosQuery = await Repository
                          .GetQueryableAsync()
                          .ConfigureAwait(false);

        // build query from filter
        var query = BuildQuery(request, cosmosQuery);

        // page the query and convert to read model
        var result = await QueryList(request, query, cancellationToken).ConfigureAwait(false);

        return(result);
    }
Exemplo n.º 22
0
        private async Task <IReadOnlyCollection <TopicDropdownModel> > LoadTopics()
        {
            var select = new EntitySelect();

            if (Year.HasValue)
            {
                var filter = new EntityFilter();
                filter.Name  = nameof(Core.Data.Entities.Topic.CalendarYear);
                filter.Value = Year.Value;

                select.Filter = filter;
            }

            var query  = new EntitySelectQuery <TopicDropdownModel>(User, select);
            var topics = await Mediator.Send(query);

            return(topics
                   .OrderBy(p => p.Text)
                   .ToList());
        }