Esempio n. 1
0
        public async ValueTask <RequestResult <Order> > CreateOrder(Order order)
        {
            var result = new RequestResult <Order>();

            try
            {
                _storage.TransactionStart();
                result.RequestData            = (await _storage.OrderInsert(order));
                result.RequestData.OrderItems = new List <Order_Product>();

                foreach (var item in order.OrderItems)
                {
                    item.OrderId = result.RequestData.Id;
                    var productPrice = (await _storage.ProductsGetById(item.Product.Id)).Price;
                    item.LocalPrice = productPrice * item.Value * order.Valute.Nominal / order.Valute.Value;
                    result.RequestData.OrderItems.Add(await _storage.OrderProductInsert(item));
                }
                _storage.TransactionCommit();
                result.IsOkay = true;
            }
            catch (Exception ex)
            {
                _storage.TransactioRollBack();
                result.ExMessage = ex.Message;
            }
            return(result);
        }