I am trying to add Car objects to my Database, it's working fine with just strings, but when I try to add an integer value, the value gets quoted in the JSON and so turned to string. Here's my .Net Core Model :
public class Car : Service
{
public string Description { get; set; }
public int Price { get; set; }
public string Options { get; set; }
}
Here's my create handler
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken)
{
var car = new Car
{
id = request.id,
Name = request.Name,
Description = request.Description,
Price = request.Price,
Options = request.Options
};
_context.Cars.Add(car);
var success= await _context.SaveChangesAsync() > 0;
if(success) return Unit.Value;
throw new System.Exception("Problem saving changes");
}
Again the create handler works fine with strings but when I try to send an integer value, here's the JSON that's sent:
{id: "f8aa6881-8a90-4510-9505-5471c1f9a656", name: "Mercedes AMG", description: "a", price: "800",…}
description: "a"
id: "f8aa6881-8a90-4510-9505-5471c1f9a656"
name: "Mercedes AMG"
options: "a"
price: "800" //This is the value creating the problem
price:{}; The JSON value could not be converted to System.Int32
Please how can I make sure the value gets passed as an integer? I appreciate the help.