If I understand correctly, the solution should be
$$\displaystyle u(x,t) = A_0+\sum_{n=1}^\infty A_n\; exp\left({\lambda_n \;t}\right) \cos ( \frac{ n \pi}{L}x)$$
with
$$\lambda_n=-\frac{-n^2 \pi ^2}{L^2}$$
for
$$u_t(x,t) - u_{xx}(x,t) = 0 \qquad \; ;0<x<L,\; t>0$$
and boundaries/initials (please check against your formulation):
\begin{align*}
u(x,0)=\phi(x) &\qquad \; ; 0<x<L\\
u_x(0,t) =0,\;\; u_x(L,t) = 0&\qquad \; ; t >0
\end{align*}
You need to pick $A_n$ such that $\phi(x)=u(x,0)$
To do this we consider what we learned from Fourier series. In particular we look for $u$
as an infinite sum
$$\displaystyle u(x,t) = A_0+\sum_{n=1}^\infty A_n\; exp\left({\lambda_n \;t}\right) \cos ( \frac{ n \pi}{L}x)$$
and find $\{A_n\}$ while satisfying:
$$\phi(x)=u(x,0)=A_0+\sum_{n=1}^\infty A_n\; \cos ( \frac{ n \pi}{L}x)$$
This requires a $cos$ expansion of $\phi(x)$ in the interval $[0,L]$, then we gain for your case $\phi(x)=x$:
$$A_0=(1/L) \int_0^L \phi(x)dx= (1/L) \int_0^L x dx$$
and
$$A_n=(2/L)\int_0^L \phi(x)\cos ( \frac{ n \pi}{L}x)dx=(2/L)\int_0^L x\cos ( \frac{ n \pi}{L}x)dx$$
Assuming $u(t,x)=T(t)X(x)$, the separated equations are
$$
\frac{T''}{c^2 T} = \lambda, \;\; \lambda = \frac{X''}{X}, \; X'(0)=X'(\pi)=0.
$$
The $X$ solutions dictate the values of $\lambda$ to be $-n^2$ for $n=1,2,3,\cdots$, and the corresponding eigenfunctions are unique up to multiplicative constants, and are given by
$$
X_n(x) = \cos(n x),\;\;\; n=0,1,2,3,\cdots.
$$
The general solution is
$$
u(x,t) = (A_0+B_0t)+\sum_{n=1}^{\infty}\left(A_n\cos(nc t)+B_n\sin(nc t)\right)\cos(n x).
$$
The constants $A_n,B_n$ are determined by the initial conditions:
$$
\cos(x) = u(x,0) = A_0+\sum_{n=1}^{\infty}A_n\cos(n x), \\
\cos^2(x) = u_{t}(x,0) = B_0+\sum_{n=1}^{\infty}nc B_n\cos(n x).
$$
The mutual orthogonality of the functions $\{ \cos(n\pi x) \}_{n=0}^{\infty}$ in $L^2[0,\pi]$ is used to determine the coefficients $A_n$ and $B_n$ in the usual manner of Fourier, which is simplified after applying the identity
$$
\cos^2(x) = \frac{1+\cos(2x)}{2}.
$$
Best Answer
Compute the initial conditions for the series and we see:
$u(0,t)=u(1,t)=0$ (due to the $\sin(\frac{n\pi}{L}x)$)
And $u_x(x,t)=\sum_{n=1}^\infty(A_n\sin(\frac{cn\pi t}{L})+B_n\cos(\frac{cn\pi t}{L}))\frac{n\pi}{L}\cos(\frac{n\pi x}{L})$
Here $u_x(0,t)=\sum_{n=1}^\infty(A_n\sin(\frac{cn\pi t}{L})+B_n\cos(\frac{cn\pi t}{L}))\frac{n\pi}{L}=0$
And $u_x(1,t)=\sum_{n=1}^\infty(-1)^n(A_n\sin(\frac{cn\pi t}{L})+B_n\cos(\frac{cn\pi t}{L}))\frac{n\pi}{L}=0$
This would impose on the values of $A_n,B_n$, the problem is that the change of initial/ boundary conditions changes the calculation of the form of the solution.
The general solution is found by solving:
$X''=-\lambda X$ for different choices of $\lambda$, i.e. $\lambda\lt 0,\lambda = 0\lambda,\gt 0$. With respect to the boundary conditions, so if those change, then the form of the (series) solution changes.