示例#1
0
        public void Delete(int id)
        {
            var result = warehouseContext.Set <T>().Find(id);

            warehouseContext.Remove(result);
            warehouseContext.SaveChanges();
        }
        public IReadOnlyCollection <ProductSearchItemModel> Search(
            string code,
            string name,
            decimal?minPrice,  //  ? indica que pode ser null
            decimal?maxPrice,
            bool?isActive,
            int skip = 0, //  se não vier designado assume estes valores de paginação skip-> itens a saltar antes de apresentar
            int take = 20 //  quantidade de itens a apresentar
            )
        {
            /*
             * var result = new []{
             *
             * };
             */

            var filterItems = _ctx.Set <ProductEntity>()
                              .Select(e => new ProductSearchItemModel
            {
                Code         = e.Code,
                Name         = e.Name,
                Price        = e.Price,
                CurrentStock = e.StockMoviments.Sum(m => m.Quantity),
                IsActive     = e.DeletedOn == null,
                UpdatedOn    = e.UpdatedOn,
                UpdatedBy    = e.UpdatedBy
            });

            if (!string.IsNullOrWhiteSpace(code))
            {
                filterItems = filterItems
                              .Where(e => e.Code.Contains(code.Trim(), StringComparison.InvariantCultureIgnoreCase));
            }
            if (!string.IsNullOrWhiteSpace(name))
            {
                filterItems = filterItems
                              .Where(e => e.Name.Contains(name.Trim(), StringComparison.InvariantCultureIgnoreCase));
            }
            if (minPrice.HasValue)
            {
                filterItems = filterItems
                              .Where(e => e.Price >= minPrice.Value);
            }

            if (maxPrice.HasValue)
            {
                filterItems = filterItems
                              .Where(e => e.Price <= maxPrice.Value);
            }

            if (isActive.HasValue)
            {
                filterItems = filterItems
                              .Where(e => e.IsActive == isActive.Value);
            }

            return(filterItems.AsEnumerable()
                   .AsPage(skip, take)
                   .ToList());
        }
        public IReadOnlyCollection <StockMovementModel> Search(
            string productCode, string productName, DateTimeOffset?minDate, DateTimeOffset?maxDate,
            int skip = 0, int take = 20
            )
        {
            var filterItems = _ctx.Set <StockMovementEntity> ().Select(e => new StockMovementModel {
                Id          = e.Id,
                ProductCode = e.Product.Code,
                ProductName = e.Product.Name,
                Price       = e.Price,
                Quantity    = e.Quantity,
                CreatedOn   = e.CreatedOn,
                CreatedBy   = e.CreatedBy
            });

            if (!string.IsNullOrWhiteSpace(productCode))
            {
                filterItems = filterItems.Where(e => e.ProductCode.Contains(productCode));
            }

            if (!string.IsNullOrWhiteSpace(productName))
            {
                filterItems = filterItems.Where(e => e.ProductName.Contains(productName));
            }

            if (minDate.HasValue)
            {
                filterItems = filterItems.Where(e => e.CreatedOn >= minDate.Value);
            }

            if (maxDate.HasValue)
            {
                filterItems = filterItems.Where(e => e.CreatedOn <= maxDate.Value);
            }

            return(filterItems
                   .OrderByDescending(e => e.CreatedOn)
                   .ThenByDescending(e => e.Id)
                   .AsPage(skip, take).ToList());
        }
示例#4
0
        public IReadOnlyCollection <ProductSearchItemModel> Search(
            string code, string name, decimal?minPrice, decimal?maxPrice, bool?isActive,
            int skip = 0, int take = 20
            )
        {
            var filterItems = _ctx.Set <ProductEntity>().Select(e => new ProductSearchItemModel {
                Code         = e.Code,
                Name         = e.Name,
                Price        = e.Price,
                CurrentStock = e.StockMovements.Sum(m => m.Quantity),
                IsActive     = e.DeletedOn == null,
                UpdatedOn    = e.UpdatedOn,
                UpdatedBy    = e.UpdatedBy
            });

            if (!string.IsNullOrWhiteSpace(code))
            {
                filterItems = filterItems
                              .Where(e => e.Code.Contains(code.Trim(), StringComparison.InvariantCultureIgnoreCase));
            }

            if (!string.IsNullOrWhiteSpace(name))
            {
                filterItems = filterItems
                              .Where(e => e.Name.Contains(name.Trim(), StringComparison.InvariantCultureIgnoreCase));
            }

            if (minPrice.HasValue)
            {
                filterItems = filterItems
                              .Where(e => e.Price >= minPrice.Value);
            }

            if (maxPrice.HasValue)
            {
                filterItems = filterItems
                              .Where(e => e.Price <= maxPrice.Value);
            }

            if (isActive.HasValue)
            {
                filterItems = filterItems
                              .Where(e => e.IsActive == isActive.Value);
            }

            return(filterItems
                   .OrderBy(e => e.Name)
                   .ThenBy(e => e.Code)
                   .AsPage(skip, take).ToList());
        }