예제 #1
0
        public async ValueTask <RequestResult <Order> > AddOrder(Order model)
        {
            var      result = new RequestResult <Order>();
            DateTime today  = DateTime.Today;

            try
            {
                if (CurrencyRates.ActualCurrencyRates == null || CurrencyRates.ActualCurrencyRates.Find(i => Equals(i.Date, today)).Date == null)
                {
                    string path = "";
                    switch (model.Warehouse.Id)
                    {
                    case (int)WarehouseEnum.Minsk:
                        path = "BYN";
                        _sendRequest.GetLocalCurrency(path);
                        break;

                    case (int)WarehouseEnum.Kiev:
                        path = "UAH";
                        _sendRequest.GetLocalCurrency(path);
                        break;

                    default: break;
                    }
                }


                foreach (OrderDetails item in model.OrderDetails)
                {
                    item.LocalPrice /= CurrencyRates.ActualCurrencyRates.Find(i => Equals(i.Date, today)).Rate;
                }
                _orderStorage.TransactionStart();
                result.RequestData = await _orderStorage.AddOrder(model);

                _orderStorage.TransactionCommit();
                result.IsOk = true;
            }
            catch (Exception ex)
            {
                _orderStorage.TransactionRollBack();
                result.ExMessage = ex.Message;
            }
            return(result);
        }