public CarrinhoItem Ler(int id) { using (var context = new pdvContext()) { return(context.CarrinhoItems.Where(o => o.Id == id).SingleOrDefault()); } }
// 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(); } }
public List <Carrinho> Listar(int id) { using (var context = new pdvContext()) { return((from ci in context.Carrinhos //where ci.Id == id select ci).ToList()); } }
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(); }
public void Gravar(CarrinhoItem carrinhoItem) { try { using (var context = new pdvContext()) { context.Add(carrinhoItem); context.SaveChanges(); } } catch (Exception) { // } }
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()); } }
public CarrinhoController(pdvContext context, CarrinhoAccess cAccess, CarrinhoItemAccess ciAccess) { _context = context; this.carrinhoAccess = cAccess; this.carrinhoItemAccess = ciAccess; }