Exemplo n.º 1
0
        public async Task <Response> SaveProduct(ProductRequest productRequest)
        {
            if (productRequest == null)
            {
                throw new ArgumentNullException(nameof(productRequest));
            }

            ProductAgg product = null;
            ControlTransactionFields transactionInfo = TransactionInfo.GetTransactionData(productRequest.UserName);
            IDbContextTransaction    transaction     = _bagelSalesControlContext.Database.BeginTransaction();

            if (productRequest.ProductId != 0)
            {
                product = _bagelSalesControlContext.Product.ToList().Find(p => p.ProductId == productRequest.ProductId);
            }

            if (product == null)
            {
                product = MaterializeProduct(productRequest, transactionInfo);

                await _bagelSalesControlContext.AddAsync <ProductAgg>(product);
            }
            else
            {
                product.NameProduct                 = productRequest.NameProduct;
                product.InitialExistence            = productRequest.InitialExistence;
                product.Existence                   = productRequest.Existence;
                product.PurchasePrice               = productRequest.PurchasePrice;
                product.SalePrice                   = productRequest.SalePrice;
                product.Wholesaleprice              = productRequest.Wholesaleprice;
                product.TransactionModificationDate = DateTime.Now;
            }

            await _bagelSalesControlContext.SaveChangesAsync();

            transaction.Commit();

            _bagelSalesControlContext.Dispose();

            return(new Response {
                Data = product, Message = "Product Saved Successfully"
            });
        }
Exemplo n.º 2
0
        public Task <Response> GetProductByName(ProductRequest productRequest)
        {
            if (productRequest == null)
            {
                throw new ArgumentNullException(nameof(productRequest));
            }

            List <ProductAgg> products = _bagelSalesControlContext.Product.ToList().FindAll(p => p.NameProduct.Contains(productRequest.NameProduct));

            if (products.Any())
            {
                _bagelSalesControlContext.Dispose();

                return(Task.FromResult(new Response {
                    Data = products
                }));
            }

            _bagelSalesControlContext.Dispose();

            return(Task.FromResult(new Response {
                Message = "There isn't Products whit that name"
            }));
        }
        public IActionResult DeleteProduct([FromBody] ProductRequest productRequest)
        {
            Task <Response> response = _productService.DeleteProduct(productRequest);

            return(Ok(response));
        }
        public IActionResult GetProducts([FromQuery] ProductRequest productRequest)
        {
            Task <Response> products = _productService.GetProductByName(productRequest);

            return(Ok(products));
        }