Пример #1
0
        /// <inheritdoc />
        public async Task <PagedResult <RoomEntity> > GetRoomsAsync(PagingModel paging)
        {
            var rooms = await _linqProvider.Query <RoomEntity>()
                        .AsPagedAsync(paging.Page, paging.Size);

            return(rooms);
        }
Пример #2
0
        /// <inheritdoc />
        public async Task <PagedResult <BookingEntity> > GetBookingsAsync(int page, int size)
        {
            var bookings = await _linqProvider.Query <BookingEntity>()
                           .AsPagedAsync(page, size);

            return(bookings);
        }
 public Task <DeliveryInterval> AskAsync(DeliveryIntervalWithTemplateByIdCriterion criterion)
 {
     return(_linqProvider.Query <DeliveryInterval>()
            .Include(x => x.DeliveryIntervalTemplate)
            .Where(x => x.Id == criterion.DeliveryIntervalId)
            .FirstOrDefaultAsync());
 }
 public Task <SubscriptionDate> AskAsync(LastSubscriptionDateForSubscriptionRepositoryCriterion criterion)
 {
     return(_linqProvider.Query <SubscriptionDate>()
            .Where(x => x.SubscriptionId == criterion.SubscriptionId)
            .OrderByDescending(x => x.Date)
            .FirstOrDefaultAsync());
 }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AddBookingFilterValidator" /> class.
        /// </summary>
        public AddBookingFilterValidator(ILinqProvider linqProvider)
        {
            RuleFor(x => x.StartDate)
            .LessThanOrEqualTo(x => x.EndDate)
            .WithMessage("'startdDate' cannot be greater that 'endDate'");


            RuleFor(x => x.EndDate)
            .GreaterThanOrEqualTo(x => x.StartDate)
            .WithMessage("'endDate' cannot be less that 'startDate'");

            RuleFor(x => x)
            .Must(y =>
            {
                var bookingsDates = linqProvider.Query <BookingEntity>()
                                    .Where(x => x.RoomId == y.RoomId)
                                    .Select(x => new { x.StartDate, x.EndDate })
                                    .ToList();

                foreach (var booking in bookingsDates)
                {
                    if (y.StartDate < booking.EndDate.AddDays(1) && y.EndDate > booking.StartDate)
                    {
                        return(false);
                    }
                }

                return(true);
            })
            .WithMessage("There is overlapping with existing bookings, please re-check yours request dates");
        }
Пример #6
0
        private IQueryable <TEntity> PreQuery(ILinqProvider linqProvider, TParam qrit)
        {
            var res = linqProvider.Query <TEntity>()
                      .Apply(Spec, qrit);

            return(res);
        }
Пример #7
0
        public async Task EFQueryAsyncTest()
        {
            int cntBook = 0;

            using (ILinqProvider linq = serviceLocator.GetInstance <ILinqProviderFactory>().Create())
            {
                var books = linq.Query <Book>().ToList();
                Assert.IsNotNull(books);
                cntBook = books.Count();
                Assert.IsTrue(cntBook > 0);
            }

            var allBooks = await handlerLocator
                           .For <IEnumerable <BookDto> >()
                           .AskAsync(new BookOrAuthorQriteria());

            var idQrit = new IdQriteria {
                Id = 2
            };
            var book = await handlerLocator
                       .For <BookDto>()
                       .AskAsync(idQrit);

            Assert.IsNotNull(allBooks);
            Assert.IsInstanceOfType(allBooks, typeof(IEnumerable <BookDto>));
            Assert.IsTrue(allBooks.Count() > 0);
            Assert.IsTrue(allBooks.Count() == cntBook);

            Assert.IsNotNull(book);
            Assert.IsInstanceOfType(book, typeof(BookDto));
            Assert.AreEqual(idQrit.Id, book.Id);
        }
Пример #8
0
 public Task <IQueryable <TResult> > AskAsync(GetCriterion criterion)
 {
     return(Task.FromResult(
                linqProvider.Query <TEntity>()
                .ProjectTo <TResult>(mapper.ConfigurationProvider)
                .DecompileAsync()
                ));
 }
Пример #9
0
        public void InMemoryStoreTest()
        {
            using (var store = new InMemoryStore())
            {
                store.Register <Author>();
                IUnitOfWork uow         = store as IUnitOfWork;
                const int   authorCount = 100;
                Parallel.For(0, authorCount, i =>
                {
                    uow.Add(new Author(i, $"Author {i}"));
                });
                ILinqProvider linq = store as ILinqProvider;

                Assert.AreEqual(authorCount, linq.Query <Author>().Count());
                int id = 3;
                Assert.AreEqual(1, linq.Query <Author>().Where(a => a.Id == id).Count());
                Assert.AreEqual(id, linq.Query <Author>().Where(a => a.Id == id).FirstOrDefault().Id);
                Assert.AreEqual($"Author {id}", linq.Query <Author>().Where(a => a.Id == id).FirstOrDefault().Name);

                var author = new Author(id, $"Author#{id}");
                uow.Update(author);
                uow.Commit();

                Assert.AreEqual(1, linq.Query <Author>().Where(a => a.Id == id).Count());
                Assert.AreEqual(author.Id, linq.Query <Author>().Where(a => a.Id == id).FirstOrDefault().Id);
                Assert.AreEqual(author.Name, linq.Query <Author>().Where(a => a.Id == id).FirstOrDefault().Name);

                Parallel.For(0, 100, i =>
                {
                    var updAuthor = new Author(id, $"Author#{i}");
                    uow.Update(updAuthor);
                });
            }
        }
Пример #10
0
 protected virtual IQueryable <TDest> GetQueryable(TSpecification spec)
 {
     return(LinqProvider
            .Query <TSource>()
            .MaybeWhere(spec)
            .MaybeSort(spec)
            .Project <TSource, TDest>(Projector)
            .MaybeWhere(spec)
            .MaybeSort(spec));
 }
Пример #11
0
        public override Result Request(ILinqProvider linq, CreateBookCmd qrit)
        {
            var query = linq.Query <Book>()
                        .Where(b => b.Name == qrit.Name)
                        .AsNoTracking();

            if (!query.Any())
            {
                return(Result.Ok());
            }

            return(new Failure(Messages.BookNameUnique, query.ToList()));
        }
Пример #12
0
        public IQueryable Query(ILinqProvider linqProvider, IPageQriteria <TParam> qrit)
        {
            var filterExpr = qrit.Subject != null ?
                             ConventionBuilder <TEntity> .FilterExpression(qrit.Subject)
                                : (x) => true;

            var query = linqProvider
                        .Query <TEntity>()
                        .Where(filterExpr)
                        .OrderByConventions(qrit);

            return(query);
        }
Пример #13
0
        private IQueryable <Expert> FetchQuery(ExpertFetch expertFetch)
        {
            var query = _linqProvider.Query <Expert>();

            if ((expertFetch & ExpertFetch.Associations) == ExpertFetch.Associations)
            {
                query.FetchMany(x => x.Associations);
            }
            if ((expertFetch & ExpertFetch.Relations) == ExpertFetch.Relations)
            {
                query.FetchMany(x => x.Relations);
            }

            return(query);
        }
Пример #14
0
        public override IEnumerable <Object> Request(ILinqProvider linqProvider, BookInGenreQrit qrit)
        {
            // некая сложная выборка, для которой недостаточно Expression
            var q1 = from b in linqProvider.Query <Book>()
                     where b.BookGenres.Any(bg => bg.Genre.Name.StartsWith(qrit.Name))
                     select new { b.Id, BookName = b.Name, b.BookGenres };

            var d1 = q1.ToArray();

            var q2 = from b in d1
                     select new
            {
                b.BookName,
                Genre = b.BookGenres.AsQueryable().Aggregate("Genre(s): ", (g, next) => g + ", " + next.Genre.Name)
            };

            return(q2);
        }
Пример #15
0
        public IReadOnlyCollection <NodeCandidate> GetNodeCandidatesBySession(SessionOfExperts session)
        {
            var totalExpectCount = new GetExpertCountQuery(_linqProvider).Execute(
                new GetExpertCountSpecification(session));

            return(_linqProvider.Query <Association>()
                   .Where(x => x.Expert.SessionOfExperts == session)
                   .GroupBy(x => new { x.Notion, TypeName = x.Type.Name, TypeId = x.Type.Id })
                   .Select(
                       gr => new NodeCandidate
            {
                Notion = gr.Key.Notion,
                TypeId = gr.Key.TypeId,
                TypeName = gr.Key.TypeName,
                ExpertCount = gr.Count(),
                TotalExpert = totalExpectCount
            })
                   .ToList());
        }
Пример #16
0
        public IReadOnlyCollection <GroupedRelation> GetGroupedRelations(SessionOfExperts sessionOfExperts)
        {
            var totalExpectCount = new GetExpertCountQuery(_linqProvider).Execute(
                new GetExpertCountSpecification(sessionOfExperts));

            var relations = _linqProvider.Query <Relation>()
                            .SelectMany(x => x.Types, (relation, type) => new { relation.Source, relation.Destination, Type = type })
                            .ToList();

            return(relations
                   .GroupBy(x => new { x.Source, x.Destination, x.Type })
                   .Select(
                       gr => new GroupedRelation
            {
                Source = gr.Key.Source,
                Destination = gr.Key.Destination,
                Type = gr.Key.Type,
                ExpertCount = gr.Count(),
                TotalExpectCount = totalExpectCount
            })
                   .ToList());
        }
Пример #17
0
 public Task <Subscription> AskAsync(SubscriptionWithProductsCriterion criterion)
 {
     return(_linqProvider.Query <Subscription>().Include(x => x.Products).FirstOrDefaultAsync());
 }
Пример #18
0
 public virtual TResult Ask(TKey specification) =>
 Projector.Project <TEntity, TResult>(LinqProvider
                                      .Query <TEntity>()
                                      .Where(x => specification.Equals(x.Id)))
 .SingleOrDefault();
Пример #19
0
 private IQueryable <TEntity> Query(TKey specification) => LinqProvider
 .Query <TEntity>()
 .Where(x => specification.Equals(x.Id));
Пример #20
0
 public Task <DeliveryIntervalTemplate> AskAsync(DeliveryIntervalTemplateByIdCriterion criterion)
 {
     return(_linqProvider.Query <DeliveryIntervalTemplate>()
            .FirstOrDefaultAsync(x => x.Id == criterion.DeliveryIntervalTemplateId));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetAvailableRoomDatesFilterValidator" /> class.
 /// </summary>
 public GetAvailableRoomDatesFilterValidator(ILinqProvider linqProvider)
 {
     RuleFor(x => x.Id)
     .Must(x => linqProvider.Query <RoomEntity>().Any(y => y.Id == x))
     .WithMessage("There is not such room with provided id");
 }
Пример #22
0
 public static TEntity ById <TEntity>(this ILinqProvider linqProvider, int id)
     where TEntity : class, IHasId <int>
 => linqProvider.Query <TEntity>().ById(id);
Пример #23
0
 public virtual IQueryable <TEntity> Query <TEntity>()
     where TEntity : class, IEntity, new()
 {
     return(_linq.Query <TEntity>());
 }
 public Task <List <Product> > AskAsync(AllProductsCriterion criterion)
 {
     return(_linqProvider.Query <Product>()
            .ToListAsync());
 }
Пример #25
0
 protected IQueryable <T> Query <T>()
 {
     return(linqProvider.Query <T>());
 }
Пример #26
0
 public IQueryable Query(ILinqProvider linqProvider, IHasId qrit)
 => linqProvider.Query <TEntity>()
 .Where(ConventionBuilder <TEntity> .IdFilterExpression(qrit));
Пример #27
0
 public Task <long> AskAsync(SubscriptionIdCriterion criterion)
 {
     return(_linqProvider.Query <Subscription>().Select(x => x.Id).FirstOrDefaultAsync());
 }
 public Task <List <DeliveryIntervalTemplate> > AskAsync(AllDeliveryIntervalTemplatesCriterion criterion)
 {
     return(_linqProvider.Query <DeliveryIntervalTemplate>().ToListAsync());
 }
Пример #29
0
 public Node GetByNotionAndType(string notion, NotionType type)
 {
     return(_linqProvider.Query <Node>().SingleOrDefault(x => x.Notion == notion && x.Type == type));
 }
Пример #30
0
 public Verge GetByNodesAndTypes(Node source, Node destination, RelationType type)
 {
     return(_linqProvider.Query <Verge>()
            .SingleOrDefault(x => x.SourceNode == source && x.DestinationNode == destination && x.Type == type));
 }