microsoft / InventorySample

Sample UWP application for LOB scenarios
MIT License
591 stars 199 forks source link

Error in DataServiceBase.OrderItems class #65

Open fmassicci opened 4 years ago

fmassicci commented 4 years ago

public async Task UpdateOrderItemAsync(OrderItem orderItem) { if (orderItem.OrderLine > 0) { _dataSource.Entry(orderItem).State = EntityState.Modified; } else { orderItem.OrderLine = _dataSource.OrderItems.Where(r => r.OrderID == orderItem.OrderID).Select(r => r.OrderLine).DefaultIfEmpty(0).Max() + 1; // TODO: //orderItem.CreateOn = DateTime.UtcNow; _dataSource.Entry(orderItem).State = EntityState.Added; } // TODO: //orderItem.LastModifiedOn = DateTime.UtcNow; //orderItem.SearchTerms = orderItem.BuildSearchTerms(); return await _dataSource.SaveChangesAsync(); }

orderItem.OrderLine = .... not working

fmassicci commented 4 years ago

In reference to my post I would like to suggest a solution: IList items = _dataSource.OrderItems.Where(r => r.OrderID == objItem.OrderID).ToList(); objItem.OrderLine = items.Select(r => r.OrderLine).DefaultIfEmpty(0).Max() + 1;