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);
        }
        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);
        }
Esempio n. 4
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);
        }