private async Task <Result> AddOrderProductAsync(Order order, OrderProductModel orderProductModel) { OrderProduct orderProduct = _orderProductMapper.MapBackToEntity(orderProductModel); orderProduct.OrderId = order.Id; Product product = await _productRepository.GetByIdAsync(orderProduct.ProductId); if (product == null) { return(new Result { ResponseMessageType = ResponseMessageType.Error }); } if (orderProduct.Quantity <= product.AvaliableQuantity) { orderProduct.Price = product.Price * orderProduct.Quantity; order.TotalCost += orderProduct.Price; product.AvaliableQuantity -= orderProduct.Quantity; await _orderProductRepository.AddAsync(orderProduct); _productRepository.Update(product); await _orderProductRepository.SaveAsync(); } return(new Result { ResponseMessageType = ResponseMessageType.Success }); }
/// <summary> /// Creates a purchase OrderProductModel and adds it to the database /// </summary> public void CreatePurchaseOrderProuct(int orderId, PurchaseOrderDetails_Join row) { OrderProductModel op = new OrderProductModel { OrderId = orderId, ProductId = row.ProductId, ProductName = row.ProductName, OrderedQuantity = row.Quantity, TaxId = row.TaxId }; GlobalConfig.Connection.Create_PO_Product(op); }