Add chapter number before section number at TOC in amsbook

amsbooktable of contents

In amsbook class, at the TOC, and also in the text, I want to add the chapter number, with a dot, before the sections numbers (and also to remove the dot at the end of the sections numbers), as in the pictures below.

\documentclass[12pt]{amsbook}
\usepackage{amsfonts,amsmath}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}

\begin{document}
\tableofcontents

\chapter{Title of the first chapter}

\section{Title of the first section}
wsdqwewqgtewhtrdjnyedty

\section{Title of the second section}
wsdqwewqgtewhtrdjnyedty

\chapter{Title of the second chapter}

\section{Title of the first section}
wsdqwewqgtewhtrdjnyedty

\section{Title of the second section}
wsdqwewqgtewhtrdjnyedty

\end{document}

How can I do this? Any help will be appreciated.
enter image description here
enter image description here

Best Answer

\documentclass{amsbook}
\renewcommand{\thesection}{\thechapter.\arabic{section}}
\makeatletter
\def\@seccntformat#1{%
  \protect\textup{\protect\@secnumfont
    \csname the#1\endcsname\enspace
  }%
}
\renewcommand{\tocsection}[3]{%
  \indentlabel{\@ifnotempty{#2}{\ignorespaces#1 #2\quad}}#3}
\makeatother
\begin{document}

\tableofcontents

\chapter{Title of the first chapter}

\section{Title of the first section}
wsdqwewqgtewhtrdjnyedty

\section{Title of the second section}
wsdqwewqgtewhtrdjnyedty

\chapter{Title of the second chapter}

\section{Title of the first section}
wsdqwewqgtewhtrdjnyedty

\section{Title of the second section}
wsdqwewqgtewhtrdjnyedty
\end{document}

enter image description here