Exemplo n.º 1
0
        public async Task <Response <int> > Handle(CreateProductCommand request, CancellationToken cancellationToken)
        {
            var product = _mapper.Map <Product>(request);
            await _productRepository.AddAsync(product);

            return(new Response <int>(product.Id));
        }
        public async Task <Response <Guid> > Handle(CreateProductCommand request, CancellationToken cancellationToken)
        {
            var product = _mapper.Map <Product>(request);
            await _productRepository.AddAsync(product).ConfigureAwait(false);

            await _unitOfWork.Commit <Guid>(cancellationToken).ConfigureAwait(false);

            return(new Response <Guid>(product.Id));
        }
            public async Task <Result <int> > Handle(CreateProductCommand command, CancellationToken cancellationToken)
            {
                var product = _mapper.Map <Domain.Entities.Products.Product>(command);

                if (await _productRepository.DoesBarCodeExist(product.Barcode))
                {
                    return(Result <int> .Failure($"Product with Barcode {product.Barcode} already exists."));
                }
                var result = await _productRepository.AddAsync(product);

                return(Result <int> .Success(result.Id));
            }
Exemplo n.º 4
0
 public async Task SeedCreateProductDemo(IProductRepositoryAsync productRepository)
 {
     _productRepository = productRepository;
     //Seed Default User
     var defaultProduct = new Product
     {
         Name        = "ABC",
         Barcode     = "123456",
         Description = "Mo ta",
         IsDeleted   = false
     };
     await _productRepository.AddAsync(defaultProduct);
 }
        public async Task <Response <Product> > Handle(CreateProductCommand request, CancellationToken cancellationToken)
        {
            var product = _mapper.Map <Product>(request);
            await _productRepository.AddAsync(product);

            var result = await _unitOfWork.Commit(cancellationToken);

            if (result > 0)
            {
                return(new Response <Product>(product));
            }
            return(new Response <Product>(null));
        }
        public async Task <Response <int> > Handle(CreateProductCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var product = _mapper.Map <Product>(request);
                await _productRepository.AddAsync(product);

                return(new Response <int>(await _unitOfWork.Commit(cancellationToken)));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public async Task <Response <CreateProductDto> > Handle(CreateProductCommand request, CancellationToken cancellationToken)
        {
            var response = await _ProductRepository.AddAsync((_mapper.Map <Product>(request)));

            return(new Response <CreateProductDto>(_mapper.Map <CreateProductDto>(response), "Product created successfull"));
        }