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)); } }
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)); }
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)); }
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)); }
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); }