public IActionResult PostComputer([FromBody] Computer computer) { if (ModelState.IsValid) { db.Computers.Add(computer); db.SaveChanges(); return(new CreatedAtRouteResult("DbPost", new { id = computer.id }, computer)); } return(BadRequest(ModelState)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContex db) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); // Inicialización de Datos if (!db.Computers.Any()) { db.Computers.AddRange(new List <Computer>() { new Computer() { memory = 8, processor = 1, diskType = 1 }, new Computer() { memory = 8, processor = 2, diskType = 1 }, new Computer() { memory = 8, processor = 3, diskType = 1 }, new Computer() { memory = 8, processor = 4, diskType = 1 } }); db.SaveChanges(); } }
public void Create(User user) { ApplicationDbContex db = new ApplicationDbContex(); db.Users.Add(user); db.SaveChanges(); }