Hey (1st time posting here so I may break some rules, tell me if I do),
I'm trying to create a Rest API and I have some problems with. In fact, the post function is not triggered on the C# API and I don't know why while the GET function used with a getAll() function is running good.
Angular Service :
public GetAll = (): Observable<Expertise[]> => {
return this.http.get(this.actionUrl, '').map((response: Response) => <Expertise[]>response.json());
}
public Add = (thingToAdd: Expertise): Observable<Expertise> => {
thingToAdd.Id = 1;
let toAdd = JSON.stringify(thingToAdd);
console.log(toAdd);
console.log(this.actionUrl);
return this.http.post(this.actionUrl, toAdd, { headers: this.headers
}).map((response: Response) => response.json());
}
C# API :
// GET api/values
[HttpGet]
public async Task<IEnumerable<Expertise>> Get()
{
try
{
System.Console.WriteLine("Test get all");
//var result = await cvService.Get("toto@azeo.com");
return new List<Expertise>();
}
catch (System.Exception ex)
{
logger.LogError(ex.Message, ex);
throw;
}
}
// POST api/values
[HttpPost]
public Expertise Post([FromBody]Expertise expertise)
{
try
{
System.Console.WriteLine("Test post");
context.Expertises.Add(expertise);
context.SaveChanges();
logger.LogInformation("New expertise added !");
return expertise;
}
catch (System.Exception ex)
{
logger.LogError(ex.Message, ex);
throw;
}
}
Expertise (EF model) :
public class Expertise
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public ICollection<ExpCV> CVs { get; set; }
}
If anyone has an idea to "link" the service and my API tell me, I'm stuck on it for a since a long time.
Thank you in advance