public async Task <ServiceResponseWithPagination <List <ProductGroupDTO_ToReturn> > > GetProductGroupFilter(ProductGroupDTO_Filter input)
        {
            var queryable = _context.ProductGroups.AsQueryable();

            //Filter
            if (!string.IsNullOrWhiteSpace(input.Name))
            {
                queryable = queryable.Where(x => x.Name.Contains(input.Name));
            }

            //Ordering
            if (!string.IsNullOrWhiteSpace(input.OrderingField))
            {
                try
                {
                    queryable = queryable.OrderBy($"{input.OrderingField} {(input.AscendingOrder ? "asc" : "desc")}");
                }
                catch (System.Exception ex)
                {
                    _logger.LogError(ex.Message);
                    return(ResponseResultWithPagination.Failure <List <ProductGroupDTO_ToReturn> >(ex.Message));
                }
            }

            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(queryable, input.RecordsPerPage, input.Page);

            var data = await queryable.Paginate(input).ToListAsync();

            var dto = _mapper.Map <List <ProductGroupDTO_ToReturn> >(data);

            return(ResponseResultWithPagination.Success(dto, paginationResult));
        }
예제 #2
0
        public async Task <ServiceResponseWithPagination <List <BookDTO_ToReturn> > > SearchPagination(BookDTO_Filter filter)
        {
            var book = _dbContext.Books.Include(x => x.CategoryBooks).AsQueryable();

            if (!string.IsNullOrWhiteSpace(filter.Name))
            {
                book = book.Where(x => x.Name.Contains(filter.Name));
            }
            book = book.Where(x => x.CategoryBooks.CodeType == filter.CategoryCode);

            book = book.Where(x => x.BorrowPrice >= filter.MinPrice);



            // 2. Order => Order by
            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    book = book.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <BookDTO_ToReturn> >($"Could not order by field: {filter.OrderingField}"));
                }
            }

            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(book, filter.RecordsPerPage, filter.Page);

            // var custom = await cus.Paginate(filter).ToListAsync();
            var result = _mapper.Map <List <BookDTO_ToReturn> >(await book.Paginate(filter).ToListAsync());

            return(ResponseResultWithPagination.Success(result, paginationResult));
        }
예제 #3
0
        public async Task <ServiceResponseWithPagination <List <CustomerDTO_ToRetun> > > SearchPagination(CustomerDTO_Filter filter)
        {
            var cus = _dbContext.Customers.AsQueryable();

            if (!string.IsNullOrWhiteSpace(filter.Name))
            {
                cus = cus.Where(x => x.Name.Contains(filter.Name));
            }
            cus = cus.Where(x => x.Email.Contains(filter.Email));

            // 2. Order => Order by
            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    cus = cus.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <CustomerDTO_ToRetun> >($"Could not order by field: {filter.OrderingField}"));
                }
            }

            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(cus, filter.RecordsPerPage, filter.Page);

            // var custom = await cus.Paginate(filter).ToListAsync();
            var result = _mapper.Map <List <CustomerDTO_ToRetun> >(await cus.Paginate(filter).ToListAsync());

            return(ResponseResultWithPagination.Success(result, paginationResult));
        }
예제 #4
0
        public async Task <ServiceResponseWithPagination <List <CategoryBookDTO_ToReturn> > > SearchPaginate(CategoryBookDTO_Filter filter)
        {
            //สามารถคิวรี่ได้ ปั้นตัวคิวรี่โดยยังไม่แตะดาต้าเบส excute 2 รอบ
            var categoryBook = _dbContext.CategoryBooks.AsQueryable();

            if (!string.IsNullOrWhiteSpace(filter.Name))
            {
                categoryBook = categoryBook.Where(x => (x.CodeType).Contains(filter.Name));
            }

            // 2. Order => Order by
            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    categoryBook = categoryBook.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <CategoryBookDTO_ToReturn> >($"Could not order by field: {filter.OrderingField}"));
                }
            }

            // 3. Add Paginate => Page,total,Perpage
            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(categoryBook, filter.RecordsPerPage, filter.Page);

            // 4. Execute Query
            var category = await categoryBook.Paginate(filter).ToListAsync();

            // 5. Return result
            var result = _mapper.Map <List <CategoryBookDTO_ToReturn> >(category);

            return(ResponseResultWithPagination.Success(result, paginationResult));
        }
        public async Task <ServiceResponseWithPagination <List <OrderDto_ToReturn> > > SearchPagination(OrderDto_Filter filter)
        {
            var order = _dbContext.Orders.Include(x => x.OrderItems).ThenInclude(x => x.Products).AsQueryable();

            order = order.Where(x => x.IsActive == filter.IsActive);

            // 2. Order => Order by
            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    order = order.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <OrderDto_ToReturn> >($"Could not order by field: {filter.OrderingField}"));
                }
            }

            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(order, filter.RecordsPerPage, filter.Page);

            // var custom = await cus.Paginate(filter).ToListAsync();
            var result = _mapper.Map <List <OrderDto_ToReturn> >(await order.Paginate(filter).ToListAsync());

            return(ResponseResultWithPagination.Success(result, paginationResult));
        }
예제 #6
0
        public async Task <ServiceResponseWithPagination <List <ProductGroupDto_ToReturn> > > SearchPagination(ProductGroupDto_Filter filter)
        {
            var productGroup = _dbContext.ProductGroups.AsQueryable();

            if (!string.IsNullOrWhiteSpace(filter.Name))
            {
                productGroup = productGroup.Where(x => x.Name.ToLower().Contains(filter.Name.ToLower()));
            }
            productGroup = productGroup.Where(x => x.IsActive == filter.IsActive);


            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    productGroup = productGroup.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <ProductGroupDto_ToReturn> >($"Could not order by field: {filter.OrderingField}"));
                }
            }

            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(productGroup, filter.RecordsPerPage, filter.Page);



            var result = _mapper.Map <List <ProductGroupDto_ToReturn> >(await productGroup.Paginate(filter).ToListAsync());

            return(ResponseResultWithPagination.Success(result, paginationResult));
        }
예제 #7
0
        public async Task <ServiceResponseWithPagination <List <mOrder> > > GetOrderWithFilterByDate(GetOrderDateFilterDTO orderFilter)
        {
            var Queryable = _dbContext.Orders.AsQueryable();

            if (orderFilter.DateFrom != null && orderFilter.DateTo != null)
            {
                //Queryable = Queryable.Where(x => x.DateOrder >= orderFilter.DateFrom.Value && x.DateOrder <= orderFilter.DateTo.Value.AddDays(1));
                Queryable = Queryable.Where(x => x.DateOrder >= orderFilter.DateFrom.Value.Date && x.DateOrder <= orderFilter.DateTo.Value.AddDays(1).Date);
            }

            if (!string.IsNullOrWhiteSpace(orderFilter.OrderingField))
            {
                try
                {
                    Queryable = Queryable.OrderBy($"{orderFilter.OrderingField} {(orderFilter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <Models.Order.Order> >($"Could not order by field: {orderFilter.OrderingField}"));
                }

                ;
            }

            var paginationResult = await _httpcontext.HttpContext.InsertPaginationParametersInResponse(Queryable, orderFilter.RecordsPerPage, orderFilter.Page);

            var dto = await Queryable.Paginate(orderFilter).ToListAsync();

            return(ResponseResultWithPagination.Success(dto, paginationResult));
        }
        public async Task <ServiceResponseWithPagination <List <GetProductDto> > > GetProductFilter(ProductFilterDto filter)
        {
            var queryable = _dBContext.Products.Include(x => x.ProductGroup).AsNoTracking().AsQueryable();

            //Filter
            if (!string.IsNullOrWhiteSpace(filter.Name))
            {
                queryable = queryable.Where(x => x.Name.Contains(filter.Name.Trim()));
            }

            //Ordering
            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    queryable = queryable.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <GetProductDto> >($"Could not order by field: {filter.OrderingField}"));
                }
            }

            var paginationResult = await _httpContext.HttpContext
                                   .InsertPaginationParametersInResponse(queryable, filter.RecordsPerPage, filter.Page);

            var dto = await queryable.Paginate(filter).AsNoTracking().ToListAsync();

            var prodDto = _mapper.Map <List <GetProductDto> >(dto);

            return(ResponseResultWithPagination.Success(prodDto, paginationResult));
        }
예제 #9
0
        public async Task <ServiceResponseWithPagination <List <Bulk> > > GetBulkFilter(BulkFilterDto filter)
        {
            var queryable = _dBContext.Bulk.AsQueryable();

            //Filter
            if (!string.IsNullOrWhiteSpace(filter.BulkName))
            {
                queryable = queryable.Where(x => x.BulkName.Contains(filter.BulkName));
            }

            if (!string.IsNullOrWhiteSpace(filter.BulkCode))
            {
                queryable = queryable.Where(x => x.BulkCode.Contains(filter.BulkCode));
            }

            //Ordering
            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    queryable = queryable.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "asc" : "desc")}");
                }
                catch (System.Exception)
                {
                    return(ResponseResultWithPagination.Failure <List <Bulk> >(string.Format("Could not order by field : {0}", filter.OrderingField)));
                }
            }

            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(queryable, filter.RecordsPerPage, filter.Page);

            var dto = await queryable.Paginate(filter).ToListAsync();

            return(ResponseResultWithPagination.Success(dto, paginationResult));
        }
예제 #10
0
        public async Task <ServiceResponseWithPagination <List <StockCardDto> > > StockCardFilter(StockCardFilterDto filter)
        {
            var queryable = _dbContext.StockCards.Include(x => x.User).Include(x => x.Product).ThenInclude(x => x.ProductGroup).AsQueryable();

            //var queryable = _dbContext.StockCards.AsQueryable();
            //Filter
            if (!string.IsNullOrWhiteSpace(filter.Name) && filter.Name != "")
            {
                queryable = queryable.Where(x => x.Product.Name.Contains(filter.Name));
            }
            if (filter.IsActive != null)
            {
                queryable = queryable.Where(x => x.IsActive.Equals(filter.IsActive));
            }
            //Ordering
            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    queryable = queryable.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <StockCardDto> >($"Could not order by field: {filter.OrderingField}"));
                }
            }
            var paginationResult = await _httpContext.HttpContext
                                   .InsertPaginationParametersInResponse(queryable, filter.RecordsPerPage, filter.Page);

            var StockCard = await queryable.Paginate(filter).ToListAsync();

            var dto = _mapper.Map <List <StockCardDto> >(StockCard);

            return(ResponseResultWithPagination.Success(dto, paginationResult));
        }
예제 #11
0
        public async Task <ServiceResponseWithPagination <List <ProductGroupDTO> > > GetAll(PaginationDto pagination = null, string productGroupfilter = null, DataOrderDTO ordering = null)
        {
            // Quering data
            var query = _dbContext.ProductGroup.AsQueryable();

            // Filtering data
            if (!(String.IsNullOrEmpty(productGroupfilter)))
            {
                query = query.Where(x => x.Name.Contains(productGroupfilter));
            }

            // Ordering
            if (!(ordering is null))
            {
                var columns = new List <string> {
                    "Id", "Name", "CreatedBy", "CreatedDate", "Status"
                };

                if (columns.Exists(x => x == ordering.OrderBy))
                {
                    if (ordering.OrderBy == "CreatedBy")
                    {
                        ordering.OrderBy = "CreatedByUser.Username";
                    }

                    var property = $"{ordering.OrderBy}";

                    if (!String.IsNullOrEmpty(ordering.Sort) && ordering.Sort.ToLower() == "desc")
                    {
                        query = ApplyOrder(query, property, "OrderByDescending");
                    }
                    else
                    {
                        query = ApplyOrder(query, property, "OrderBy");
                    }
                }
            }

            // Pagination
            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(query, pagination.RecordsPerPage, pagination.Page);

            // Generate result
            var result = await query.Paginate(pagination).Include(_ => _.CreatedByUser).ToListAsync();

            //await query.Paginate(pagination).Include(_=>_.CreatedByUser).DefaultIfEmpty().ToListAsync();

            // Return error if count is 0
            if (result.Count == 0)
            {
                throw new InvalidOperationException("Product Group is not Exist");
            }

            // Mapping
            var dto = _mapper.Map <List <ProductGroupDTO> >(result);

            // Return Results
            return(ResponseResultWithPagination.Success <List <ProductGroupDTO> >(dto, paginationResult));
        }
예제 #12
0
        public async Task <ServiceResponseWithPagination <List <Bulk> > > GetBulkWithPagination(PaginationDto pagination)
        {
            var queryable = _dBContext.Bulk.AsQueryable();

            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(queryable, pagination.RecordsPerPage, pagination.Page);

            var dto = await queryable.Paginate(pagination).ToListAsync();

            return(ResponseResultWithPagination.Success(dto, paginationResult));
        }
        public async Task <ServiceResponseWithPagination <List <ProductDTO> > > GetAll(PaginationDto pagination = null, ProductFilterDTO productFilter = null, DataOrderDTO ordering = null)
        {
            // Quering data
            var query = _dbContext.Product.AsQueryable();

            // Filtering data
            query = Filter(query, productFilter);

            // Ordering
            if (!(ordering is null))
            {
                var columns = new List <string> {
                    "Id", "GroupId", "Name", "Price", "CreatedBy", "Status"
                };

                if (columns.Exists(x => x == ordering.OrderBy))
                {
                    if (ordering.OrderBy == "CreatedBy")
                    {
                        ordering.OrderBy = "CreatedByUser.Username";
                    }

                    var property = $"{ordering.OrderBy}";

                    if (!String.IsNullOrEmpty(ordering.Sort) && ordering.Sort.ToLower() == "desc")
                    {
                        query = ApplyOrder(query, property, "OrderByDescending");
                    }
                    else
                    {
                        query = ApplyOrder(query, property, "OrderBy");
                    }
                }
            }

            // Pagination
            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(query, pagination.RecordsPerPage, pagination.Page);

            // Generate result
            var result = await query.Paginate(pagination).Include(entity => entity.CreatedByUser.Products).Include(entity => entity.Group).ToListAsync();

            // Return error if count is 0
            if (result.Count == 0)
            {
                return(ResponseResultWithPagination.Failure <List <ProductDTO> >("Product is not Exist", ResponseType.NoContent));
            }

            // Mapping
            var dto = _mapper.Map <List <ProductDTO> >(result);

            // Return Results
            return(ResponseResultWithPagination.Success <List <ProductDTO> >(dto, paginationResult));
        }
예제 #14
0
        public async Task <ServiceResponseWithPagination <List <ProductStockDTO> > > GetStockHistory(int productId, PaginationDto pagination = null)
        {
            string responseMessage;

            // Check product is exist
            if (productId <= 0)
            {
                throw new ArgumentOutOfRangeException("productId", productId, "Product ID must greater than 0");
            }


            var product = await _dbContext.Product
                          .Where(_ => _.Id == productId)
                          .FirstOrDefaultAsync();

            if (product is null)
            {
                throw new InvalidOperationException("Product is not Exist");
            }

            var stockHistory = _dbContext.Stock
                               .Where(_ => _.ProductId == productId)
                               .OrderByDescending(_ => _.Id)
                               .AsQueryable();

            var paginationResult = await _httpContext.HttpContext
                                   .InsertPaginationParametersInResponse(
                stockHistory,
                pagination.RecordsPerPage,
                pagination.Page
                );

            var result = await stockHistory.Paginate(pagination)
                         .Include(_ => _.CreatedByUser)
                         .Include(_ => _.Product)
                         .Include(_ => _.Product.Group)
                         .ToListAsync();


            if (result.Count == 0)
            {
                responseMessage = $"Product ({product.Name}) have no recent stock records";
            }
            else
            {
                responseMessage = $"Product ({product.Name}) requested record successfully";
            }

            var dto = _mapper.Map <List <ProductStockDTO> >(result);

            return(ResponseResultWithPagination.Success <List <ProductStockDTO> >(dto, paginationResult, responseMessage));
        }
예제 #15
0
        public async Task <IActionResult> GetAll([FromQuery] PaginationDto pagination, [FromQuery] OrderFilterDTO filter, [FromQuery] DataOrderDTO order)
        {
            try
            {
                var result = await _service.GetAll(pagination, filter, order);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(Ok(ResponseResultWithPagination.Failure <OrderDTO>(ex.Message)));
            }
        }
        public async Task <IActionResult> GetAll([FromQuery] PaginationDto pagination, [FromQuery] string filter = null, [FromQuery] DataOrderDTO ordering = null)
        {
            try
            {
                var paginationResult = await _ProductGroupService.GetAll(pagination, filter, ordering);

                return(Ok(paginationResult));
            }
            catch (Exception ex)
            {
                return(Ok(ResponseResultWithPagination.Failure <List <ProductGroupDTO> >(ex.Message)));
            }
        }
예제 #17
0
        public async Task <ServiceResponseWithPagination <List <MovieDto> > > GetAllMoviesPagination(PaginationDto pagination)
        {
            var queryable        = _context.Movies.AsQueryable();
            var paginationResult = await _httpContext.HttpContext
                                   .InsertPaginationParametersInResponse(
                queryable
                , pagination.RecordsPerPage
                , pagination.Page);

            var movies = await queryable.Paginate(pagination).ToListAsync();

            List <MovieDto> movieDTOs = _mapper.Map <List <MovieDto> >(movies);

            return(ResponseResultWithPagination.Success(movieDTOs, paginationResult));
        }
예제 #18
0
        public async Task <ServiceResponseWithPagination <List <mProduct> > > GetProductWithFilter(GetProductFilterDto ProductFilter)
        {
            var Queryable = _dbContext.Products
                            .Include(x => x.ProductGroup)
                            .AsQueryable();

            if (!string.IsNullOrWhiteSpace(ProductFilter.Name))
            {
                Queryable = Queryable.Where(x => x.Name.Contains(ProductFilter.Name));
            }

            if (ProductFilter.Price != null)
            {
                Queryable = Queryable.Where(x => x.Price == ProductFilter.Price);
            }

            if (ProductFilter.StockCount != null)
            {
                Queryable = Queryable.Where(x => x.StockCount == ProductFilter.StockCount);
            }


            if (ProductFilter.ProductGroupId != null)
            {
                Queryable = Queryable.Where(x => x.ProductGroupId == ProductFilter.ProductGroupId);
            }

            if (!string.IsNullOrWhiteSpace(ProductFilter.OrderingField))
            {
                try
                {
                    Queryable = Queryable.OrderBy($"{ProductFilter.OrderingField} {(ProductFilter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <Models.Product.Product> >($"Could not order by field: {ProductFilter.OrderingField}"));
                }

                ;
            }

            var paginationResult = await _httpcontext.HttpContext.InsertPaginationParametersInResponse(Queryable, ProductFilter.RecordsPerPage, ProductFilter.Page);

            var dto = await Queryable.Paginate(ProductFilter).ToListAsync();

            return(ResponseResultWithPagination.Success(dto, paginationResult));
        }
예제 #19
0
        public async Task <IActionResult> GetStockHistory(int id, [FromQuery] PaginationDto pagination)
        {
            string errorMessage;

            try
            {
                var result = await _services.GetStockHistory(id, pagination);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            return(Ok(ResponseResultWithPagination.Failure <List <ProductStockDTO> >(errorMessage)));
        }
        public async Task <ServiceResponseWithPagination <List <GetVoiceRecordDetail> > > GetVoiceRecordDetailJson(FilterVoiceRecordDetail filter)
        {
            var queryable = _dBContext.VoiceRecordDetails.AsNoTracking().AsQueryable();

            //************************************Start Filter*************************************//
            //Filter AgentId
            if (filter.ExtensionNo != null)//null is for get all AgentId
            {
                queryable = queryable.Where(x => x.ExtensionNo == filter.ExtensionNo);
            }
            //Filter CallType
            if (filter.CallingType != null) //null is for get all type
            {
                queryable = queryable.Where(x => x.CallTypeId == filter.CallingType);
            }
            //Filter duration of date
            if (filter.EndDate != default(DateTime))
            {
                queryable = queryable.Where(x => x.CreatedDate >= filter.StartDate && x.CreatedDate <= filter.EndDate);
            }
            //************************************End Filter*************************************//

            //Ordering
            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    queryable = queryable.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <GetVoiceRecordDetail> >($"Could not order by field: {filter.OrderingField}"));
                }
            }

            var paginationResult = await _httpContext.HttpContext
                                   .InsertPaginationParametersInResponse(queryable, filter.RecordsPerPage, filter.Page);

            var dto = await queryable.Paginate(filter).AsNoTracking().ToListAsync();

            var VoiceDto = _mapper.Map <List <GetVoiceRecordDetail> >(dto);

            return(ResponseResultWithPagination.Success(VoiceDto, paginationResult));
        }
예제 #21
0
        public async Task <ServiceResponse <List <OrderDTO_ToReturn> > > SearchOrderPaginate(OrderDTO_Filter filter)
        {
            var queryable = _dbContext.Orders.AsQueryable();

            //filter
            if (!String.IsNullOrWhiteSpace(filter.PaymentType))
            {
                queryable = queryable.Where(x => (x.PaymentType).Contains(filter.PaymentType));
            }

            if (filter.MinPrice != 0)
            {
                queryable = queryable.Where(x => x.TotalPrice >= filter.MinPrice);
            }

            //Order By
            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    queryable = queryable.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <OrderDTO_ToReturn> >($"Could not order by field: {filter.OrderingField}"));
                }
            }


            //Add Paginate
            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(queryable, filter.RecordsPerPage, filter.Page);

            //Excute query
            var order = await queryable.Paginate(filter).ToListAsync();

            var result = _mapper.Map <List <OrderDTO_ToReturn> >(order);

            return(ResponseResultWithPagination.Success(result, paginationResult));
        }
예제 #22
0
        public async Task <ServiceResponseWithPagination <List <BookDTO_ToReturn> > > SearchPaginate(BookDTO_Filter filter)
        {
            // 1. Filter => Search
            var queryable = _db.Books.AsQueryable();

            if (!string.IsNullOrWhiteSpace(filter.Name))
            {
                queryable = queryable.Where(x => (x.Name).Contains(filter.Name));
            }

            queryable = queryable.Where(x => x.Price >= filter.MinPrice);
            queryable = queryable.Where(x => x.Price <= filter.MaxPrice);


            // 2. Order => Order by
            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    queryable = queryable.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <BookDTO_ToReturn> >($"Could not order by field: {filter.OrderingField}"));
                }
            }


            // 3. Add Paginate => Page,total,Perpage
            var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(queryable, filter.RecordsPerPage, filter.Page);

            // 4. Execute Query
            var books = await queryable.Paginate(filter).ToListAsync();

            // 5. Return result
            var result = _mapper.Map <List <BookDTO_ToReturn> >(books);

            return(ResponseResultWithPagination.Success(result, paginationResult));
        }
예제 #23
0
        public async Task <ServiceResponseWithPagination <List <MovieDto> > > Filter(MovieDtoFilter filter)
        {
            var query = _context.Movies.AsQueryable();

            //Filter
            if (!string.IsNullOrWhiteSpace(filter.Title))
            {
                query = query.Where(x => x.Title.Contains(filter.Title));
            }

            if (filter.UpcomingReleases)
            {
                query = query.Where(x => x.InTheaters);
            }

            if (filter.UpcomingReleases)
            {
                var today = new DateTime(2020, 01, 01);
                query = query.Where(x => x.ReleaseDate > today);
            }

            if (filter.GenreId != 0)
            {
                query = query.Where(x => x.MoviesGenres.Select(y => y.GenreId)
                                    .Contains(filter.GenreId));
            }

            //Ordering
            if (!string.IsNullOrWhiteSpace(filter.OrderingField))
            {
                try
                {
                    //nuget system.linq.dynamic.core
                    query = query.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <MovieDto> >("Could not order by field: " + filter.OrderingField));
                }

                //if (filter.OrderingField == "title")
                //{
                //    if (filter.AscendingOrder)
                //    {
                //        query = query.OrderBy(x => x.Title);
                //    }
                //    else
                //    {
                //        query = query.OrderByDescending(x => x.Title);
                //    }
                //}
            }

            var paginationResult = await _httpContext.HttpContext
                                   .InsertPaginationParametersInResponse(
                query
                , filter.RecordsPerPage
                , filter.Page);

            var movies = await query.Paginate(filter).ToListAsync();

            List <MovieDto> movieDTOs = _mapper.Map <List <MovieDto> >(movies);

            return(ResponseResultWithPagination.Success(movieDTOs, paginationResult));
        }
예제 #24
0
        public async Task <ServiceResponseWithPagination <List <mOrder> > > GetOrderWithFilter(GetOrderFilterDto orderFilter)
        {
            var Queryable = _dbContext.Orders
                            .AsQueryable();

            if (orderFilter.DateOrder != null)
            {
                Queryable = Queryable.Where(x => x.DateOrder.Date == orderFilter.DateOrder.Value);
            }

            if (orderFilter.ItemCount > 0)
            {
                Queryable = Queryable.Where(x => x.ItemCount == orderFilter.ItemCount);
            }

            if (orderFilter.Total > 0)
            {
                Queryable = Queryable.Where(x => x.Total == orderFilter.Total);
            }

            if (orderFilter.Discount > 0)
            {
                Queryable = Queryable.Where(x => x.Discount == orderFilter.Discount);
            }

            if (orderFilter.Net > 0)
            {
                Queryable = Queryable.Where(x => x.Net == orderFilter.Net);
            }

            if (!string.IsNullOrWhiteSpace(orderFilter.OrderNumber))
            {
                Queryable = Queryable.Where(x => x.OrderNumber.Contains(orderFilter.OrderNumber));
            }


            if (orderFilter.Status != null)
            {
                Queryable = Queryable.Where(x => x.Status == orderFilter.Status);
            }


            if (!string.IsNullOrWhiteSpace(orderFilter.OrderingField))
            {
                try
                {
                    Queryable = Queryable.OrderBy($"{orderFilter.OrderingField} {(orderFilter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <Models.Order.Order> >($"Could not order by field: {orderFilter.OrderingField}"));
                }

                ;
            }

            var paginationResult = await _httpcontext.HttpContext.InsertPaginationParametersInResponse(Queryable, orderFilter.RecordsPerPage, orderFilter.Page);

            var dto = await Queryable.Paginate(orderFilter).ToListAsync();

            return(ResponseResultWithPagination.Success(dto, paginationResult));
        }