public new async Task <PagedResults <ProductDto> > GetListAsync(int offset, int limit, string keyword, SortOptions <ProductDto, ProductEntity> sortOptions, FilterOptions <ProductDto, ProductEntity> filterOptions, IQueryable <ProductEntity> querySearch)
        {
            IQueryable <ProductEntity> query = _entity;

            query = sortOptions.Apply(query);
            query = filterOptions.Apply(query);
            if (keyword != null)
            {
                query = querySearch;
            }

            var size = await query.CountAsync();

            var items = await query
                        .Skip(offset *limit)
                        .Take(limit)
                        .ProjectTo <ProductDto>()
                        .ToArrayAsync();

            return(new PagedResults <ProductDto>
            {
                Items = items,
                TotalSize = size
            });
        }
Ejemplo n.º 2
0
        public async Task <PagedResults <UserDto> > GetListAsync(int offset, int limit, string keyword,
                                                                 SortOptions <UserDto, UserEntity> sortOptions, FilterOptions <UserDto, UserEntity> filterOptions,
                                                                 IQueryable <UserEntity> querySearch
                                                                 )
        {
            IQueryable <UserEntity> query = _entity;

            query = sortOptions.Apply(query);
            query = filterOptions.Apply(query);
            if (keyword != null)
            {
                query = querySearch;
            }

            var size = await query.CountAsync();

            var items = await query
                        .Skip(offset *limit)
                        .Take(limit)
                        .ToArrayAsync();

            List <UserDto> returnUserList = new List <UserDto>();

            foreach (UserEntity user in items)
            {
                var roleNames = await _userManager.GetRolesAsync(user);

                var userStorages = _context.UserStorages.Where(us => us.UserId == user.Id).Include(us => us.Storage).OrderBy(s => s.Storage.Name);
                var storages     = new List <StorageDto>();

                foreach (var userStorage in userStorages)
                {
                    storages.Add(Mapper.Map <StorageDto>(userStorage.Storage));
                }

                var userDto = new UserDto
                {
                    FirstName          = user.FirstName,
                    LastName           = user.LastName,
                    Email              = user.Email,
                    PhoneNumber        = user.PhoneNumber,
                    Id                 = user.Id,
                    UserName           = user.UserName,
                    JobTitle           = user.JobTitle,
                    IsActive           = user.IsActive,
                    RoleNames          = roleNames,
                    AccessibleStorages = storages
                };
                returnUserList.Add(userDto);
            }

            return(new PagedResults <UserDto>
            {
                Items = returnUserList,
                TotalSize = size
            });
        }
Ejemplo n.º 3
0
        public async Task <PagedResults <OrderDto> > GetListAsync(
            int offset, int limit, string keyword,
            SortOptions <OrderDto, OrderEntity> sortOptions,
            FilterOptions <OrderDto, OrderEntity> filterOptions,
            IQueryable <OrderEntity> querySearch)
        {
            IQueryable <OrderEntity> query = _order;

            query = sortOptions.Apply(query);
            query = filterOptions.Apply(query);

            if (keyword != null)
            {
                // DateTime a = DateTime.ParseExact(DateTime.Now.Date.ToString(), "dd/MM/yyyy",
                // System.Globalization.CultureInfo.InvariantCulture).Date;
                query = query.Where(p =>
                                    p.Code.Contains(keyword) ||
                                    p.Status.Contains(keyword)
                                    );
            }

            var items = await query
                        .Skip(offset *limit)
                        .Take(limit)
                        .ToArrayAsync();

            var totalSize = await query.CountAsync();

            var returnItems = Mapper.Map <List <OrderDto> >(items);



            for (var i = 0; i < items.Length; i++)
            {
                returnItems[i].PackageList = new List <PackageDto>();

                var packageIdList = JsonConvert.DeserializeObject <List <Guid> >(items[i].PackageIdList);
                foreach (Guid packageId in packageIdList)
                {
                    var package = await _context.Packages.SingleOrDefaultAsync(s => s.Id == packageId);

                    if (package == null)
                    {
                        throw new Exception("Can not find storage with Id=" + packageId);
                    }
                    var packageDto = Mapper.Map <PackageDto>(package);
                    returnItems[i].PackageList.Add(packageDto);
                }
            }
            return(new PagedResults <OrderDto>
            {
                Items = returnItems,
                TotalSize = totalSize
            });
        }
Ejemplo n.º 4
0
        public async Task <IEnumerable <TopicResultDto> > GetAll(string userId, SearchOptions <TopicResultDto, Topic> searchOptions,
                                                                 PagingOptions pagingOptions, FilterOptions filterOptions)
        {
            var query = _context.Topics
                        .Where(t => !t.IsDeleted)
                        .Include(t => t.Category)
                        .Include(t => t.User)
                        .Include(t => t.Comments)
                        .Include(t => t.Views)
                        .AsQueryable();

            query = pagingOptions.Apply(filterOptions.Apply(searchOptions.Apply(query), userId));

            return((await query.ToListAsync()).Select(TopicResultDto.Create));
        }
        public async Task <PagedResults <InventoryDto> > GetListAsync(int offset, int limit, string keyword,
                                                                      ICollection <Guid> storageIds, SortOptions <InventoryDto, InventoryEntity> sortOptions,
                                                                      FilterOptions <InventoryDto, InventoryEntity> filterOptions)
        {
            IQueryable <InventoryEntity> querySearch;

            querySearch = _entity.Where(x =>
                                        x.Code.Contains(keyword) ||
                                        x.Note.Contains(keyword) ||
                                        x.Storage.Name.Contains(keyword) ||
                                        x.ProductList.Contains(keyword)
                                        );

            try
            {
                DateTime searchDate = DateTime.ParseExact(keyword, "dd/MM/yyyy",
                                                          System.Globalization.CultureInfo.InvariantCulture).Date;
                querySearch = _entity.Where(x => x.CreatedDateTime.Date == searchDate.Date || x.BalanceDateTime == searchDate.Date);
            }
            catch (Exception)
            {
            }

            IQueryable <InventoryEntity> query = _entity;

            query = sortOptions.Apply(query);
            query = filterOptions.Apply(query);
            if (keyword != null)
            {
                query = querySearch;
            }

            query = query.Where(w => storageIds.Contains(w.StorageId));

            var items = await query
                        .Skip(offset *limit)
                        .Take(limit)
                        .ProjectTo <InventoryDto>()
                        .ToArrayAsync();

            var size = await query.CountAsync();

            return(new PagedResults <InventoryDto>
            {
                Items = items,
                TotalSize = size
            });
        }
Ejemplo n.º 6
0
        public async Task <PagedResults <UserDto> > GetListAsync(int offset, int limit, string keyword,
                                                                 SortOptions <UserDto, UserEntity> sortOptions, FilterOptions <UserDto, UserEntity> filterOptions,
                                                                 IQueryable <UserEntity> querySearch
                                                                 )
        {
            IQueryable <UserEntity> query = _entity;

            query = sortOptions.Apply(query);
            query = filterOptions.Apply(query);
            if (keyword != null)
            {
                query = querySearch;
            }

            var size = await query.CountAsync();

            var items = await query
                        .Skip(offset *limit)
                        .Take(limit)
                        .ToArrayAsync();

            List <UserDto> returnUserList = new List <UserDto>();

            foreach (UserEntity user in items)
            {
                var roleNames = await _userManager.GetRolesAsync(user);

                var userDto = new UserDto
                {
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    Email     = user.Email,
                    Id        = user.Id,
                    UserName  = user.UserName,
                    JobTitle  = user.JobTitle,
                    IsActive  = user.IsActive,
                    RoleNames = roleNames
                };
                returnUserList.Add(userDto);
            }

            return(new PagedResults <UserDto>
            {
                Items = returnUserList,
                TotalSize = size
            });
        }
Ejemplo n.º 7
0
        public async Task <IEnumerable <ProductResultDto> > GetProductsBySubcategory(string subcategoryUri, FilterOptions <ProductResultDto, Product> filterOptions,
                                                                                     SearchOptions <ProductResultDto, Product> searchOptions, PagingOptions pageOptions)
        {
            var subcategory = await _categoryService.GetSubcategoryByUri(subcategoryUri);

            if (subcategory == null)
            {
                throw new KeyNotFoundException("Subcategory not found");
            }

            var products = _context.Products
                           .Where(p => p.SubcategoryId == subcategory.Id).AsQueryable();

            if (!products.Any())
            {
                return(new List <ProductResultDto>());
            }

            if (pageOptions == null)
            {
                pageOptions = new PagingOptions
                {
                    Offset = 0,
                    Limit  = 24
                };
            }

            IQueryable <Product> query = null;

            if (filterOptions != null)
            {
                query = filterOptions.Apply(products);

                if (query == null)
                {
                    return(new List <ProductResultDto>());
                }
            }

            return(searchOptions.Apply(query ?? products)
                   .Include(p => p.Images)
                   .Include(p => p.Seller)
                   .OrderByDescending(p => p.DateTime)
                   .Skip(pageOptions.Offset ?? default)
                   .Take(pageOptions.Limit ?? 24).AsEnumerable()
                   .Select(ProductResultDto.Create));
        }
        public async Task <PagedResults <ProductStorageDto> > GetListAsync(int offset, int limit, string keyword,
                                                                           SortOptions <ProductStorageDto, ProductStorageEntity> sortOptions,
                                                                           FilterOptions <ProductStorageDto, ProductStorageEntity> filterOptions,
                                                                           Guid storageId,
                                                                           string inventoryStatus = "ALL"
                                                                           )
        {
            IQueryable <ProductStorageEntity> query = _entity.Include(p => p.Product).Include(p => p.Storage).OrderBy(p => p.Product.Code);

            query = sortOptions.Apply(query);
            query = filterOptions.Apply(query);

            if (keyword != null)
            {
                query = query.Where(
                    x => x.Product.Name.Contains(keyword) ||
                    x.Product.Code.Contains(keyword)
                    );
            }

            if (inventoryStatus == CONSTANT.PRODUCT_STORAGE_HAS_INVENTORY)
            {
                query = query.Where(x => x.Inventory > 0);
            }
            else if (inventoryStatus == CONSTANT.PRODUCT_STORAGE_SOLD_OUT)
            {
                query = query.Where(x => x.Inventory <= 0);
            }

            if (storageId != Guid.Empty)
            {
                query = query.Where(x => x.StorageId == storageId);
            }

            var size = await query.CountAsync();

            var productStorageEntities = await query
                                         .Skip(offset *limit)
                                         .Take(limit)
                                         .ToListAsync();

            var productStorageDtos = Mapper.Map <List <ProductStorageDto> >(productStorageEntities);

            for (int i = 0; i < productStorageDtos.Count; i++)
            {
                productStorageDtos[i].ProductProductionDateList = (productStorageEntities[i].ProductProductionDateList != null) ?
                                                                  JsonConvert.DeserializeObject <List <ProductProductionDateDto> >(productStorageEntities[i].ProductProductionDateList)
                    : new List <ProductProductionDateDto>();

                productStorageDtos[i].Product.UnitConverterList = (productStorageEntities[i].Product.UnitConverterList != null) ?
                                                                  JsonConvert.DeserializeObject <List <UnitConverterDto> >(productStorageEntities[i].Product.UnitConverterList)
                    : new List <UnitConverterDto>();

                productStorageDtos[i].Product.Inventory    = productStorageDtos[i].Inventory;
                productStorageDtos[i].Product.CapitalPrice = productStorageDtos[i].CapitalPrice;

                productStorageDtos[i].ProductProductionDateList = productStorageDtos[i].ProductProductionDateList.OrderBy(p => p.ProductionDate).ToList();
            }

            return(new PagedResults <ProductStorageDto>
            {
                TotalSize = size,
                Items = productStorageDtos
            });
        }
        public async Task <PagedResults <WarehousingDto> > GetListAsync(int offset, int limit, string keyword, ICollection <Guid> storageIds, SortOptions <WarehousingDto, WarehousingEntity> sortOptions,
                                                                        FilterOptions <WarehousingDto, WarehousingEntity> filterOptions,
                                                                        DateTime fromDate, DateTime toDate
                                                                        )
        {
            IQueryable <WarehousingEntity> query = _entity;

            query = sortOptions.Apply(query);
            query = filterOptions.Apply(query);
            query = query.Where(w => storageIds.Contains(w.StorageId));

            if (fromDate != DateTime.MinValue && toDate != DateTime.MinValue)
            {
                query = query.Where(w => w.CreatedDateTime.Date >= fromDate.Date &&
                                    w.CreatedDateTime.Date <= toDate.Date);
            }
            else if (fromDate != DateTime.MinValue)
            {
                query = query.Where(w => w.CreatedDateTime.Date == fromDate.Date);
            }


            if (keyword != null)
            {
                try
                {
                    DateTime searchDate = DateTime.ParseExact(keyword, "dd/MM/yyyy",
                                                              System.Globalization.CultureInfo.InvariantCulture).Date;

                    query = query.Where(w =>
                                        w.Code.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                        w.Note.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                        w.Storage.Name.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                        w.Supplier.Name.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                        w.Note.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                        w.ProductList.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                        w.InputDate.Date == searchDate.Date
                                        );
                }
                catch (Exception)
                {
                    query = query.Where(w =>
                                        w.Code.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                        w.Note.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                        w.Supplier.Name.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                        w.Note.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                        w.ProductList.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                        w.SupplierBillList.Contains(keyword, StringComparison.OrdinalIgnoreCase));
                }
            }

            var items = await query
                        .Skip(offset *limit)
                        .Take(limit)
                        .Include(w => w.Storage)
                        .Include(w => w.CreatedUser)
                        .Include(w => w.UpdatedUser)
                        .Include(w => w.Supplier)
                        .ToArrayAsync();

            var totalSize = await query.CountAsync();

            var returnItems = Mapper.Map <List <WarehousingDto> >(items);

            for (var i = 0; i < items.Length; i++)
            {
                returnItems[i].SupllierBillList = JsonConvert.DeserializeObject <List <SupplierBillDto> >(items[i].SupplierBillList);
                returnItems[i].ProductList      = JsonConvert.DeserializeObject <List <ProductForWareshousingCreationDto> >(items[i].ProductList);
            }
            return(new PagedResults <WarehousingDto>
            {
                Items = returnItems,
                TotalSize = totalSize
            });
        }
Ejemplo n.º 10
0
        public async Task <ProductPagedResultDto> GetListAsync(int offset, int limit, string keyword, Guid currentStorageId, SortOptions <ProductDto, ProductEntity> sortOptions,
                                                               FilterOptions <ProductDto, ProductEntity> filterOptions, bool isOldProduct)
        {
            IQueryable <ProductEntity> query = _entity;

            query = sortOptions.Apply(query);
            query = filterOptions.Apply(query);

            if (keyword != null)
            {
                query = query.Where(p =>
                                    (p.Code.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                     p.Name.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                     p.Note.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                     p.ProductCategory.Name.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                     p.Provider.Name.Contains(keyword, StringComparison.OrdinalIgnoreCase))
                                    );
            }

            var size = await query.CountAsync();

            var productEntities = await query.Include(p => p.ProductCategory)
                                  .Include(p => p.Provider)
                                  .Skip(offset * limit)
                                  .Take(limit)
                                  .ToListAsync();

            var productDtos = new List <ProductDto>();

            // convert string UnitConventerList to List<UnitConverterDto>
            foreach (var productEntity in productEntities)
            {
                var productDto = Mapper.Map <ProductDto>(productEntity);
                productDto.UnitConverterList = (productEntity.UnitConverterList == null) ?
                                               new List <UnitConverterDto>() : JsonConvert.DeserializeObject <List <UnitConverterDto> >(productEntity.UnitConverterList);

                productDtos.Add(productDto);
            }


            DateTime today       = DateTime.Now;
            var      settings    = _context.Settings.ToList();
            var      setting     = settings[0];
            var      oldProducts = new List <ProductDto>();

            foreach (var product in productDtos)
            {
                //var productStorage = await _context.ProductStorages
                //    .Include(ps => ps.Storage)
                //    .SingleOrDefaultAsync(ps => ps.StorageId == currentStorageId && ps.ProductId == product.Id);

                var productStorage = _allProductStorages
                                     .SingleOrDefault(ps => ps.StorageId == currentStorageId && ps.ProductId == product.Id);

                if (productStorage == null)
                {
                    throw new Exception("Can not find ProductStorage with productId=" + product.Id + ", StorageId=" + currentStorageId);
                }
                // find the lowest discount

                product.Inventory     = productStorage.Inventory;
                product.CapitalPrice  = productStorage.CapitalPrice;
                product.Storage       = Mapper.Map <StorageDto>(productStorage.Storage);
                product.PlacePosition = productStorage.PlacePosition;
                product.StorageName   = product.Storage.Name;

                if (productStorage.ProductProductionDateList != null && productStorage.ProductProductionDateList.Length > 0)
                {
                    product.ProductProductionDateList = JsonConvert.DeserializeObject <List <ProductProductionDateDto> >(productStorage.ProductProductionDateList);
                    product.ProductProductionDateList = product.ProductProductionDateList.OrderBy(p => p.ProductionDate).ToList();

                    foreach (var productProductionDate in product.ProductProductionDateList)
                    {
                        int comparedDays = setting.OldProductWarmingDays;
                        if (product.ProductCategory.Keyword == CONSTANT.PRODUCT_CATEGORY_TRAVEL_TIRE)
                        {
                            comparedDays = setting.OldTravelTireWarmingDays;
                        }
                        else if (product.ProductCategory.Keyword == CONSTANT.PRODUCT_CATEGORY_TRUCK_TIRE)
                        {
                            comparedDays = setting.OldTruckTireWarmingDays;
                        }

                        if ((today.Date - productProductionDate.ProductionDate).TotalDays >= comparedDays)
                        {
                            oldProducts.Add(product);
                            break;
                        }
                    }
                }
                else
                {
                    product.ProductProductionDateList = new List <ProductProductionDateDto>();
                }
            }

            //var returnProducts = (isOldProduct) ? oldProducts : productDtos;

            //returnProducts = returnProducts.Skip(offset * limit).Take(limit).ToList();

            return(new ProductPagedResultDto
            {
                Items = productDtos,
                TotalSize = size,
                OldProductNumber = oldProducts.Count
            });
        }
Ejemplo n.º 11
0
        public async Task <PagedResults <BillDto> > GetListAsync(int offset, int limit, string keyword,
                                                                 SortOptions <BillDto, BillEntity> sortOptions, FilterOptions <BillDto, BillEntity> filterOptions,
                                                                 List <Guid> storageIds, DateTime fromDate, DateTime toDate

                                                                 )
        {
            IQueryable <BillEntity> query = _entity;

            query = sortOptions.Apply(query);
            query = filterOptions.Apply(query);


            if (keyword != null)
            {
                try
                {
                    DateTime searchDate = DateTime.ParseExact(keyword, "dd/MM/yyyy",
                                                              System.Globalization.CultureInfo.InvariantCulture).Date;

                    query = _entity.Where(x =>
                                          x.ProductList.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Code.Contains(keyword, StringComparison.OrdinalIgnoreCase)

                                          || x.AttachedDocuments.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Note.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Storage.Name.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.CompanyName.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.CompanyTaxCode.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.CompanyAddress.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.ShipAddress.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.ShipContactName.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.ShipPhone.Contains(keyword, StringComparison.OrdinalIgnoreCase)

                                          || x.Customer.Code.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Customer.Phone.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Customer.FirstName.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Customer.LastName.Contains(keyword, StringComparison.OrdinalIgnoreCase)

                                          || x.CreatedDateTime.Date == searchDate.Date
                                          );
                }
                catch (Exception)
                {
                    query = _entity.Where(x =>
                                          x.ProductList.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Code.Contains(keyword, StringComparison.OrdinalIgnoreCase)

                                          || x.AttachedDocuments.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Note.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Storage.Name.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.CompanyName.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.CompanyTaxCode.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.CompanyAddress.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.ShipAddress.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.ShipContactName.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.ShipPhone.Contains(keyword, StringComparison.OrdinalIgnoreCase)

                                          || x.Customer.Code.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Customer.Phone.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Customer.FirstName.Contains(keyword, StringComparison.OrdinalIgnoreCase) ||
                                          x.Customer.LastName.Contains(keyword, StringComparison.OrdinalIgnoreCase)
                                          );
                }
            }

            query = query.Where(b => storageIds.Contains(b.StorageId));
            if (fromDate != DateTime.MinValue && toDate != DateTime.MinValue)
            {
                query = query.Where(b => b.CreatedDateTime.Date >= fromDate.Date &&
                                    b.CreatedDateTime.Date <= toDate.Date);
            }
            else if (fromDate != DateTime.MinValue)
            {
                query = query.Where(b => b.CreatedDateTime.Date == fromDate.Date);
            }
            var totalSize = await query.CountAsync();

            var items = await query
                        .Skip(offset *limit)
                        .Take(limit)
                        .Include(w => w.Storage)
                        .Include(w => w.User)
                        .Include(w => w.Customer)
                        .ToArrayAsync();

            var returnItems = Mapper.Map <List <BillDto> >(items);

            for (var i = 0; i < items.Length; i++)
            {
                returnItems[i].ProductList = JsonConvert.DeserializeObject <List <ProductForBillCreationDto> >(items[i].ProductList);
            }
            return(new PagedResults <BillDto>
            {
                Items = returnItems,
                TotalSize = totalSize
            });
        }