An error message is popping up that says: '{"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'Fromdate' of non-nullable type 'System.DateTime' for method 'System.Net.Http.HttpResponseMessage CustomerWiseQuotationHistory(Int64, System.String, System.DateTime, System.DateTime)' in 'shenoyapi.Controllers.ReportController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."}'
Here is the Component.ts code:
validate(): boolean {
this.appErrors = [];
if (this.objProductQuotationHistory.ProductName=='') {
this.appErrors.push({ Title: 'Select Product Name.' });
}
if (this.objProductQuotationHistory.FromDate > this.objProductQuotationHistory.ToDate) {
this.appErrors.push({ Title: 'From Date date cannot be greater than To Date.' });
}
if (this.appErrors.length > 0) {
return false;
}
else {
return true;
}
}
print(type: string ): void {
if (!this.validate()) {
const dialogRef = this.dialog.open(AlertdialogComponent, { data: this.appErrors });
return;
}
And here is the services.ts code:
getProductHistory(productId: number,FromDate: Date,ToDate:Date): Observable<number>{
let f = moment(FromDate);
let fromdate = f.format('YYYY-MM-DD');
let t = moment(ToDate);
let todate = t.format('YYYY-MM-DD');
return this.http.get<number>(AppConfig.BASE_API_URL +'/api/report/productwisequotationhistoryreport/' + productId + '/' + fromdate + '/' + todate);
}
This snippet shows the API:
[Route("api/report/productwisequotationhistoryreport/{id}/{type}/{Fromdate}/{ToDate}")]
[HttpGet]
public HttpResponseMessage ProductrWiseQuotationHistory(long id, string type, DateTime Fromdate, DateTime ToDate)
{
try
{
// Code block for processing and generating report
return response;
}
catch (Exception ee)
{
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, ee.Message));
}