Click here to Skip to main content
14,768,114 members
Home » Discussions » C#
   

C#

 
GeneralRe: How to make a dll library? Pin
Alex Dunlop16-Nov-20 5:15
MemberAlex Dunlop16-Nov-20 5:15 
GeneralRe: How to make a dll library? Pin
OriginalGriff16-Nov-20 5:37
mveOriginalGriff16-Nov-20 5:37 
GeneralRe: How to make a dll library? Pin
OriginalGriff16-Nov-20 6:41
mveOriginalGriff16-Nov-20 6:41 
GeneralRe: How to make a dll library? Pin
OriginalGriff16-Nov-20 3:21
mveOriginalGriff16-Nov-20 3:21 
QuestionC# WPF MenuItem Control not working Pin
Member 783087415-Nov-20 10:01
MemberMember 783087415-Nov-20 10:01 
AnswerRe: C# WPF MenuItem Control not working Pin
Mycroft Holmes15-Nov-20 12:03
professionalMycroft Holmes15-Nov-20 12:03 
GeneralRe: C# WPF MenuItem Control not working Pin
Member 783087417-Nov-20 15:51
MemberMember 783087417-Nov-20 15:51 
QuestionHow to group an array list, within a list of records, Linq GroupBy Pin
jkirkerx14-Nov-20 14:29
professionaljkirkerx14-Nov-20 14:29 
Scratching my head on this.

I have a list of inventory items, and I want to add how many has sold from orders. I can get the inventory, and then loop that inventory to get the "itemNumber", and query the orders to extract only orders that contain that item. But each order can have multiple items sold, so I need to get the "items sold array" within the order.

This is written for MongoDB, and is not really a MongoDB question. I have no clue how to write this in pure Mongo C# driver.

OrderId<br />
OrderNumber<br />
OrderItems = > ItemId<br />
OrderItems = > ItemNumber<br />
OrderItems = > Qty<br />
OrderItems = > Price

I wrote code to get all my inventory items, and used a for each of each item to query the orders. But I can't figure out the GroupBy part, or perhaps GroupBy is not the right solution.

The var in purple below is suggesting the order model, and not the OrderItems within the Order model. I know I constructed the GroupBy wrong, or using GroupBy is just plain wrong.
// Process inventory items
var start = (page * show) - show;
var query = _context.MarketPlaceInventory.Find(mp => mp.MarketChannel.Equals(marketChannel)).SortBy(s => s.ItemNumber);
var totalTask = query.CountDocumentsAsync();
var inventoryTask = query.Skip(start).Limit(show).ToListAsync();

// Wait for inventory to process
await Task.WhenAll(totalTask, inventoryTask);

// Process units sold from orders, bylooping the inventory
foreach (var product in inventoryTask.Result)
{
   var queryFilter = Builders<MarketPlaceOrders>.Filter.ElemMatch(oi => oi.OrderItems, item => item.ItemNumber == product.ItemNumber);
   var ordersTask = _context.MarketPlaceOrders.Find(queryFilter).ToListAsync();
   await Task.WhenAll(ordersTask);

   var orderItems = ordersTask.Result.GroupBy(x => x.OrderItems).Select(item => new MarketPlaceOrderItems() { 
       ItemQty = item.Sum(qty => <code>qty.ItemQty</code>) // This is suggesting the order, and not orderItems 
   });
   Console.Write(orderItems);

}

return new Get_MarketPlaceInventory
{
  Count = totalTask.Result,
  Inventory = inventoryTask.Result,                   
  Page = page,
  Show = show
};
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: How to group an array list, within a list of records, Linq GroupBy Pin
Gerry Schmitz14-Nov-20 23:31
mveGerry Schmitz14-Nov-20 23:31 
QuestionA proper way to return a list (Xamarin, CollectionView, Realm) Pin
Member 1499286214-Nov-20 10:10
MemberMember 1499286214-Nov-20 10:10 
SuggestionRe: A proper way to return a list (Xamarin, CollectionView, Realm) Pin
Richard MacCutchan14-Nov-20 7:07
mveRichard MacCutchan14-Nov-20 7:07 
GeneralRe: A proper way to return a list (Xamarin, CollectionView, Realm) Pin
Member 1499286214-Nov-20 10:10
MemberMember 1499286214-Nov-20 10:10 
GeneralRe: A proper way to return a list (Xamarin, CollectionView, Realm) Pin
OriginalGriff14-Nov-20 10:16
mveOriginalGriff14-Nov-20 10:16 
AnswerRe: A proper way to return a list (Xamarin, CollectionView, Realm) Pin
Mycroft Holmes14-Nov-20 13:18
professionalMycroft Holmes14-Nov-20 13:18 
GeneralRe: A proper way to return a list (Xamarin, CollectionView, Realm) Pin
Member 1499286216-Nov-20 9:17
MemberMember 1499286216-Nov-20 9:17 
QuestionHow to selected value of a dropbox column of a DataGridView programmatically? Pin
Alex Dunlop13-Nov-20 1:41
MemberAlex Dunlop13-Nov-20 1:41 
AnswerRe: How to selected value of a dropbox column of a DataGridView programmatically? Pin
Richard MacCutchan13-Nov-20 2:55
mveRichard MacCutchan13-Nov-20 2:55 
GeneralRe: How to selected value of a dropbox column of a DataGridView programmatically? Pin
Richard Deeming13-Nov-20 3:06
mveRichard Deeming13-Nov-20 3:06 
GeneralRe: How to selected value of a dropbox column of a DataGridView programmatically? Pin
Richard MacCutchan13-Nov-20 3:16
mveRichard MacCutchan13-Nov-20 3:16 
GeneralRe: How to selected value of a dropbox column of a DataGridView programmatically? Pin
Alex Dunlop13-Nov-20 4:09
MemberAlex Dunlop13-Nov-20 4:09 
AnswerRe: How to selected value of a dropbox column of a DataGridView programmatically? Pin
Gerry Schmitz13-Nov-20 5:10
mveGerry Schmitz13-Nov-20 5:10 
QuestionCommented code in c# forms does it affect the performance Pin
Sachin Kulkarni B12-Nov-20 5:50
MemberSachin Kulkarni B12-Nov-20 5:50 
AnswerRe: Commented code in c# forms does it affect the performance Pin
OriginalGriff12-Nov-20 6:08
mveOriginalGriff12-Nov-20 6:08 
GeneralRe: Commented code in c# forms does it affect the performance Pin
trønderen12-Nov-20 8:22
Membertrønderen12-Nov-20 8:22 
AnswerRe: Commented code in c# forms does it affect the performance Pin
Gerry Schmitz13-Nov-20 4:58
mveGerry Schmitz13-Nov-20 4:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.