I am looking for answer for this question for a lot of time, but I don't always get what I want.
This is the code in my REST controller:
[Route("api/[controller]")]
[ApiController]
[Route("InsertOneProduct/{ean:long}/{name}/{producer}/{type}/{quantity:int}/{price:float}/{vat:int}")]
[HttpPost]
public void InsertOneProductWithType(long ean, string name, string producer, List<TypeOfProduct> type ,int quantity, float price, int vat)
{
var product = new Products(ean, name, producer, type ,quantity, price, vat);
mongoDB.InsertProducts(product);
}
This what I want is to send List of types in url, so i try to do this this way and many more but this doesn't work
https://localhost:44385/api/Rest/InsertOneProduct/059013590036/TyskieGronie/KompaniaPiwowarska/type=Tyskie/100/1.99/23
https://localhost:44385/api/Rest/InsertOneProduct/059013590036/TyskieGronie/KompaniaPiwowarska/Tyskie/100/1.99/23
https://localhost:44385/api/Rest/InsertOneProduct/059013590036/TyskieGronie/KompaniaPiwowarska/type="Tyskie"/100/1.99/23
https://localhost:44385/api/Rest/InsertOneProduct/059013590036/TyskieGronie/KompaniaPiwowarska/"Tyskie"/100/1.99/23`
Code of products and type of products:
public class Products
{
[BsonId]
ObjectId objectId { get; set; }
public long ean { get; set;}
public string name { get; set; }
public string producer { get; set; }
public List<TypeOfProduct> type { get; set; }
public float price { get; set; }
public int vat { get; set; }
public int quantity { get; set; }
}
public class TypeOfProduct
{
string type;
}
Can somebody explain how to do it properly? Thanks for all answers