Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Queue")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ticket);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ticket));
        }
Ejemplo n.º 2
0
        public async Task <Ticket> AddAsync(Ticket ticket)
        {
            _ = ticket ?? throw new ArgumentNullException(nameof(ticket));

            try
            {
                int cola1 = _context.Ticket.Where(w => w.Queue == 1).Count() + 1 * 2;
                int cola2 = _context.Ticket.Where(w => w.Queue == 2).Count() + 1 * 3;

                await _context.Ticket.AddAsync(new Ticket
                {
                    Name  = ticket.Name,
                    Queue = cola1 > cola2 ? 2 : 1,
                });

                await _context.SaveChangesAsync();

                return(ticket);
            }
            catch (Exception)
            {
                throw;
            }
        }