예제 #1
0
 public async Task <IDataResult <Product> > GetByIdAsync(int id)
 {
     try
     {
         return(new SuccessDataResult <Product>(await _productDal.GetAsync(p => p.ProductId == id)));
     }
     catch (Exception ex)
     {
         return(new ErrorDataResult <Product>(await _productDal.GetAsync(p => p.ProductId == id), ex.Message));
     }
 }
예제 #2
0
        public IDataResult <Product> GetAsync(Expression <Func <Product, bool> > filter)
        {
            if (DateTime.Now.Hour == 07)
            {
                return(new ErrorDataResult <Product>(ProductMessages.MaintenanceTime));
            }

            var _getAsync = _productDal.GetAsync(filter).Result;

            if (_getAsync == null)
            {
                return(new ErrorDataResult <Product>(ProductMessages.RecordNotFound));
            }
            return(new SuccessDataResult <Product>(_getAsync, ProductMessages.ProductListed));
        }
예제 #3
0
            public async Task <IResult> Handle(UpdateProductCommand request, CancellationToken cancellationToken)
            {
                var productToUpdate = await _productDal.GetAsync(u => u.ProductID == request.ProductID);


                productToUpdate.CategoryId      = request.CategoryId;
                productToUpdate.ProductName     = request.ProductName;
                productToUpdate.QuantityPerUnit = request.QuantityPerUnit;
                productToUpdate.UnitPrice       = request.UnitPrice;
                productToUpdate.UnitsInStock    = request.UnitsInStock;

                await _productDal.UpdateAsync(productToUpdate);

                return(new SuccessResult(Messages.ProductUpdated));
            }
예제 #4
0
            public async Task <IResult> Handle(UpdateProductCommand request, CancellationToken cancellationToken)
            {
                var productExits = await _productDal.GetAsync(u => u.ProductName == request.ProductName);

                if (productExits != null)
                {
                    return(new ErrorResult(Messages.NameAlreadyExist));
                }

                var productToUpdate = new Product
                {
                    CategoryId      = request.CategoryId,
                    ProductName     = request.ProductName,
                    QuantityPerUnit = request.QuantityPerUnit,
                    UnitPrice       = request.UnitPrice,
                    UnitsInStock    = request.UnitsInStock
                };
                await _productDal.UpdateAsync(productToUpdate);

                return(new SuccessResult(Messages.ProductUpdated));
            }
예제 #5
0
            public async Task <IDataResult <Product> > Handle(GetProductQuery request, CancellationToken cancellationToken)
            {
                var product = await _productDal.GetAsync(p => p.ProductID == request.ProductId);

                return(new SuccessDataResult <Product>(product));
            }
        public async Task <Product> GetAsync(Expression <Func <Product, bool> > filter)
        {
            var cancelToken = new CancellationTokenSource();

            return(await _productDal.GetAsync(filter, cancelToken.Token));
        }
            public async Task <Product> Handle(GetProductQuery request, CancellationToken cancellationToken)
            {
                var product = await _productDal.GetAsync(p => p.ProductId == request.ProductId);

                return(product);
            }