CSharp · Console
using System;
using System.Linq;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
var items = new InternalConditionModel[]
{
new InternalConditionModel { ProductId = "a", IsSSoldOnlyOnDisplay = false, Value = 1},
new InternalConditionModel { ProductId = "a", IsSSoldOnlyOnDisplay = true, Value = 2}, // should be chosen
new InternalConditionModel { ProductId = "b", IsSSoldOnlyOnDisplay = true, Value = 2},
new InternalConditionModel { ProductId = "b", IsSSoldOnlyOnDisplay = true, Value = 4}, // should be chosen
new InternalConditionModel { ProductId = "b", IsSSoldOnlyOnDisplay = true, Value = 3},
};
var result = items.GroupBy(x => x.ProductId).Select(x => x.OrderByDescending(y => y.Value).FirstOrDefault(y => x.Count(z => z.IsSSoldOnlyOnDisplay) == 1 ? y.IsSSoldOnlyOnDisplay : true));
foreach(var item in result)
{
Console.WriteLine("id="+item.ProductId+", Value="+item.Value);
}
}
}
class InternalConditionModel
{
public string ProductId { get; set; }
public double Value { get; set; }
public DateTime DateFrom { get; set; }
public DateTime DateThru { get; set; }
public bool IsSSoldOnlyOnDisplay { get; set; }
}