Beispiel #1
0
        public IActionResult Create([FromBody] LightsItem item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            _context.LightsItems.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetLights", new { id = item.Id }, item));
        }
Beispiel #2
0
 public LightsController(LightsContext context)
 {
     _context = context;
     if (_context.LightsItems.Count() == 0)
     {
         _context.LightsItems.Add(new LightsItem {
             Name = "Item1"
         });
         _context.SaveChanges();
     }
 }