I'm new to angular and .NET core, I'm trying to store related data to sqlserver via .net core api. My problem is Order controller is receiving one Order object how It will store orderitems with same OrderId which will be generated in Order Table? Plus I'm unable to call order controller, my service method returning this error
Failed to load resource: the server responded with a status of 500 () POST https://localhost:44378/api/Orders 500
checkout.ts
placeorder() {
this.postservice.placeorder(this.orderdata.value, this.cart.selections)
}
In this code orderdata.value are simple values while cart.selections are list of objects
Service code
placeorder(orderdata: order, orderitems: orderItems): Observable<any[]>{
return this.http.post<any[]>(this.myAppUrl + 'api/Orders', [orderdata,orderitems]);}
order Interface
export interface order{
orderid: number;
uid: number;
orderdate: Date;
orderstatus: string;
}
OrderItems interface
export interface orderItems extends Array<orderItem> {
}
export interface orderItem {
productId?: number;
productName?: string;
productPrice?: number;
quantityValue?: number;
}
Order Controller
[HttpPost]
public async Task<ActionResult<Orders>> PostOrders(Orders orders)
{
_context.Orders.Add(orders);
await _context.SaveChangesAsync();
return CreatedAtAction("GetOrders", new { id = orders.OrderId }, orders);
}
Order Model Class
public partial class Orders
{
public Orders()
{
OrderItems = new HashSet<OrderItems>();
}
public int OrderId { get; set; }
public int? Uid { get; set; }
public DateTime? OrderDate { get; set; }
public string OrderStatus { get; set; }
public virtual ICollection<OrderItems> OrderItems { get; set; }
}
OrderItems Model Class
public partial class OrderItems
{
public int ItemId { get; set; }
public int? ProductId { get; set; }
public string ProductName { get; set; }
public int? ProductPrice { get; set; }
public int? ProductQuantity { get; set; }
public int? OrderId { get; set; }
public virtual Orders Order { get; set; }
}