Exemple #1
0
        static void Main(string[] args)
        {
            Lanchonete lanchonete = new Lanchonete("CJ Lanches");


            lanchonete.inserirLanche(new Lanche(1, "Cachorro quente", 3.00));
            lanchonete.inserirLanche(new Lanche(2, "X-Salada", 2.50));
            lanchonete.inserirLanche(new Lanche(3, "X-Bacon", 5.00));
            lanchonete.inserirLanche(new Lanche(4, "Torrada simples", 4.50));
            lanchonete.inserirLanche(new Lanche(5, "Refrigerante", 1.50));


            string leitura = Console.ReadLine();

            while (leitura != null)
            {
                string[] split      = leitura.Split(' ');
                int      id         = int.Parse(split[0]);
                int      quantidade = int.Parse(split[1]);
                Pedido   pedido     = new Pedido();
                try{
                    pedido.inserirLanche(lanchonete.getLanche(id), quantidade);
                    Console.WriteLine($"Total: R$ {pedido.getPrecoPedido()}");
                }catch {
                    Console.WriteLine("Lanche inválido");
                    Console.WriteLine("Tabela de lanches: ");
                    Console.WriteLine("Código | Nome | Preço");
                    foreach (KeyValuePair <int, Lanche> entry in lanchonete.getLanches())
                    {
                        Console.WriteLine(entry.Value);
                    }
                }
                leitura = Console.ReadLine();
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("LanchoneteId,Nome")] Lanchonete lanchonete)
        {
            if (id != lanchonete.LanchoneteId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(lanchonete);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LanchoneteExists(lanchonete.LanchoneteId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(lanchonete));
        }
 public void Inserir(Lanchonete lanchonete)
 {
     sb = new StringBuilder();
     sb.Append("INSERT INTO LANCHONETE (descricao, quantidade_clientes, numero_empregados, total_receita, total_despesa) VALUES ");
     sb.Append(string.Format("('{0}', '{1}', '{2}', '{3}', '{4}')", lanchonete.Descricao, lanchonete.QuantidadeClientes, lanchonete.NumeroEmpregados, lanchonete.TotalReceita, lanchonete.TotalDespesa));
     using (var conexao = new ConnectionSQLServer())
     {
         conexao.ExecutaComando(sb.ToString());
     }
 }
        public async Task <IActionResult> Create([Bind("LanchoneteId,Nome")] Lanchonete lanchonete)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lanchonete);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(lanchonete));
        }
        private List <Lanchonete> TransformaSQLReaderEmList(SqlDataReader retorno)
        {
            List <Lanchonete> lanchonetes = new List <Lanchonete>();

            while (retorno.Read())
            {
                var lanchonete = new Lanchonete()
                {
                    Id                 = int.Parse(retorno["id"].ToString()),
                    Descricao          = retorno["descricao"].ToString(),
                    QuantidadeClientes = int.Parse(retorno["quantidade_clientes"].ToString()),
                    NumeroEmpregados   = int.Parse(retorno["numero_empregados"].ToString()),
                    TotalReceita       = double.Parse(retorno["total_receita"].ToString()),
                    TotalDespesa       = double.Parse(retorno["total_despesa"].ToString()),
                };
                lanchonetes.Add(lanchonete);
            }
            return(lanchonetes);
        }