Beispiel #1
0
        private static void CreateClient()
        {
            mClient            = EntityHelper.GenerateClient();
            mClient.CurrencyId = mCurrency.Id;

            var response = ClientCore.CreateAsync(mClient, true).ConfigureAwait(false).GetAwaiter().GetResult();

            AssertObjects(response, mClient);
        }
Beispiel #2
0
        public async Task <IHttpActionResult> Create([FromBody] Client client)
        {
            try
            {
                var response = await ClientCore.CreateAsync(client).ConfigureAwait(false);

                return(Json(response));
            }
            catch (Exception e)
            {
                LogHelper.LogException <ClientController>(e);

                return(Ok(ResponseFactory.CreateResponse(false, ResponseCode.Error)));
            }
        }
Beispiel #3
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
            }
        }