Exemplo n.º 1
0
        public async Task <CreatePriceResponse> Handle(
            CreatePriceRequest request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                _notificationContext.AddNotification("Request null", "O request não pode ser nulo");
                return(null);
            }

            var priceRange = await _priceRangeRepository.GetByIdAsync(request.IdPriceRange);

            if (priceRange == null)
            {
                _notificationContext.AddNotification("Price range", "Price range não encontrado");
                return(null);
            }

            var price = new Price(
                request.Start,
                request.End,
                request.Value
                );

            if (price.Invalid)
            {
                _notificationContext.AddNotifications(price.ValidationResult);
                return(null);
            }

            price.HasOne(priceRange);

            await _priceRepository.CreateAsync(price);

            return(new CreatePriceResponse(price.Id, priceRange.Id));
        }
Exemplo n.º 2
0
        public async Task <Option <Exception, Guid> > Handle(PriceCreateCommand request, CancellationToken cancellationToken)
        {
            var allReadIn = await _repository.GetByDateAsync(request.Initial);

            if (allReadIn.IsSuccess)
            {
                return(new DuplicateException("Já existe preço com periodo inicial informado"));
            }

            var createCallBack = await _repository.CreateAsync(Mapper.Map <PriceCreateCommand, Price>(request));

            if (createCallBack.IsFailure)
            {
                return(createCallBack.Failure);
            }

            return(createCallBack.Success.Id);
        }