public async Task <IHttpActionResult> Get() { try { var productsResponse = await ProductCore.GetAllAsync().ConfigureAwait(false); var ordersResponse = await OrderCore.GetAllAsync().ConfigureAwait(false); var orderItemsResponse = await OrderItemCore.GetAllAsync().ConfigureAwait(false); var clientsResponse = await ClientCore.GetAllAsync().ConfigureAwait(false); var paymentsResponse = await PayrollCore.GetAllAsync().ConfigureAwait(false); if (!productsResponse.Success || !orderItemsResponse.Success || !orderItemsResponse.Success || !clientsResponse.Success || !paymentsResponse.Success) { return(Ok(ResponseFactory.CreateResponse(false, ResponseCode.Error))); } var totalIncomeValue = paymentsResponse.Data.Sum(payment => payment.Value); var totalOrdersValue = orderItemsResponse.Data.Sum(orderItem => orderItem.Price * orderItem.Quantity); var model = new SummaryModel { NumberOfClients = clientsResponse.Data.Count, NumberOfOrders = ordersResponse.Data.Count, NumberOfPayments = paymentsResponse.Data.Count, NumberOfProducts = productsResponse.Data.Count, TotalIncomeValue = totalIncomeValue, TotalOrdersValue = totalOrdersValue }; return(Ok(ResponseFactory <SummaryModel> .CreateResponse(true, ResponseCode.Success, model))); } catch (Exception e) { LogHelper.LogException <SummaryController>(e); return(Ok(ResponseFactory <SummaryModel> .CreateResponse(false, ResponseCode.Error))); } }
public async Task <IHttpActionResult> GetAll(string orderBy = "", bool orderAscending = true) { try { var response = await OrderCore.GetAllAsync(orderBy, orderAscending, new[] { nameof(Order.Client), nameof(Order.OrderItems), $"{nameof(Order.OrderItems)}.{nameof(OrderItem.Product)}", $"{nameof(Order.OrderItems)}.{nameof(OrderItem.Product)}.{nameof(Product.ValueAddedTax)}", nameof(Order.Payrolls), nameof(Order.Currency) }).ConfigureAwait(false); return(Ok(response)); } catch (Exception e) { LogHelper.LogException <OrderController>(e); return(Ok(ResponseFactory <IList <Order> > .CreateResponse(false, ResponseCode.Error))); } }
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 } }