示例#1
0
 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));
 }
示例#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, 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();
            }
        }
示例#3
0
 public void Create(User user)
 {
     ApplicationDbContex db = new ApplicationDbContex();
     db.Users.Add(user);
     db.SaveChanges();
 }