コード例 #1
0
        public static void Initialize(AngularTodoContext context)
        {
            context.Database.EnsureCreated();

            // Look for any todos
            if (context.Todos.Any())
            {
                return; // DB has been seeded
            }

            var todos = new Todos[]
            {
                new Todos {
                    Id = 1, Name = "pick up mom from airport"
                },
                new Todos {
                    Id = 2, Name = "get groceries"
                },
                new Todos {
                    Id = 3, Name = "walk doggo"
                },
                new Todos {
                    Id = 4, Name = "buy bread"
                }
            };

            foreach (Todos todo in todos)
            {
                context.Todos.Add(todo);
            }
            context.SaveChanges();
        }
コード例 #2
0
        public IActionResult Add(Todos todo)
        {
            if (ModelState.IsValid)
            {
                _context.Todos.Add(todo);
                _context.SaveChanges();

                return(StatusCode(200));
            }

            return(StatusCode(400));
        }