Beispiel #1
0
        public async Task <Result> DeleteProductAsync(int productId)
        {
            Product productToDelete = await _productRepository.GetByIdAsync(productId);

            if (productToDelete == null)
            {
                return(new Result
                {
                    ResponseMessageType = ResponseMessageType.Error
                });
            }

            List <OrderProduct> orderProducts = await _orderProductRepository.GetOrderProductsOfProduct(productId);

            if (orderProducts.Any())
            {
                return(new Result
                {
                    ResponseMessageType = ResponseMessageType.Error,
                    MessageDetails = "Product is used in some orders"
                });
            }

            await _productRepository.DeleteAsync(productToDelete);

            await _productRepository.SaveAsync();

            return(new Result
            {
                ResponseMessageType = ResponseMessageType.Success
            });
        }
Beispiel #2
0
        public async Task <DataResult <ProductModel> > DeleteProductAsync(int productId)
        {
            Product productToDelete = await _productRepository.GetByIdAsync(productId);

            if (productToDelete == null)
            {
                return(null);
            }

            List <OrderProduct> orderProducts = await _orderProductRepository.GetOrderProductsOfProduct(productId);

            if (orderProducts.Any())
            {
                return(new DataResult <ProductModel>
                {
                    ResponseMessageType = ResponseMessageType.Error,
                    MessageDetails = "Product is used in some orders"
                });
            }

            Product deletedProduct = await _productRepository.DeleteAsync(productToDelete);

            await _productRepository.SaveAsync();

            return(new DataResult <ProductModel>
            {
                ResponseMessageType = ResponseMessageType.Success,
                Data = _productMapper.MapToModel(deletedProduct)
            });
        }