Beispiel #1
0
        public IActionResult BorrarTicket(IndexViewModel model)
        {
            using (ticketDBContext db = new ticketDBContext())
            {
                lista = (from d in db.Colas
                         where d.Cola == model.cola
                         select new ColaViewModel
                {
                    id = d.Id,
                    cola = d.Cola.Value,
                    ticket_id = d.TicketId.Value
                }
                         ).ToList();
                if (lista.Count > 0)
                {
                    ColaViewModel primerTicket = lista.ElementAt(0);
                    Colas         primeroCola  = new Colas();

                    primeroCola.Id       = primerTicket.id;
                    primeroCola.Cola     = primerTicket.cola;
                    primeroCola.TicketId = primerTicket.ticket_id;

                    db.Colas.Remove(primeroCola);
                    db.SaveChanges();
                }

                lista = (from d in db.Colas
                         join t in db.Ticket
                         on d.TicketId equals t.Id
                         where d.Cola == 1
                         select new ColaViewModel
                {
                    id = d.Id,
                    cola = d.Cola.Value,
                    ticket_id = d.TicketId.Value,
                    nombre = t.Nombre
                }
                         ).ToList();

                lista2 = (from d in db.Colas
                          join t in db.Ticket
                          on d.TicketId equals t.Id
                          where d.Cola == 2
                          select new ColaViewModel
                {
                    id = d.Id,
                    cola = d.Cola.Value,
                    ticket_id = d.TicketId.Value,
                    nombre = t.Nombre
                }
                          ).ToList();
            }
            model.cola1 = lista;
            model.cola2 = lista2;


            return(PartialView("_ListaCola", model));
        }
Beispiel #2
0
 public override string ToString()
 {
     return(new StringBuilder()
            .AppendLine("Drinks")
            .AppendLine($"-Cola {Colas.Display(2)}")
            .AppendLine($"-Beer {Beers.Display(2)}")
            .AppendLine($"-Other {Other.Display(2)}")
            .ToString());
 }
Beispiel #3
0
        public IActionResult CrearTicket(IndexViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int cola = 1;
                    //Se calcula el tiempo de espera de cada cola.
                    int tCola1 = tiempoCola(1, 2);
                    int tCola2 = tiempoCola(2, 3);

                    if (tCola1 <= tCola2)
                    {
                        cola = 1;
                    }
                    else
                    {
                        cola = 2;
                    }

                    using (ticketDBContext db = new ticketDBContext())
                    {
                        var oTicket = new Ticket();
                        oTicket.Id     = model.ticket_id;
                        oTicket.Nombre = model.nombre;
                        if (db.Ticket.Find(oTicket.Id) == null)
                        {
                            db.Ticket.Add(oTicket);
                            db.SaveChanges();
                        }



                        var oCola = new Colas();
                        oCola.Cola     = cola;
                        oCola.TicketId = oTicket.Id;
                        db.Colas.Add(oCola);
                        db.SaveChanges();


                        lista = (from d in db.Colas
                                 join t in db.Ticket
                                 on d.TicketId equals t.Id
                                 where d.Cola == 1
                                 select new ColaViewModel
                        {
                            id = d.Id,
                            cola = d.Cola.Value,
                            ticket_id = d.TicketId.Value,
                            nombre = t.Nombre
                        }
                                 ).ToList();

                        lista2 = (from d in db.Colas
                                  join t in db.Ticket
                                  on d.TicketId equals t.Id
                                  where d.Cola == 2
                                  select new ColaViewModel
                        {
                            id = d.Id,
                            cola = d.Cola.Value,
                            ticket_id = d.TicketId.Value,
                            nombre = t.Nombre
                        }
                                  ).ToList();
                    }
                    model.cola1 = lista;
                    model.cola2 = lista2;

                    return(PartialView("_ListaCola", model));
                }

                return(null);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.InnerException.Message);
            }

            return(null);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Colas  cola = new Colas();
            int    max;
            int    opcion;
            string e;
            string ebusqueda;

            Menu();
            Console.WriteLine("Presione una tecla para continuar");
            Console.ReadKey();

            void Menu()
            {
                Console.WriteLine("MENU COLAS" + '\n');
                Console.WriteLine("1. Crear Cola");
                Console.WriteLine("2. Insertar Datos");
                Console.WriteLine("3. Eliminar Datos");
                Console.WriteLine("4. Recorrer la Cola");
                Console.WriteLine("5. Buscar elementos");
                Console.WriteLine("6. Salir");
                Console.Write('\n' + "Seleccione una opcion: ");
                opcion = int.Parse(Console.ReadLine());
                switch (opcion)
                {
                case 1:
                    opcion = 1;
                    {
                        Console.Clear();
                        Console.Write("Ingrese el tamaño de la cola: ");
                        max  = int.Parse(Console.ReadLine());
                        cola = new Colas(max);
                        Console.WriteLine("Cola creada exitosamente" + '\n');
                        Menu();
                        break;
                    }

                case 2:
                    opcion = 2;
                    {
                        Console.Clear();
                        Console.Write("Ingrese un dato para insertar en la pila: ");
                        e = Console.ReadLine();
                        cola.Push(e);
                        Console.WriteLine("Elemento agregado a la cola" + '\n');
                        Menu();
                        break;
                    }

                case 3:
                    opcion = 3;
                    {
                        Console.Clear();
                        cola.Pop();
                        Menu();
                        break;
                    }

                case 4:
                    opcion = 4;
                    {
                        Console.Clear();
                        cola.Recorrido();
                        Console.WriteLine('\n');
                        Menu();
                        break;
                    }

                case 5:
                    opcion = 5;
                    {
                        Console.Clear();
                        Console.Write("Ingrese un valor a buscar: ");
                        ebusqueda = Console.ReadLine();
                        cola.Busqueda(ebusqueda);
                        Console.WriteLine('\n');
                        Menu();
                        break;
                    }

                case 6:
                    opcion = 6;
                    {
                        Console.Clear();
                        break;
                    }
                }
            }
        }