Esempio n. 1
0
        public IReadOnlyList <ProductDto> Execute(ProductSearchParams search)
        {
            var data = _context.Read();

            if (!search.Name.IsTotalyEmpty())
            {
                data = data.Where(p => p.Name.Contains(search.Name));
            }

            if (search.Order != null)
            {
                data = search.Order == SortOrder.Ascending ?
                       data.OrderBy(x => x.Name) :
                       data.OrderByDescending(x => x.Name);
            }

            return(data.ToList());
        }
 public CreateProductJsonValidation(
     IJsonProductContext productContext,
     IJsonSupplierContext supplierContext,
     IJsonManufacturerContext manufacturerContext,
     IJsonCategoryContext categoryContext)
 {
     RuleFor(x => x.Name)
     .NotEmpty()
     .Must(name => !productContext.Read().Any(x => x.Name == name))
     .WithMessage("Name must be unique.");
     RuleFor(x => x.Category)
     .Must(category => categoryContext.Read().Any(x => x.Name == category))
     .WithMessage("Category must exist");
     RuleFor(x => x.Manufacturer)
     .Must(manufacturer => manufacturerContext.Read().Any(x => x.Name == manufacturer))
     .WithMessage("Manufacturer must exist");
     RuleFor(x => x.Supplier)
     .Must(supplier => supplierContext.Read().Any(x => x.Name == supplier))
     .WithMessage("Supplier must exist");
 }