Esempio n. 1
0
        public async Task <IActionResult> AddTicket([FromBody] TicketView tv)
        {
            var oper = await _userManager.GetUserAsync(User);

            BusinessPoint bp = await _ctx.BusinessPoints
                               .Include(p => p.Owner)
                               .Where(p => p.Id == tv.BusinessPointId)
                               .SingleOrDefaultAsync();

            Ticket t = new Ticket {
                OperationDate = DateTime.Now, Amount = tv.Amount, Operator = oper, BusinessPoint = bp
            };

            _ctx.Tickets.Add(t);
            var result = await _ctx.SaveChangesAsync();

            if (result > 0)
            {
                decimal Amount = await _ctx.Tickets.Where(tt => tt.BusinessPoint.Id == bp.Id && tt.OperationDate.ToShortDateString() == DateTime.Now.ToShortDateString())
                                 .SumAsync(tt => tt.Amount);

                await _sc.GetChannel(bp.Owner.UserName).Writer.WriteAsync(new BusinessPointStats {
                    BusinessPointId = bp.Id, TotalAmount = Amount
                });

                return(CreatedAtAction(nameof(Get), new { id = t.Id }, tv));
            }
            return(BadRequest(tv));
        }
Esempio n. 2
0
 public ChannelReader <BusinessPointStats> Stats()
 {
     return(_sc.GetChannel(Context.User.Identity.Name));
 }