I'm encountering a 400 error code and I'm struggling to pinpoint the issue. My attempts to find solutions online have been unsuccessful so far. Any assistance or insight would be greatly appreciated. Thank you.
The error message states: "The JSON value could not be converted to TheMoonshineCafe.Models.Event. Path: $ | LineNumber: 0 | BytePositionInLine: 1."
It appears that there may be an issue with converting the payload into the Event type correctly?
Here is the edit event function from my data service:
editEvent(id: Number, event: EventWithID[]){
var callResult : any;
console.log(id);
console.log(event);
this.http.put(this.baseUrl + 'api/Events/' + id, event).subscribe(result => {
callResult = result;
console.log(result);
})
}
This is the Put Event method from my API:
[HttpPut("{id}")]
public async Task<ActionResult<Event>> PutEvent(int id, Event @event)
{
if (id != @event.id)
{
return BadRequest();
}
_context.Entry(@event).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!EventExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
Payload structure:
export class EventWithID {
id: number;
eventStart: Date;
eventEnd: Date;
refundCutOffDate: Date;
bandName: String;
bandImagePath: String;
bandLink: String;
maxNumberOfSeats: number;
currentNumberOfSeats: number;
ticketPrice: number;
description: String;
}
The Models.Event class looks like this:
public class Event
{
public int id {get; set; }
public DateTime eventStart { get; set; }
public DateTime eventEnd { get; set; }
public DateTime refundCutOffDate { get; set; }
public string bandName { get; set; }
public string bandImagePath { get; set; }
public string bandLink { get; set; }
public int maxNumberOfSeats { get; set; }
public int currentNumberOfSeats { get; set; }
public double ticketPrice { get; set; }
public string description { get; set; }
}