private bool IsHaveProduct(string nameProduct) { using (var context = new WarehouseContext()) { foreach (var product in context.Products) { if (product.Name == nameProduct) { return(true); } } } return(false); }
private void ButtonYes_Click(object sender, EventArgs e) { var product = InitProduct(); if (product == null) { return; } using (var context = new WarehouseContext()) { context.Products.Add(product); context.SaveChanges(); } MessageBox.Show("Product successfully added"); Close(); }
public MainForm() { InitializeComponent(); warehouseDb = new WarehouseContext(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, WarehouseContext context) { // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseIdentityServer(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); app.UseSpa(spa => { spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseReactDevelopmentServer(npmScript: "start"); } }); ApplyMigrations(context); CreateRoles(serviceProvider).Wait(); }