Exemplo n.º 1
0
        public IActionResult Delete(string id)
        {
            var device = _context.Device.FirstOrDefault(d => d.Id == id);

            if (device != null)
            {
                _context.Device.Remove(device);
                _context.SaveChanges();
            }

            var model = GetModel();

            return(View("Dashboard", model));
        }
 public JsonResult RegisterDevice([FromBody] Device device)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(new JsonResult(BadRequest(device)));
         }
         _context.Device.Add(device);
         _context.SaveChanges();
         return(new JsonResult($"{{result: {true}}}"));
     }
     catch (Exception ex)
     {
         return(new JsonResult($"{{result: {false}, message: {ex.Message}, innerException: {ex.InnerException?.Message}}}"));
     }
 }