public async Task <IActionResult> Create([Bind("Id,AccessToken,Name,Description,Location,IPv4Address,MacAddress")] Device device) { if (ModelState.IsValid) { _context.Add(device); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(device)); }
public async Task <IActionResult> PutDevice([FromRoute] int id, [FromBody] UpdateDeviceDto dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dto.Id) { return(BadRequest()); } var device = await _context.FindAsync <Device>(dto.Id); device = dto.Adapt(device); device.IPv4Address = Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); _context.Entry(device).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DeviceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }