Пример #1
0
        public async Task <IActionResult> Remove(RemoveViewModel model)
        {
            var dlm = await _repository.GetDLMByGuid(model.Guid);

            if (dlm == 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.DLMs.All(x => x.Id != model.Guid))
            {
                return(BadRequest());
            }

            await _mqttService.PublishRemoveDLMCommand(dlm.Id);

            home.DLMs.Remove(dlm);

            _repository.RemoveDlm(dlm);

            await _repository.Commit();

            return(Ok());
        }