コード例 #1
0
        private static void CreateCurrency()
        {
            mCurrency      = EntityHelper.GenerateCurreny();
            mCurrency.Name = mCurrency.Name.Substring(0, 5);

            CurrencyCore.CreateAsync(mCurrency, true).ConfigureAwait(false).GetAwaiter().GetResult();
        }
コード例 #2
0
        private static async Task UpdateCurrencies(IList <Currency> existingCurrencies, CurrencyModel currencyData)
        {
            await CreateOrUpdateCurrency(existingCurrencies, currencyData.Base, 1).ConfigureAwait(false);

            foreach (var rate in currencyData.Rates)
            {
                await CreateOrUpdateCurrency(existingCurrencies, rate.Key, rate.Value).ConfigureAwait(false);
            }

            await CurrencyCore.UpdateAsync(existingCurrencies).ConfigureAwait(false);
        }
コード例 #3
0
        public async Task <IHttpActionResult> GetAll()
        {
            try
            {
                var response = await CurrencyCore.GetAllAsync().ConfigureAwait(false);

                return(Ok(response));
            }
            catch (Exception e)
            {
                LogHelper.LogException <CurrencyController>(e);

                return(Ok(ResponseFactory <IList <Currency> > .CreateResponse(false, ResponseCode.Error)));
            }
        }
コード例 #4
0
        private static async Task PopulateCurrencies(CurrencyModel currencyData)
        {
            var currencies = new List <Currency>
            {
                new Currency
                {
                    Name       = currencyData.Base,
                    Multiplier = 1
                }
            };

            currencies.AddRange(currencyData.Rates.Select(rate => new Currency
            {
                Name       = rate.Key,
                Multiplier = rate.Value
            }));

            await CurrencyCore.CreateAsync(currencies).ConfigureAwait(false);
        }
コード例 #5
0
        private static async Task CreateOrUpdateCurrency(IEnumerable <Currency> currencies, string name, double multiplier)
        {
            var currency = currencies.FirstOrDefault(c => c.Name == name);

            if (currency == null)
            {
                currency = new Currency
                {
                    Name       = name,
                    Multiplier = multiplier
                };

                await CurrencyCore.CreateAsync(currency).ConfigureAwait(false);
            }
            else
            {
                currency.Multiplier = multiplier;
            }
        }
コード例 #6
0
        private static async Task RefreshCurrencies()
        {
            var currencyData = await RestClient.GetAsync <CurrencyModel>(CURRENCY_PROVIDER_BASE_URL, new Dictionary <string, string>
            {
                {
                    BASE_CURRENCY_PARAMETER_NAME, BASE_CURRENCY_PARAMETER_VALUE
                }
            }).ConfigureAwait(false);

            var existingCurrencies = await CurrencyCore.GetAllAsync().ConfigureAwait(false);

            if (!existingCurrencies.Success || existingCurrencies.Data == null || existingCurrencies.Data.Count == 0)
            {
                await PopulateCurrencies(currencyData).ConfigureAwait(false);
            }
            else
            {
                await UpdateCurrencies(existingCurrencies.Data, currencyData).ConfigureAwait(false);
            }
        }
コード例 #7
0
 private static void DeleteCurrency()
 {
     CurrencyCore.DeleteAsync(mCurrency).ConfigureAwait(false).GetAwaiter().GetResult();
 }
コード例 #8
0
        public void InitializeMockData()
        {
            try
            {
                Task.Run(async() =>
                {
                    var existingProducts = await ProductCore.GetAllAsync().ConfigureAwait(false);
                    if (existingProducts.Data != null && existingProducts.Data.Count != 0)
                    {
                        return;
                    }

                    var products = await ProductCore.CreateAsync(mProducts, true).ConfigureAwait(false);

                    var existingClients = await ClientCore.GetAllAsync().ConfigureAwait(false);
                    if (existingClients.Data != null && existingClients.Data.Count != 0)
                    {
                        return;
                    }

                    var currencies = await CurrencyCore.GetAllAsync().ConfigureAwait(false);
                    if (!currencies.Success || currencies.Data == null || currencies.Data.Count == 0)
                    {
                        return;
                    }

                    var currency = currencies.Data.FirstOrDefault(c => c.Name == "RON");
                    if (currency == null)
                    {
                        return;
                    }

                    foreach (var client in mClients)
                    {
                        client.CurrencyId = currency.Id;
                    }

                    var clients = await ClientCore.CreateAsync(mClients, true).ConfigureAwait(false);

                    var existingOrders = await OrderCore.GetAllAsync().ConfigureAwait(false);
                    if (existingOrders.Data != null && existingOrders.Data.Count != 0)
                    {
                        return;
                    }

                    int nr = 0;
                    List <Order> newOrders = new List <Order>();
                    foreach (var client in clients.Data)
                    {
                        if (products.Data.Count >= 6)
                        {
                            for (int i = 0; i < 2; i++)
                            {
                                nr++;
                                var o = new Order()
                                {
                                    Id         = Guid.NewGuid(),
                                    CurrencyId = currency.Id,
                                    ClientId   = client.Id,
                                    SaleType   = i,
                                    Status     = 0,
                                    Date       = DateTime.Now.AddDays(-nr).AddHours(-nr),
                                    OrderItems = new List <OrderItem>()
                                };

                                for (int k = i + nr / 2; k < 6; k += 1)
                                {
                                    o.OrderItems.Add(new OrderItem()
                                    {
                                        Id        = Guid.NewGuid(),
                                        OrderId   = o.Id,
                                        ProductId = products.Data.ElementAt(k).Id,
                                        Price     = products.Data.ElementAt(k).Price,
                                        Quantity  = k + 1
                                    });
                                }

                                newOrders.Add(o);
                            }
                        }
                    }

                    var orders = await OrderCore.CreateAsync(newOrders, true, new[] { nameof(Order.OrderItems) }).ConfigureAwait(false);

                    var payrolls = new List <Payroll>();
                    if (orders.Data.Count > 3)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            var payroll = new Payroll()
                            {
                                Id       = Guid.NewGuid(),
                                ClientId = clients.Data.ElementAt(i).Id,
                                OrderId  = orders.Data.ElementAt(i).Id,
                                Date     = DateTime.Now.AddDays(-i),
                                Value    = orders.Data.ElementAt(i).OrderItems.Sum(p => p.Price * p.Quantity),
                            };

                            payrolls.Add(payroll);
                        }
                    }

                    await PayrollCore.CreateAsync(payrolls, true).ConfigureAwait(false);
                }).ConfigureAwait(false).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                // ignored
            }
        }