コード例 #1
0
 public CarrinhoItem Ler(int id)
 {
     using (var context = new pdvContext())
     {
         return(context.CarrinhoItems.Where(o => o.Id == id).SingleOrDefault());
     }
 }
コード例 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });


            //Banco de Dados
            using (var context = new pdvContext())
            {
                context.Database.Migrate();
                //context.InicializaDB();
            }
        }
コード例 #3
0
 public List <Carrinho> Listar(int id)
 {
     using (var context = new pdvContext())
     {
         return((from ci in context.Carrinhos
                 //where ci.Id == id
                 select ci).ToList());
     }
 }
コード例 #4
0
        static void Main(string[] args)
        {
            using (var context = new pdvContext())
            {
                //context.Database.EnsureCreated();
                context.Database.Migrate();
            }

            Console.WriteLine("Database!");

            Console.ReadKey();

            using (var context = new pdvContext())
            {
                var author = new Author
                {
                    FirstName = "William",
                    LastName  = "Shakespeare",
                    Books     = new List <Book>
                    {
                        new Book {
                            Title = "Hamlet"
                        },
                        new Book {
                            Title = "Othello"
                        },
                        new Book {
                            Title = "MacBeth"
                        }
                    }
                };
                context.Add(author);
                context.SaveChanges();
            }

            Console.WriteLine("Save!");

            Console.ReadKey();

            using (var context = new pdvContext())
            {
                foreach (var book in context.Books)
                {
                    Console.WriteLine(book.Title);
                }
            }

            Console.WriteLine("Lista!");

            Console.WriteLine("Hello World!");

            Console.ReadKey();
        }
コード例 #5
0
 public void Gravar(CarrinhoItem carrinhoItem)
 {
     try
     {
         using (var context = new pdvContext())
         {
             context.Add(carrinhoItem);
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         //
     }
 }
コード例 #6
0
 public List <CarrinhoItemViewModel> Listar(int idCarrinho)
 {
     using (var context = new pdvContext())
     {
         return((from ci in context.CarrinhoItems
                 where ci.Carrinho.Id == idCarrinho
                 select new CarrinhoItemViewModel
         {
             Id = ci.Id,
             Ordem = ci.Ordem,
             Nome = ci.Item.Nome,
             Quantidade = ci.Quantidade,
             Preco = ci.Preco,
             Desconto = ci.Desconto,
             Total = (ci.Quantidade * (ci.Preco - ci.Desconto))
         }).ToList());
     }
 }
コード例 #7
0
 public CarrinhoController(pdvContext context, CarrinhoAccess cAccess, CarrinhoItemAccess ciAccess)
 {
     _context                = context;
     this.carrinhoAccess     = cAccess;
     this.carrinhoItemAccess = ciAccess;
 }