Sunday 20 October 2019

c# - Service can't reach post function

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 => {
return this.http.get(this.actionUrl, '').map((response: Response) => response.json());
}
public Add = (thingToAdd: Expertise): Observable => {
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> Get()
{
try
{
System.Console.WriteLine("Test get all");
//var result = await cvService.Get("toto@azeo.com");
return new List();
}
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 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

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...