public async Task <ActionResult <DeviceIndex> > Post(DeviceCreate viewModel) { var model = mapper.Map <Device>(viewModel); model.IsConnected = false; await sqlService.AddAsync(model); var deviceToReturn = mapper.Map <DeviceIndex>(model); return(CreatedAtRoute("Device", new { Id = deviceToReturn.Id }, deviceToReturn)); }
public async Task <IActionResult> Create(DeviceCreate viewModel) { var model = mapper.Map <Device>(viewModel); //model.UserId = userManager.GetUserId(User); model.IsConnected = false; if (ModelState.IsValid) { await sqlService.AddAsync(model); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }