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 }); }