public void PostOrder(Order order) { OrderedProduct orderedProduct = order.OrderedProducts.FirstOrDefault(); if (orderedProduct.Product.Count >= orderedProduct.CountProduct) { if (order.OrdererName.Length <= 100) { var orderFromList = OrderMethods.GetOrder(order, Connection); if (orderFromList == null) { OrderMethods.CreateOrder(order, Connection); } orderFromList = OrderMethods.GetOrder(order, Connection); if (orderFromList.EndDate == null) { if (OrderMethods.CheckProductInOrder(orderFromList.Id, orderedProduct.Product.Id, Connection)) { OrderMethods.UpdateOrder(orderFromList.Id, orderedProduct.Product.Id, orderedProduct.CountProduct, Connection); } else { OrderMethods.AddProductsInOrder(orderFromList.Id, orderedProduct, Connection); } ProductMethods.UpdateProduct(Connection, $"update PRODUCTS set ProductCount -= {orderedProduct.CountProduct} where Id = {orderedProduct.Product.Id};"); } } } }
public void AddProduct(Product product) { Product prodFromList = ProductMethods.GetProductById(product, ConnectionString); if (prodFromList == null) { if (product.Name.Length <= 200) { ProductMethods.AddProduct(product, ConnectionString); } } else { ProductMethods.UpdateProduct(ConnectionString, $"update PRODUCTS set ProductCount += {product.Count} where Id = {prodFromList.Id};"); } }