public Task UpdateValue(OrdersStats value)
        {
            // update the state
            _state = _state.NextVersion(value);
            _logger.LogInformation("{@GrainType} {@GrainKey} updated value to {@Value} with version {@Version}",
                                   GrainType, GrainKey, _state.Value, _state.Version);

            // fulfill waiting promises
            _wait.SetResult(_state);
            _wait = new TaskCompletionSource <VersionedValue <OrdersStats> >();

            return(Task.CompletedTask);
        }
        private async Task UpdateStatsAsync()
        {
            int orders             = State.Orders.Count;
            int ordersNotDipatched = State.OrdersNotDispatched.Count;

            // update the stats state
            var value = new OrdersStats {
                Orders = orders, OrdersNotDispatched = ordersNotDipatched
            };

            _logger.LogInformation("{@GrainType} {@GrainKey} updating value to {@Value}", GrainType, GrainKey, value);

            await GrainFactory.GetGrain <IOrdersStatsProducer>(Guid.Empty).UpdateValue(value);
        }
        public async Task <ActionResult <OrdersStats> > GetOrders(int year)
        {
            var ordersOfYear = await _context.Orders.Include(o => o.OrderDetail).Where(o => o.OrderDate.Year == year).ToListAsync();

            var orderStats = new OrdersStats
            {
                OrdersCount   = ordersOfYear.Count(),
                ProductsCount = 0,
                Revenues      = 0
            };

            foreach (var order in ordersOfYear)
            {
                orderStats.ProductsCount += order.OrderDetail.Sum(od => od.Quantity);
                orderStats.Revenues      += order.OrderDetail.Sum(od => od.Quantity * od.UnitPrice * (1 - (decimal)od.Discount));
            }

            return(orderStats);
        }
        public ActionResult <OrdersStats> GetStats(int year)
        {
            OrdersStats stats = new OrdersStats();

            // On récupère les commandes de l'année passée en paramètre
            var orders = _context.Orders.Where(o => o.OrderDate.Year == year).Include(o => o.OrderDetail).ToList();

            // On calcule le nombre d'articles commandés et le CA généré par ces commandes
            double revenues  = 0d;
            int    prodCount = 0;

            foreach (var o in orders)
            {
                prodCount += o.OrderDetail.Sum(od => od.Quantity);
                revenues  += o.OrderDetail.Sum(od => (float)od.Quantity * (float)od.UnitPrice * (1.0 - od.Discount));
            }

            stats.OrdersCount   = orders.Count();       // Nombre de commandes pour l'année
            stats.ProductsCount = prodCount;            // Nombre d'articles commandés
            stats.Revenues      = Math.Round(revenues); // CA réalisé

            return(stats);
        }
示例#5
0
 public OrdersStatsViewModel(OrdersStats stats)
 {
     All           = stats.Orders;
     NotDispatched = stats.OrdersNotDispatched;
 }