@ -89,11 +89,11 @@ namespace Yavsc.ApiControllers
/// <returns>The estim tex.</returns>
/// <returns>The estim tex.</returns>
/// <param name="estimid">Estimid.</param>
/// <param name="estimid">Estimid.</param>
[AcceptVerbs ("GET")]
[AcceptVerbs ("GET")]
public HttpResponseMessage Get EstimTex ( long estimid )
public HttpResponseMessage EstimateTo Tex ( long estimid )
{
{
string texest = null ;
string texest = null ;
try {
try {
texest = g etE stimTex ( estimid ) ;
texest = estimateTo Tex ( estimid ) ;
} catch ( TemplateException ex ) {
} catch ( TemplateException ex ) {
return new HttpResponseMessage ( HttpStatusCode . OK ) { Content =
return new HttpResponseMessage ( HttpStatusCode . OK ) { Content =
new ObjectContent ( typeof ( string ) ,
new ObjectContent ( typeof ( string ) ,
@ -102,16 +102,17 @@ namespace Yavsc.ApiControllers
) )
) )
} ;
} ;
} catch ( Exception ex ) {
} catch ( Exception ex ) {
return new HttpResponseMessage ( HttpStatusCode . OK ) { Content =
return new HttpResponseMessage ( HttpStatusCode . OK ) { Content =
new ObjectContent ( typeof ( string ) ,
new ObjectContent ( typeof ( string ) ,
ex . Message , new SimpleFormatter ( "text/text" ) )
ex . Message , new ErrorHtmlFormatter ( HttpStatusCode . InternalServerError ,
LocalizedText . DocTemplateException ) )
} ;
} ;
}
}
if ( texest = = null )
if ( texest = = null )
return new HttpResponseMessage ( HttpStatusCode . OK ) { Content =
return new HttpResponseMessage ( HttpStatusCode . OK ) { Content =
new ObjectContent ( typeof ( string ) ,
new ObjectContent ( typeof ( string ) , "Not an estimation id:" + estimid ,
"Not an estimation id:" + estimid , new SimpleFormatter ( "text/text" ) )
new ErrorHtmlFormatter ( HttpStatusCode . NotFound ,
LocalizedText . Estimate_not_found ) )
} ;
} ;
return new HttpResponseMessage ( ) {
return new HttpResponseMessage ( ) {
@ -121,7 +122,7 @@ namespace Yavsc.ApiControllers
} ;
} ;
}
}
private string g etE stimTex ( long estimid )
private string estimateTo Tex ( long estimid )
{
{
Yavsc . templates . Estim tmpe = new Yavsc . templates . Estim ( ) ;
Yavsc . templates . Estim tmpe = new Yavsc . templates . Estim ( ) ;
Estimate e = wfmgr . GetEstimate ( estimid ) ;
Estimate e = wfmgr . GetEstimate ( estimid ) ;
@ -141,22 +142,42 @@ namespace Yavsc.ApiControllers
return tmpe . TransformText ( ) ;
return tmpe . TransformText ( ) ;
}
}
/// <summary>
/// <summary>
/// Gets the estimate in pdf format from tex generation.
/// Gets the estimate in pdf format from tex generation.
/// </summary>
/// </summary>
/// <returns>The estim pdf.</returns>
/// <returns>The to pdf.</returns>
/// <param name="estimid">Estimid.</param>
/// <param name="estimid">Estimid.</param>
public HttpResponseMessage GetEstimPdf ( long estimid )
[AcceptVerbs("GET")]
public HttpResponseMessage EstimateToPdf ( long estimid )
{
{
Estimate estim = wfmgr . GetEstimate ( estimid ) ;
string texest = null ;
//TODO better with pro.IsBankable && cli.IsBillable
try {
texest = estimateToTex ( estimid ) ;
} catch ( TemplateException ex ) {
return new HttpResponseMessage ( HttpStatusCode . OK ) { Content =
new ObjectContent ( typeof ( string ) ,
ex . Message , new ErrorHtmlFormatter ( HttpStatusCode . NotAcceptable ,
LocalizedText . DocTemplateException
) )
} ;
} catch ( Exception ex ) {
return new HttpResponseMessage ( HttpStatusCode . OK ) { Content =
new ObjectContent ( typeof ( string ) ,
ex . Message , new ErrorHtmlFormatter ( HttpStatusCode . InternalServerError ,
LocalizedText . DocTemplateException ) )
} ;
}
if ( texest = = null )
return new HttpResponseMessage ( HttpStatusCode . OK ) { Content =
new ObjectContent ( typeof ( string ) , "Not an estimation id:" + estimid ,
new ErrorHtmlFormatter ( HttpStatusCode . NotFound ,
LocalizedText . Estimate_not_found ) )
} ;
return new HttpResponseMessage ( ) {
return new HttpResponseMessage ( ) {
Content = new ObjectContent (
Content = new ObjectContent ( typeof ( string ) ,
typeof ( Estimate ) ,
texest ,
estim ,
new TexToPdfFormatter ( ) )
new EstimToPdfFormatter ( ) )
} ;
} ;
}
}
}
}