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);
        }
Exemple #2
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);
        }
        public async ValueTask <RequestResult <Order> > AddOrder(Order dataModel)
        {
            var result = new RequestResult <Order>();

            try
            {
                string  path;
                decimal curCurrency = 1;
                switch (dataModel.City.Id)
                {
                case (int?)CityEnum.Kiev:
                    path        = "UAH";
                    curCurrency = await CurrentCurrency.GetCurrency(path);

                    break;

                case (int?)CityEnum.Minsk:
                    path        = "BYN";
                    curCurrency = await CurrentCurrency.GetCurrency(path);

                    break;
                }
                foreach (var item in dataModel.OrderDetails)
                {
                    item.LocalPrice /= curCurrency;
                }
                _orderStorage.TransactionStart();
                result.RequestData = await _orderStorage.AddOrder(dataModel);

                _orderStorage.TransactionCommit();
                result.IsOkay = true;
            }
            catch (Exception ex)
            {
                _orderStorage.TransactioRollBack();
                result.ExMessage = ex.Message;
            }
            return(result);
        }
        public async ValueTask <RequestResult <Order> > AddOrder(Order dataModel)
        {
            if (!Russia.Cities.Contains(dataModel.FilialCity))
            {
                await ConvertPrices(dataModel);
            }
            var result = new RequestResult <Order>();

            try
            {
                _orderStorage.TransactionStart();
                result.RequestData = await _orderStorage.AddOrder(dataModel);

                _orderStorage.TransactionCommit();
                result.IsOkay = true;
            }
            catch (Exception ex)
            {
                _orderStorage.TransactioRollBack();
                result.ExMessage = ex.Message;
            }
            return(result);
        }
Exemple #5
0
        public async ValueTask <RequestResult <Order> > AddOrder(Order dataModel)
        {
            var result = new RequestResult <Order>();

            try
            {
                _orderStorege.TransactionStart();
                string  country;
                decimal currency = 1;

                switch (dataModel.City.Id)
                {
                case (int)CountryTypeEnam.Belarus:
                    country  = "UAH";
                    currency = await CurCurrency.GetCurrentCurrency(country);

                    break;

                case (int)CountryTypeEnam.Ukraine:
                    country  = "BYN";
                    currency = await CurCurrency.GetCurrentCurrency(country);

                    break;
                }
                result.RequestData = await _orderStorege.OrderAdd(dataModel, currency);

                _orderStorege.TransactionCommit();
                result.IsOkay = true;
            }
            catch (Exception ex)
            {
                _orderStorege.TransactioRollBack();
                result.ExMessage = ex.Message;
            }
            return(result);
        }