public async Task <IActionResult> Remove(RemoveViewModel model) { var idm = await _repository.GetIDMByGuid(model.Guid); if (idm == null) { return(BadRequest()); } var currentUser = await _userManager.GetUserAsync(HttpContext.User); if (currentUser.HomeId == null) { return(BadRequest()); } var home = await _repository.GetHomeById(currentUser.HomeId); if (home.IDMs.All(x => x.Id != model.Guid)) { return(BadRequest()); } await _mqttService.PublishRemoveIDMCommand(idm.Id); home.IDMs.Remove(idm); _repository.RemoveIdm(idm); await _repository.Commit(); return(Ok()); }