I have a c# WEB API using Entity Framework - I am trying to make a put request through my angular front end to simulate a 'checkin' function but the request isn't going through.
Here is my Web api method
[HttpPut("checkin/{id}")]
[AuthorizeRoles(Role.Administrator, Role.User)]
public async Task<IActionResult> CheckIn(int id)
{
var reservation = await context.Reservations.FindAsync(id);
var username = User.Identity.Name;
if (reservation == null)
return NotFound();
// Ensure user is checking-in their own reservation and its not already checked-in
if (reservation.UserName == username && reservation.CheckInDate == null)
{
reservation.CheckInDate = DateTime.Now;
var count = await context.SaveChangesAsync();
if (count < 1)
return StatusCode((int)HttpStatusCode.InternalServerError);
}
return Ok();
}
Here is my two .ts files where the request is being initiated -note: in the second method I decided to pass the ID manually for testing purposes
-checkIn(id: number){
if (confirm('Would you like to check in')) {
this.reservationService.checki(7);
};
}
reservationservice.ts
checki(id: number) {
const headers = new Headers();
const url = `${this.url}+/checkin/${7}`;
return this.http
.put(url, JSON.stringify(7), {headers: headers})
.map(res => res.json());
}