public TEntity Save(TEntity item) { TEntity savedEntity = item.Id == 0 ? Table.Add(item).Entity : Table.Update(item).Entity; _pizzaShopDbContext.SaveChanges(); return(savedEntity); }
public IActionResult MarkCompleted(int orderID) { Order order = context.Orders.FirstOrDefault(o => o.OrderID == orderID); if (order != null) { order.Completed = true; context.SaveChanges(); } return(RedirectToAction(nameof(List))); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { using (PizzaShopDbContext pizzaShopDbContext = app.ApplicationServices.CreateScope() .ServiceProvider.GetRequiredService <PizzaShopDbContext>()) { try { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); pizzaShopDbContext.Database.EnsureDeleted(); pizzaShopDbContext.Database.EnsureCreated(); pizzaShopDbContext.Add(new Customer { PhoneNumber = "1111111111", Password = "******", Name = "Surafel Assefa", Address = "White House", PaymentType = PaymentType.VisaCard, }); pizzaShopDbContext.SaveChanges(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); pizzaShopDbContext.Database.Migrate(); } } catch (PostgresException e) { throw e; } } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseSession(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); }
private void AddEntity <T>(T entity) { _pizzaShopDbContext.Add(entity); _pizzaShopDbContext.SaveChanges(); }