public async Task <IList <ProductAttributeResult> > SearchAsync(ProductAttributeFilter filter)
        {
            string search = filter.Keyword;

            if (search == null)
            {
                search = string.Empty;
            }

            var inactivedStatus = ProductAttributeStatus.Inactived.GetCode();

            search = search.ToLower();
            var query = _productAttributeRepository.Get(x => filter.CanGetInactived || x.StatusId != inactivedStatus);

            if (!string.IsNullOrEmpty(search))
            {
                query = query.Where(x => x.Name.ToLower().Contains(search) ||
                                    x.Description.ToLower().Contains(search));
            }

            if (filter.ExcludedIds.Any())
            {
                query = query.Where(x => x.Id.NotIn(filter.ExcludedIds));
            }

            if (filter.Id.HasValue)
            {
                query = query.Where(x => x.Id != filter.Id);
            }

            if (filter.PageSize > 0)
            {
                query = query.Skip((filter.Page - 1) * filter.PageSize).Take(filter.PageSize);
            }

            var productAttributes = await query
                                    .Select(x => new ProductAttributeResult()
            {
                Id          = x.Id,
                Name        = x.Name,
                Description = x.Description,
                StatusId    = x.StatusId,
                CreatedById = x.CreatedById,
                UpdatedById = x.UpdatedById,
                CreatedDate = x.CreatedDate,
                UpdatedDate = x.UpdatedDate
            }).ToListAsync();

            return(productAttributes);
        }
        public async Task <BasePageList <ProductAttributeResult> > GetAsync(ProductAttributeFilter filter)
        {
            var inactivedStatus = ProductAttributeStatus.Inactived.GetCode();
            var search          = filter.Keyword != null?filter.Keyword.ToLower() : "";

            var productAttributeQuery = _productAttributeRepository.Get(x => filter.CanGetInactived || x.StatusId != inactivedStatus);

            if (!string.IsNullOrEmpty(search))
            {
                productAttributeQuery = productAttributeQuery.Where(user => user.Name.ToLower().Contains(search) ||
                                                                    user.Description.ToLower().Contains(search));
            }

            var query = productAttributeQuery.Select(x => new ProductAttributeResult
            {
                Description = x.Description,
                Id          = x.Id,
                Name        = x.Name,
                StatusId    = x.StatusId,
                CreatedById = x.CreatedById,
                UpdatedById = x.UpdatedById,
                CreatedDate = x.CreatedDate,
                UpdatedDate = x.UpdatedDate
            });

            if (filter.StatusId.HasValue)
            {
                query = query.Where(x => x.StatusId == filter.StatusId);
            }

            var filteredNumber = query.Select(x => x.Id).Count();

            var productAttributes = await query.Skip(filter.PageSize *(filter.Page - 1))
                                    .Take(filter.PageSize).ToListAsync();

            var result = new BasePageList <ProductAttributeResult>(productAttributes)
            {
                TotalResult = filteredNumber,
                TotalPage   = (int)Math.Ceiling((double)filteredNumber / filter.PageSize)
            };

            return(result);
        }
        public async Task <BasePageList <ProductAttributeResult> > GetAsync(ProductAttributeFilter filter)
        {
            var attributesPageList = await _productAttributeRepository.GetAsync(filter);

            var createdByIds = attributesPageList.Collections.Select(x => x.CreatedById).ToArray();
            var updatedByIds = attributesPageList.Collections.Select(x => x.UpdatedById).ToArray();

            var createdByUsers = await _userRepository.GetNameByIdsAsync(createdByIds);

            var updatedByUsers = await _userRepository.GetNameByIdsAsync(updatedByIds);

            foreach (var category in attributesPageList.Collections)
            {
                var createdBy = createdByUsers.FirstOrDefault(x => x.Id == category.CreatedById);
                category.CreatedBy = createdBy.DisplayName;

                var updatedBy = updatedByUsers.FirstOrDefault(x => x.Id == category.CreatedById);
                category.UpdatedBy = updatedBy.DisplayName;
            }
            return(attributesPageList);
        }
 public async Task <IList <ProductAttributeResult> > SearchAsync(ProductAttributeFilter filter)
 {
     return(await _productAttributeRepository.SearchAsync(filter));
 }