Exemple #1
0
        public async Task <ResponseViewModel> DeleteProductAsync(string id, CancellationToken cancellationToken = default)
        {
            var response = new ResponseViewModel();
            var success  = await _productRepository.DeleteProduct(id, cancellationToken);

            if (!success)
            {
                response.AddMessage("Cannot delete product.", ResponseMessageType.Warning);
                return(await Task.FromResult(response));
            }
            response.Succeed();
            return(await Task.FromResult(response));
        }
Exemple #2
0
        public async Task <ResponseViewModel <bool> > UpdateProductByAsync(string id, Product product, CancellationToken cancellationToken = default)
        {
            var response = new ResponseViewModel <bool>();
            var success  = await _productRepository.UpdateProductByAsync(id, product, cancellationToken);

            if (!success)
            {
                response.AddMessage("Product cannot be updated.", ResponseMessageType.Warning);
                return(await Task.FromResult(response));
            }
            response.Succeed();
            return(await Task.FromResult(response));
        }
Exemple #3
0
        public async Task <ResponseViewModel <IEnumerable <Product> > > GetProductsAsync(CancellationToken cancellationToken = default)
        {
            var response = new ResponseViewModel <IEnumerable <Product> >();

            response.Entity = await _productRepository.GetProductsAsync(cancellationToken);

            if (response.Entity is null)
            {
                response.AddMessage("No product is found.", ResponseMessageType.Warning);
                return(await Task.FromResult(response));
            }
            response.Succeed();
            return(await Task.FromResult(response));
        }
Exemple #4
0
        public async Task <ResponseViewModel <Product> > GetProductByIdAsync(string id, CancellationToken cancellationToken = default)
        {
            var response = new ResponseViewModel <Product>();

            response.Entity = await _productRepository.GetProductByIdAsync(id, cancellationToken);

            if (response.Entity is null)
            {
                response.AddMessage("No product is found with this ID.", ResponseMessageType.Warning);
                return(await Task.FromResult(response));
            }
            response.Succeed();
            return(await Task.FromResult(response));
        }