Open fmassicci opened 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
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;
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