public IActionResult Delete(int id) { Rights _right = _rightsRepository.GetSingle(id); if (_right == null) { return(NotFound()); } else { IEnumerable <RightsToUser> _rightsToUser = _rightsToUserRepository.FindBy(r => r.IdRight == id); foreach (var rightToUser in _rightsToUser) { _rightsToUserRepository.Delete(rightToUser); } _rightsRepository.Delete(_right); _rightsRepository.Commit(); _rightsToUserRepository.Commit(); return(new NoContentResult()); } }