In my app, I am making a http.post request and getting back a value of 'gradeS'. Now I wanted to use this value of gradeS as parameter to make another cascaded call and fetch some list of names. I'll post the code I have written so far --
1. my first call [originally]
this.http.post('api/SampleData/CustomerGradeByID', JSON.stringify(body), { headers: _Headers })
.subscribe((result: any) =>
{
this.gradeS = result.json() as any[]
},
(error: any)=>console.error(error))
2. my service function
export class CommListService {
endPoint: string;
constructor(private http: Http) {
this.endPoint = "/api/SampleData/MakeCommunicationList";
}
GetfacilityNames(grade: string): Observable<Communication[]> {
var body = grade;
var _Headers = new Headers();
_Headers.append('Content-Type', 'application/json');
var commList = this.http.post(this.endPoint, JSON.stringify(body))
.map((r: Response) => {
return (r.json().length != 0 ? r.json() : [{"facility_name": "No Record Found" }]) as Communication[]
});
return commList;
}
}
3. my model class
export interface ICommunication {
facility_name: string;
}
export class Communication implements ICommunication {
facility_name: string;
}
4. how I tried to merge
this.http.post('api/SampleData/CustomerGradeByID', JSON.stringify(body), { headers: _Headers })
.do(u => this.gradeS = u)
.flatMap(u => this.commu.GetfacilityNames(this.gradeS))
.subscribe(p => this.comms = p);
5. finally in my html
<ul>
<li *ngFor="let cm of comms">{{cm.facility_name}}</li>
</ul>
SO where did I go wrong? I am getting data from database. By running a stored procedure. Whats' with the 415 status? What does it mean in this context? Could there be something wrong in the server side C# code? I have a hunch that I could have written something wrong at the server side stuff the backend comprising of C# and MSSQL. Although I am not sure.
this is my C# code
public JsonResult MakeCommunicationList([FromBody]string grade)
{
var gId = _appDbContext.CustomerGrades.First(m => m.grade_name == grade);
try
{
var inpParam = new SqlParameter("gId", SqlDbType.BigInt) { Direction = ParameterDirection.Input };
var salesData = (_appDbContext.Database.ExecuteSqlCommand($"EXEC {"sp_GetCommunicationList"} @gId", inpParam));
return Json(salesData);
}
catch (Exception exp)
{
return Json(exp.GetBaseException());
}
}
and this is my SP
CREATE procedure [dbo].[sp_GetCommunicationList]
@gId bigint
as
begin
begin try
if exists (
Select * from tempdb..sysobjects Where id = object_id('tempdb.dbo.#temp')
)
DROP TABLE #temp
else
select facility_name
into #temp
from Facilities ff
join
GradeFacilities gf
on
gf.facility_id=ff.Id
where
grade_id=@gId
-- select * into #temp from Orders where customer_id=@customer_id
end try
begin catch
select error_message(),
error_severity(),
error_number(),
error_state()
end catch
end
Please Help!! I am unable to figure this out!