'make a Put http request with Angular12 and ASP.NET Core REST API (example: reset notification count)
This is the service in angular : I get the OnlineUser from the component, here i can't connect to APi :
private baseUrlRemoveNotifications: string =
"api/v1.0/UploadDownload/removeNotifications";
public removeNotificationForUser(onlineUserModel: OnlineUserModel) {
let username = onlineUserModel.userName;
console.log("send remove.............");
const url = `${this.baseUrlRemoveNotifications}`;
const options = {
headers: new HttpHeaders({
"Content-Type": "application/json",
}),
};
return this.http.put(
`${this.baseUrlRemoveNotifications}`,
username,
options
);
}
My API in .Net core When i debugger i can't reach the api is here some mistakes... if possible how can i remove the result from the reducer to update the state of notification and thank you ...
[HttpPut("[action]")]
[Route("removeNotifications")]
public async Task<IActionResult> RemoveNotifications([FromBody] string username)
{
try
{
var sender = await _userManager.FindByNameAsync(username);
var reciever = await _userManager.FindByNameAsync(User.Identity.Name);
// My Methode to update Notification Table => change Iseen column to true //
return Ok("Success");
}
catch (Exception ex)
{
Log.Error("An error occurred while seeding the database {Error} {StackTrace} {InnerException} {Source}",
ex.Message, ex.StackTrace, ex.InnerException, ex.Source);
}
return BadRequest("Failed");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
