Hello all,
I am working with the C# driver, creating orders based on availability of inventory. I have a nested BSON structure for my data, that is stored in MongoDB Compass.
public class OrderItem
{
[BsonElement("Type")]
public string Type { get; set; }
[BsonElement("Vendor")]
public string Vendor { get; set; }
[BsonElement("Description")]
public string Description { get; set; }
[BsonElement("Cost")]
public double Cost { get; set; }
[BsonElement("Order Qty")]
public int OrderQty { get; set; }
[BsonElement("Serial")]
public int Serial { get; set; }
[BsonElement("PID")]
public string PID { get; set; }
}
public class Order
{
public Order(List<OrderItem> listOfItems, string po, double orderTotal, DateTime timeOfOrder)
{
OrderItemList = listOfItems;
Po = po;
OrderTotal = orderTotal;
OrderDate = timeOfOrder;
}
public ObjectId Id { get; set; }
[BsonElement("Order")]
public List<OrderItem> OrderItemList { get; set; }
[BsonElement("PO")]
public string Po { get; set; }
[BsonElement("Order Total")]
public double OrderTotal { get; set; }
[BsonElement("Date")]
public DateTime OrderDate { get; set; }
}
and I have gotten my code to work properly by using below code:
OrderItem item = new OrderItem();
List<OrderItem> listOfItemsT = new List<OrderItem>();
foreach (DataGridViewRow row in DGV_orders.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
tbl.AddCell(Convert.ToString(cell.Value));
}
item.Description = Convert.ToString(row.Cells["Description"].Value);
item.Vendor = Convert.ToString(row.Cells["Vendor"].Value);
item.Cost = Convert.ToDouble(row.Cells["Cost"].Value);
item.OrderQty = Convert.ToInt32(row.Cells["OrderQty"].Value);
item.Type = Convert.ToString(row.Cells["Type"].Value);
item.PID = Convert.ToString(row.Cells["ProductId"].Value);
item.Serial = Convert.ToInt32(row.Cells["ProductLink"].Value);
double cost = Convert.ToDouble(row.Cells[1].Value);
double qty = Convert.ToDouble(row.Cells[2].Value);
double lineTotal = cost * qty;
sum += lineTotal;
listOfItemsT.Add(item);
}
Order order = new Order(listOfItemsT,orderPO.Text, Math.Round(sum, 2),DateTime.Today);
everything works good. Now i just want to improve some smaller things, but I’m not sure where to look for the answers. When I view the data on Compass, the objects in the list array are obviously not named but I’m not too sure how I can name them.
See picture below.
All I’m hoping to accomplish is change the “Object”'s in order:Array to a productId or another parameter I have set already.