Exemplo n.º 1
0
        public IHttpActionResult Post(SaleSystemNotification notification)
        {
            // run asynchronously to leave web request thread
            BackgroundJob.Enqueue <DefaultCounterProcessorAdapter>(p => p.Process(notification));

            return(StatusCode(HttpStatusCode.Accepted));
        }
Exemplo n.º 2
0
 public async Task Write(SaleSystemNotification notification)
 {
     await
     _conn.ExecuteAsync(
         "insert into Hit (Product, Filial, ContractSigningDate, Increment) values (@product, @filial, @signingdate, @increment)",
         new
     {
         product     = notification.Product,
         filial      = notification.Filial,
         signingdate = notification.ContractSigningDateTime,
         increment   = notification.Increment
     });
 }
Exemplo n.º 3
0
        public async Task ProcessAsync(SaleSystemNotification notification)
        {
            var periodKind  = PeriodKind.Daily;
            var counterKind = CounterKind.Total;
            var counter     = new Counter()
            {
                Product = notification.Product, PeriodKind = periodKind, PeriodStart = DateTimeOffset.Now.Date, Kind = counterKind
            };

            await _logger.Write(notification);

            var delta = notification.Increment ? 1 : -1;

            var savedCounter = await _storage.UpdateCounter(counter, delta);

            await _broadcaster.SendCounter(new CounterMessage
            {
                Product     = notification.Product,
                Value       = savedCounter.Value,
                PeriodStart = counter.PeriodStart.Date,
                Kind        = counterKind,
                PeriodKind  = periodKind
            });
        }
 public void Process(SaleSystemNotification notification)
 {
     ProcessAsync(notification).Wait();
 }