Esempio n. 1
0
        public IActionResult Create([FromBody] TodoItem item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            _dbContext.TodoItems.Add(item);
            _dbContext.SaveChanges();

            return(CreatedAtRoute("GetTodo", new { id = item.Id }, item));
        }
Esempio n. 2
0
 public TodoController(ApiDbcontext dbContext)
 {
     _dbContext = dbContext;
     if (!_dbContext.TodoItems.Any())
     {
         _dbContext.TodoItems.Add(new TodoItem {
             Name = "Item1"
         });
         _dbContext.SaveChanges();
     }
 }
Esempio n. 3
0
        private static IDictionary <string, string> CreateAndSaveDefaultValues(
            ApiDbcontext dbContext)
        {
            var configValues = new Dictionary <string, string>
            {
                { "key1", "value_from_ef_1" },
                { "key2", "value_from_ef_2" }
            };

            dbContext.ConfigurationValues.AddRange(configValues
                                                   .Select(kvp => new ConfigurationValue {
                Id = kvp.Key, Value = kvp.Value
            })
                                                   .ToArray());
            dbContext.SaveChanges();
            return(configValues);
        }