public async Task <IEnumerable <Registration> > GetAllAsync()
    {
        var dbRegistrations = await EntityFrameworkQueryableExtensions
                              .ToListAsync(context.Registrations);

        return(mapper.Map <List <Registration> >(dbRegistrations));
    }
Exemple #2
0
        private async Task <List <TwitterMedia> > GetImagePosts(AppDbContext context, string displayName)
        {
            var mediaQuery = context.TwitterMedia
                             .Where(m => string.Equals(m.Username, displayName, StringComparison.OrdinalIgnoreCase));
            var lastCachedTweet = mediaQuery
                                  .Select(m => m.TweetId)
                                  .DefaultIfEmpty(0UL)
                                  .Max();
            var tweets = await GetTweets(displayName, lastCachedTweet);

            var newMedia = tweets
                           .SelectMany(tweet => tweet.ExtendedEntities.MediaEntities
                                       .Select(entity => new TwitterMedia
            {
                Url = entity.Type == "video"
                            ? entity.VideoInfo.Variants.MaxBy(v => v.BitRate).First().Url
                            : entity.MediaUrl,
                StatusText = tweet.Entities.MediaEntities
                             .Aggregate(tweet.Text, (t, e) => t.Replace(e.Url, string.Empty)),
                TweetId  = tweet.StatusID,
                MediaId  = entity.ID,
                Username = tweet.ScreenName,
            }))
                           .ToList();

            if (newMedia.Any())
            {
                await context.TwitterMedia.AddRangeAsync(newMedia);

                await context.SaveChangesAsync();
            }

            return(await EntityFrameworkQueryableExtensions.ToListAsync(mediaQuery));
        }
Exemple #3
0
        public async Task <Result <List <PanelUserDTO> > > GetAllUserAsync(PanelUserSearchModel searchModel)
        {
            searchModel.FixPageDefinations();
            int?companyId = searchModel.CompanyId;
            IQueryable <PanelUser> source = _unitOfWork.EntityRepository <PanelUser>().GetQueryable((PanelUser w) => w.IsDeleted == false && ((object)companyId == null || (object)(int?)w.CompanyId == (object)companyId), null);

            if (!string.IsNullOrEmpty(searchModel.SearchText))
            {
                source = from w in source
                         where w.Name.Contains(searchModel.SearchText) || w.Email.Contains(searchModel.SearchText)
                         select w;
            }
            return(Result.Data(await EntityFrameworkQueryableExtensions.ToListAsync <PanelUserDTO>(from s in (from o in source
                                                                                                              orderby o.Id
                                                                                                              select o).Skip(searchModel.PageSize * searchModel.PageIndex).Take(searchModel.PageSize)
                                                                                                   select new PanelUserDTO
            {
                Id = s.Id,
                CompanyId = s.CompanyId,
                Role = s.Role,
                Name = s.Name,
                Email = s.Email,
                PlaceName = (s.PlaceId.HasValue ? s.Place.Name : null),
                Company = new CompanyInfoDTO
                {
                    Name = s.Company.Name
                },
                CreatedDate = s.CreatedDate
            }, default(CancellationToken))));
        }
 public static Task <List <TSource> > ToListEFCoreAsync <TSource>(
     this IQueryable <TSource> source,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(EntityFrameworkQueryableExtensions.ToListAsync(
                source, cancellationToken));
 }
        public async Task CoinReset()
        {
            //Check if event happened today
            var didHappen = await EntityFrameworkQueryableExtensions.AnyAsync(_db.Events, ev => ev.Date.Day == DateTime.Today.Day &&
                                                                              ev.Date.Month == DateTime.Today.Month &&
                                                                              ev.Date.Year == DateTime.Today.Year &&
                                                                              ev.Type == EventType.Coins);

            if (didHappen)
            {
                return;
            }

            //get users
            var users = await EntityFrameworkQueryableExtensions.ToListAsync(_db.UserData);

            var newUsers = users.Select(c => { c.UserDaily = false; return(c); }).ToList();

            _db.UserData.UpdateRange(newUsers);
            await _db.SaveChangesAsync();

            //Add event
            await AddEvent(EventType.Coins);

            _logger.LogInformation("Coin reset");
        }
Exemple #6
0
        /// <summary>
        /// 获取分页信息,不使用Mapper
        /// </summary>
        /// <typeparam name="TEntityOrView"></typeparam>
        /// <param name="query"></param>
        /// <param name="pagedInputDto"></param>
        /// <returns></returns>
        public static async Task <MyPagedResult <TEntityOrView> > GetPageEntityOrViewAsync <TEntityOrView>(this IQueryable <TEntityOrView> query, PagedInputDto pagedInputDto) where TEntityOrView : class
        {
            query = EntityFrameworkQueryableExtensions.AsNoTracking <TEntityOrView>(query);
            //排序
            if (!string.IsNullOrEmpty(pagedInputDto.Order))
            {
                List <string> strList = pagedInputDto.Order.Split(new char[1]
                {
                    ','
                }).ToList();
                for (int i = 0; i < strList.Count; i++)
                {
                    query = ((i != 0) ? ((!strList[i].ToLower().Contains("desc")) ? DynamicQueryable.OrderBy <TEntityOrView>(query, pagedInputDto.Order, Array.Empty <object>()) : DynamicQueryable.ThenByDescending <TEntityOrView>(query, pagedInputDto.Order, Array.Empty <object>())) : ((!strList[i].ToLower().Contains("desc")) ? DynamicQueryable.OrderBy <TEntityOrView>(query, pagedInputDto.Order, Array.Empty <object>()) : DynamicQueryable.OrderByDescending <TEntityOrView>(query, pagedInputDto.Order, Array.Empty <object>())));
                }
            }
            if (pagedInputDto.Filter != null)
            {
                string   text  = pagedInputDto.Filter.ToWhere();
                object[] array = pagedInputDto.Filter.paramValues.ToArray();
                query = DynamicQueryable.Where <TEntityOrView>(query, text, array);
            }
            IQueryable <TEntityOrView> queryable = query.Skip(pagedInputDto.SkipCount).Take(pagedInputDto.PageSize);

            List <TEntityOrView> dataList = await EntityFrameworkQueryableExtensions.ToListAsync <TEntityOrView>(queryable, default(CancellationToken));

            MyPagedResult <TEntityOrView> obj = new MyPagedResult <TEntityOrView>();

            obj.PageSize  = pagedInputDto.PageSize;
            obj.PageIndex = pagedInputDto.PageIndex;
            obj.DataList  = dataList;
            obj.RowCount  = query.Count();
            return(obj);
        }
Exemple #7
0
 private static async Task GetAllWithContextInclude()
 {
     using (var context = _factory.CreateDbContext())
     {
         context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
         var orders = await EntityFrameworkQueryableExtensions.ToListAsync(context.Set <Order>().Include(o => o.Details));
     }
 }
Exemple #8
0
        public static async Task <IList <T> > ToListAsync <T>(this IEnumerable <T> list)
        {
            if (list is IQueryable <T> query)
            {
                return(await EntityFrameworkQueryableExtensions.ToListAsync(query));
            }

            return(list.ToList());
        }
Exemple #9
0
        public async Task <IActionResult> SearchLastName(string q)
        {
            var search = await EntityFrameworkQueryableExtensions.ToListAsync(_context.Contacts
                                                                              // .Include("Addresses")
                                                                              .Where(a => a.FirstName.Contains(q)));

            ;
            return(View(search));
        }
        public static Task <List <T> > ToListAsync <T>(this IQueryable <T> source)
            where T : class
        {
            if (source is EntitySet <T> )
            {
                source = (source as EntitySet <T>).DbSet;
            }

            return(EntityFrameworkQueryableExtensions.ToListAsync(source));
        }
Exemple #11
0
        public async Task <IActionResult> ShowAllAddresses(int id)
        {
            var query = await EntityFrameworkQueryableExtensions.ToListAsync((from ct in _context.Contacts
                                                                              //join ca in _context.ContactToAddress on ct.ID equals ca.ContactId
                                                                              join a in _context.Addresses on ct.ID equals a.ContactID
                                                                              where ct.ID == id
                                                                              select a));

            return(View("~/Views/Addresses/Index.cshtml", query));
        }
Exemple #12
0
        public async Task <IActionResult> ShowAllPart(int id)
        {
            var query = await EntityFrameworkQueryableExtensions.ToListAsync((from ct in _context.Contacts
                                                                              //join ca in _context.ContactToAddress on ct.ID equals ca.ContactId
                                                                              join a in _context.Addresses on ct.ID equals a.ContactID
                                                                              where ct.ID == id &&
                                                                              a.Name.Contains("work")
                                                                              select a));

            return(PartialView("ViewAllP", query));
        }
Exemple #13
0
 public async Task <IEnumerable <CountsProduct> > GetCountsProduct(long itemId, CancellationToken cts = new CancellationToken())
 {
     return(await Task.Run(() =>
     {
         cts.ThrowIfCancellationRequested();
         return EntityFrameworkQueryableExtensions.ToListAsync(Db.CountsProducts
                                                               .FromSql("select * from dbo.getCountProduct ({0})", itemId).Include(c => c.Store)
                                                               .AsNoTracking(),
                                                               cts);
     }, cts));
 }
Exemple #14
0
 public async Task <IEnumerable <EquivalentCostForExistingProduct> > GetEquivalentCostsForЕxistingProduct(long itemId, CancellationToken cts = new CancellationToken())
 {
     return(await Task.Run(() =>
     {
         cts.ThrowIfCancellationRequested();
         return EntityFrameworkQueryableExtensions.ToListAsync(
             Db.EquivalentCostForЕxistingProducts
             .FromSql("select * from dbo.getEquivalentCostForЕxistingProduct ({0})", itemId).AsNoTracking(),
             cts);
     }, cts));
 }
        public async Task <List <TResult> > DistinctAsync <TResult>(Expression <Func <T, TResult> > selector)
        {
            var newSource = _source.Select(selector);

            var results = await GetStatisDataAsync <List <TResult> >(x =>
            {
                var q = Queryable.Distinct((dynamic)x);
                return(EntityFrameworkQueryableExtensions.ToListAsync(q));
            }, newSource);

            return(results.SelectMany(x => x).Distinct().ToList());
        }
Exemple #16
0
        public async Task <IEnumerable <Product> > GetProductsWithCountAndPrice(CancellationToken cts = new CancellationToken(), ISpecification <Product> where = null, Dictionary <string, SortingTypes> order = null, int skip = 0, int take = -1)
        {
            return(await Task.Run(() =>
            {
                var query = from p in Db.Products
                            select p;

                cts.ThrowIfCancellationRequested();

                if (where != null)
                {
                    query = query.Where(where.IsSatisfiedBy()).AsQueryable();
                }
                if (order != null)
                {
                    query = query.OrderUsingSortExpression(order).AsQueryable();
                }
                if (skip != 0)
                {
                    query = query.Skip(skip).AsQueryable();
                }
                if (take != -1)
                {
                    query = query.Take(take).AsQueryable();
                }

                cts.ThrowIfCancellationRequested();

                query = from q in query
                        join pwcap in Db.ProductWithCountAndPrice on q.Id equals pwcap.Id
                        select new Product
                {
                    Title = q.Title,
                    Barcode = q.Barcode,
                    Id = q.Id,
                    Description = q.Description,
                    IdCategory = q.IdCategory,
                    IdPriceGroup = q.IdPriceGroup,
                    IdUnitStorage = q.IdUnitStorage,
                    IdWarrantyPeriod = q.IdWarrantyPeriod,
                    KeepTrackSerialNumbers = q.KeepTrackSerialNumbers,
                    Price = pwcap.Price,
                    Count = pwcap.Count,
                    Category = q.Category,
                    UnitStorage = q.UnitStorage,
                    VendorCode = q.VendorCode,
                    PriceGroup = q.PriceGroup
                };

                cts.ThrowIfCancellationRequested();
                return EntityFrameworkQueryableExtensions.ToListAsync(query, cts);
            }, cts));
        }
        public async Task <Result <List <FeedbackDetailDTO> > > GetAllFeedbackDetailAsync(CompanyUserSearchModel searchModel)
        {
            searchModel.FixPageDefinations();
            int?companyId = searchModel.CompanyId;
            int?placeId   = searchModel.PlaceId;
            int?userId    = searchModel.UserId;
            IQueryable <Feedback> source = _unitOfWork.EntityRepository <Feedback>()
                                           .GetQueryable((Feedback w) =>
                                                         w.IsDeleted == false &&
                                                         ((object)placeId == null || (object)(int?)w.PlaceId == (object)placeId) &&
                                                         ((object)userId == null || (object)w.UserId == (object)userId) &&
                                                         ((object)companyId == null || (object)(int?)w.Place.CompanyId == (object)companyId)
                                                         , null);

            //IQueryable<Feedback> source = _unitOfWork.EntityRepository<Feedback>().GetQueryable((Feedback w) => w.IsDeleted == false, null);
            if (!string.IsNullOrEmpty(searchModel.SearchText))
            {
                source = from w in source
                         where w.Description.Contains(searchModel.SearchText)
                         select w;
            }
            return(Result.Data(await EntityFrameworkQueryableExtensions.ToListAsync <FeedbackDetailDTO>(from s in (from o in source
                                                                                                                   orderby o.Id
                                                                                                                   select o).Skip(searchModel.PageSize * searchModel.PageIndex).Take(searchModel.PageSize)
                                                                                                        select new FeedbackDetailDTO
            {
                Id = s.Id,
                DeskCode = s.DeskCode,
                Description = s.Description,
                CreatedDate = s.CreatedDate,
                PlcId = s.PlaceId,
                Place = s.Place.Name,
                Info = (s.DetailId.HasValue ? new FeedbackDetailInfoDTO
                {
                    EmployeeRate = s.Detail.EmployeeRate,
                    FlavorRate = s.Detail.FlavorRate,
                    PriceRate = s.Detail.PriceRate,
                    CleaningRate = s.Detail.CleaningRate,
                    AdviseRate = s.Detail.AdviseRate
                } : null),
                User = (s.UserId.HasValue ? new UserDTO
                {
                    Id = s.User.Id,
                    Name = s.User.Name,
                    Email = s.User.Email,
                    Phone = s.User.Phone
                } : null),
                IsUserShare = s.IsUserShare,
                IsAnon = (s.UserId.HasValue == false)
            }, default(CancellationToken))));
        }
Exemple #18
0
        /// <summary>
        ///     ToListAsync
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="queryable"></param>
        /// <returns></returns>
        public static async Task <List <TEntity> > ToListAsync <TEntity>(this IQueryable <TEntity> queryable)
            where TEntity : class
        {
            if (queryable is IMongoQueryable <TEntity> mongoQueryable)
            {
                var cursor = await mongoQueryable.ToCursorAsync()
                             .ConfigureAwait(false);

                return(await cursor.ToListAsync()
                       .ConfigureAwait(false));
            }

            return(await EntityFrameworkQueryableExtensions.ToListAsync(queryable)
                   .ConfigureAwait(false));
        }
Exemple #19
0
        private static async Task GetAllWithContextParallel()
        {
            using (var context1 = _factory.CreateDbContext())
                using (var context2 = _factory.CreateDbContext())
                {
                    context1.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
                    context2.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
                    var ordersTask  = EntityFrameworkQueryableExtensions.ToListAsync(context1.Set <Order>());
                    var detailsTask = EntityFrameworkQueryableExtensions.ToListAsync(context2.Set <Detail>());

                    await Task.WhenAll(ordersTask, detailsTask);

                    var orders  = ordersTask.Result;
                    var details = detailsTask.Result;
                }
        }
Exemple #20
0
        /// <summary>
        /// 带mapper
        /// </summary>
        /// <typeparam name="TEntityOrView"></typeparam>
        /// <typeparam name="TDto"></typeparam>
        /// <param name="query"></param>
        /// <param name="pagedInputDto"></param>
        /// <param name="configurationProvider"></param>
        /// <returns></returns>
        public static async Task <MyPagedResult <TDto> > GetPageAsync <TEntityOrView, TDto>(this IQueryable <TEntityOrView> query, PagedInputDto pagedInputDto) where TEntityOrView : class where TDto : class
        {
            query = EntityFrameworkQueryableExtensions.AsNoTracking <TEntityOrView>(query);
            //排序
            if (!string.IsNullOrEmpty(pagedInputDto.Order))
            {
                List <string> strList = pagedInputDto.Order.Split(new char[1]
                {
                    ','
                }).ToList();
                for (int i = 0; i < strList.Count; i++)
                {
                    query = ((i != 0) ? ((!strList[i].ToLower().Contains("desc")) ? DynamicQueryable.OrderBy <TEntityOrView>(query, pagedInputDto.Order, Array.Empty <object>()) : DynamicQueryable.ThenByDescending <TEntityOrView>(query, pagedInputDto.Order, Array.Empty <object>())) : ((!strList[i].ToLower().Contains("desc")) ? DynamicQueryable.OrderBy <TEntityOrView>(query, pagedInputDto.Order, Array.Empty <object>()) : DynamicQueryable.OrderByDescending <TEntityOrView>(query, pagedInputDto.Order, Array.Empty <object>())));
                }
            }
            //if (!string.IsNullOrEmpty(pagedInputDto.Order))
            //{
            //    query = DynamicQueryable.OrderBy<TEntityOrView>(query, pagedInputDto.Order, Array.Empty<object>());
            //}
            if (pagedInputDto.Filter != null)
            {
                string   text  = pagedInputDto.Filter.ToWhere();
                object[] array = pagedInputDto.Filter.paramValues.ToArray();
                query = DynamicQueryable.Where <TEntityOrView>(query, text, array);
            }
            IQueryable <TEntityOrView> queryable = query.Skip(pagedInputDto.SkipCount).Take(pagedInputDto.PageSize);

            IQueryable <TDto> queryable2;

            if (!string.IsNullOrEmpty(pagedInputDto.Select))
            {
                queryable2 = DynamicQueryable.Select(queryable, pagedInputDto.Select, Array.Empty <object>()).Cast <TDto>();
            }
            else
            {
                queryable2 = Extensions.ProjectTo <TDto>(queryable, (AutoMapper.IConfigurationProvider)pagedInputDto.configurationProvider, Array.Empty <Expression <Func <TDto, object> > >());
            }
            List <TDto> dataList = await EntityFrameworkQueryableExtensions.ToListAsync <TDto>(queryable2, default(CancellationToken));

            MyPagedResult <TDto> obj = new MyPagedResult <TDto>();

            obj.PageSize  = pagedInputDto.PageSize;
            obj.PageIndex = pagedInputDto.PageIndex;
            obj.DataList  = dataList;
            obj.RowCount  = query.Count();
            return(obj);
        }
Exemple #21
0
        private async Task <Option <List <Beverage>, Error> > GetBeveragesIfInStock(IEnumerable <int> menuNumbers)
        {
            var allBeveragesInStock = (await EntityFrameworkQueryableExtensions.ToListAsync(_dbContext.Beverages))
                                      .ToDictionary(x => x.MenuNumber);

            var beveragesToServeResult = menuNumbers
                                         .Select(menuNumber => allBeveragesInStock
                                                 .GetValueOrNone(menuNumber)
                                                 .WithException <Error>(Errors.Beverage.NotFound(menuNumber)))
                                         .ToList();

            var errors = beveragesToServeResult.Exceptions().ToArray();

            return(errors.Length > 0 ?
                   Option.None <List <Beverage>, Error>(errors) :
                   beveragesToServeResult.Values().ToList().Some <List <Beverage>, Error>());
        }
Exemple #22
0
        public Task <List <Spawnpoints> > GetNearestSpawnpointsAsync(double latitude, double longitude)
        {
            return(EntityFrameworkQueryableExtensions.ToListAsync <Spawnpoints>(Spawnpoints.FromSql($@"
SELECT s.* FROM spawnpoints AS s INNER JOIN (
SELECT id, (
	6371 * 1000 * 
	acos(cos(radians({latitude})) *
	cos(radians(lat)) *
	cos(radians(lon) - radians({longitude})) +
	sin(radians({latitude})) *
	sin(radians(lat))) 
) AS distance_in_m
FROM spawnpoints
HAVING distance_in_m < 100
ORDER BY distance_in_m  ASC
) AS f on s.id = f.id
")));
        }
Exemple #23
0
    public async Task <Result <List <PromotionDTO> > > GetAllPromotionAsync(CompanyUserSearchModel searchModel)
    {
        searchModel.FixPageDefinations();
        int?companyId = searchModel.CompanyId;
        int?placeId   = searchModel.PlaceId;
        int?userId    = searchModel.UserId;
        IQueryable <Promotion> source = _unitOfWork.EntityRepository <Promotion>().GetQueryable((Expression <Func <Promotion, bool> >)((Promotion w) => ((object)placeId == null || (object)(int?)w.PlaceId == (object)placeId) && ((object)userId == null || (object)(int?)w.UserId == (object)userId) && ((object)companyId == null || (object)(int?)w.Place.CompanyId == (object)companyId)), (Func <IQueryable <Promotion>, IOrderedQueryable <Promotion> >)null, Array.Empty <Expression <Func <Promotion, object> > >());

        if (!string.IsNullOrEmpty(searchModel.SearchText))
        {
            source = from w in source
                     where w.Message.Contains(searchModel.SearchText)
                     select w;
        }
        DateTime today = DateTime.Today;

        return(Result.Data <List <PromotionDTO> >(await EntityFrameworkQueryableExtensions.ToListAsync <PromotionDTO>(from s in (from o in source
                                                                                                                                 orderby o.Id
                                                                                                                                 select o).Skip(searchModel.PageSize * searchModel.PageIndex).Take(searchModel.PageSize)
                                                                                                                      select new PromotionDTO
        {
            Id = s.Id,
            Title = s.Title,
            Message = s.Message,
            DueDate = s.DueDate,
            IsActive = s.IsActive,
            CreatedDate = s.CreatedDate,
            CreatedBy = s.CreatedBy,
            UsageCode = s.UsageCode,
            UserId = s.UserId,
            Status = ((s.DueDate < today) ? "Süresi Bitti" : (s.IsActive ? "Aktif" : "Kullanıldı")),
            User = new UserInfoDTO
            {
                Id = s.User.Id,
                Name = s.User.Name,
                Email = s.User.Email
            },
            Place = new PlaceInfoDTO
            {
                Id = s.Place.Id,
                Name = s.Place.Name
            }
        }, default(CancellationToken))));
    }
Exemple #24
0
        public async Task TestAsyncMethods()
        {
            using (var ctx = CreateAdventureWorksContext())
            {
                var query = ctx.Products.AsQueryable().Where(p => p.Name.Contains("a"));

                var expected = await query.ToArrayAsync();

                var expectedDictionary = await query.ToDictionaryAsync(p => p.ProductID);

                var expectedAny = await query.AnyAsync();

                var byList = await EntityFrameworkQueryableExtensions.ToListAsync(query.ToLinqToDB());

                var byArray = await EntityFrameworkQueryableExtensions.ToArrayAsync(query.ToLinqToDB());

                var byDictionary = await EntityFrameworkQueryableExtensions.ToDictionaryAsync(query.ToLinqToDB(), p => p.ProductID);

                var any = await EntityFrameworkQueryableExtensions.AnyAsync(query.ToLinqToDB());
            }
        }
        public async Task TestAsyncMethods([Values(true, false)] bool enableFilter)
        {
            using (var ctx = CreateContext(enableFilter))
            {
                var query = ctx.Products.AsQueryable().Where(p => p.ProductName.Contains("a"));

                var expectedArray = await query.ToArrayAsync();

                var expectedDictionary = await query.ToDictionaryAsync(p => p.ProductId);

                var expectedAny = await query.AnyAsync();

                var byList = await EntityFrameworkQueryableExtensions.ToListAsync(query.ToLinqToDB());

                var byArray = await EntityFrameworkQueryableExtensions.ToArrayAsync(query.ToLinqToDB());

                var byDictionary = await EntityFrameworkQueryableExtensions.ToDictionaryAsync(query.ToLinqToDB(), p => p.ProductId);

                var any = await EntityFrameworkQueryableExtensions.AnyAsync(query.ToLinqToDB());
            }
        }
Exemple #26
0
        public async Task <Result <List <CompanyInfoDTO> > > GetAllCompanyAsync(SearchModel searchModel)
        {
            searchModel.FixPageDefinations();
            IQueryable <Company> source = _unitOfWork.EntityRepository <Company>().GetQueryable((Company w) => w.IsDeleted == false, null);

            if (!string.IsNullOrEmpty(searchModel.SearchText))
            {
                source = from w in source
                         where w.Name.Contains(searchModel.SearchText)
                         select w;
            }
            return(Result.Data(await EntityFrameworkQueryableExtensions.ToListAsync <CompanyInfoDTO>(from s in (from o in source
                                                                                                                orderby o.Name
                                                                                                                select o).Skip(searchModel.PageSize * searchModel.PageIndex).Take(searchModel.PageSize)
                                                                                                     select new CompanyInfoDTO
            {
                Id = s.Id,
                Name = s.Name,
                Image = s.Image
            }, default(CancellationToken))));
        }
        public async Task <Result <List <FeedbackDTO> > > GetAllFeedbackAsync(CompanyUserSearchModel searchModel)
        {
            searchModel.FixPageDefinations();
            int?companyId = searchModel.CompanyId;
            int?placeId   = searchModel.PlaceId;
            int?userId    = searchModel.UserId;
            IQueryable <Feedback> source = _unitOfWork.EntityRepository <Feedback>().GetQueryable((Feedback w) => w.IsDeleted == false && ((object)placeId == null || (object)(int?)w.PlaceId == (object)placeId) && ((object)userId == null || (object)w.UserId == (object)userId) && ((object)companyId == null || (object)(int?)w.Place.CompanyId == (object)companyId), null);

            if (!string.IsNullOrEmpty(searchModel.SearchText))
            {
                source = from w in source
                         where w.Description.Contains(searchModel.SearchText)
                         select w;
            }
            return(Result.Data(await EntityFrameworkQueryableExtensions.ToListAsync <FeedbackDTO>(from s in (from o in source
                                                                                                             orderby o.Id descending
                                                                                                             select o).Skip(searchModel.PageSize * searchModel.PageIndex).Take(searchModel.PageSize)
                                                                                                  select new FeedbackDTO
            {
                Id = s.Id,
                DeskCode = s.DeskCode,
                Description = s.Description,
                CreatedDate = s.CreatedDate,
                CreatedBy = s.CreatedBy,
                UserId = s.UserId,
                User = (s.UserId.HasValue ? new UserInfoDTO
                {
                    Id = s.User.Id,
                    Name = s.User.Name
                } : null),
                PlaceId = s.PlaceId,
                Place = new PlaceInfoDTO
                {
                    Id = s.Place.Id,
                    Name = s.Place.Name
                }
            }, default(CancellationToken))));
        }
        public async Task EggplantReset()
        {
            var didHappen = await EntityFrameworkQueryableExtensions.AnyAsync(_db.Events, ev => ev.Date.Day == DateTime.Today.Day &&
                                                                              ev.Date.Month == DateTime.Today.Month &&
                                                                              ev.Date.Year == DateTime.Today.Year &&
                                                                              ev.Type == EventType.EggplantReset);

            if (didHappen)
            {
                return;
            }

            var users = await EntityFrameworkQueryableExtensions.ToListAsync(_db.UserData);

            var newUsers = users.Select(c => { c.EggplantDaily = false; return(c); }).ToList();

            _db.UserData.UpdateRange(newUsers);
            await _db.SaveChangesAsync();

            await AddEvent(EventType.EggplantReset);

            _logger.LogInformation("Eggplant reset");
        }
 public virtual async Task <IReadOnlyList <T> > GetAllAsync()
 {
     return(await EntityFrameworkQueryableExtensions.ToListAsync(_dbContext
                                                                 .Set <T>()));
 }
Exemple #30
0
 public override async Task <List <TEntity> > GetAllListAsync(Expression <Func <TEntity, bool> > predicate)
 {
     return(await EntityFrameworkQueryableExtensions.ToListAsync <TEntity>(this.GetAll().Where(predicate), default(CancellationToken)));
 }