public UpdateExistingBeerValidator(IBeerCatalog catalog)
        {
            RuleFor(beer => beer.Id)
            .Custom((id, context) =>
            {
                if (catalog.FindOneBeerByGuid(id) == null)
                {
                    context.AddFailure("Unknown beer.");
                }
            })
            .NotNull();

            RuleFor(beer => beer.Label)
            .NotNull()
            .NotEmpty()
            .MinimumLength(3);

            RuleFor(beer => beer.Description)
            .NotNull()
            .NotEmpty()
            .MinimumLength(3);

            RuleFor(beer => beer.Stock)
            .NotNull()
            .GreaterThanOrEqualTo(0);
        }
示例#2
0
        public void Execute(GetOneBeerRequest request, IGetOneBeerPresenter presenter)
        {
            var beer = _catalog.FindOneBeerByGuid(request.Id);

            var response = new GetOneBeerResponse
            {
                Beer = beer
            };

            presenter.Present(response);
        }
示例#3
0
        public void Execute(DeleteExistingBeerRequest request, IDeleteExistingBeerPresenter presenter)
        {
            var beer = _catalog.FindOneBeerByGuid(request.Id);

            var response = new DeleteExistingBeerResponse();

            if (beer == null)
            {
                response.Founded = false;
            }
            else
            {
                _catalog.DeleteExistingBeer(request.Id);

                response.Founded = true;
            }

            presenter.Present(response);
        }