I am working on an application where I have a list of statuses like Submitted, Approved, and Rejected. In my scenario when all the statutes are Approved then I have to return Approved but if there is a single record that is Rejected then will return Rejected. If there is a record with the status Submitted and the other two are Approved then return Submitted. I have implemented a simple check base logic but I need to make it better with best practices and more generic.
List<string> statuses = new List<string>() { "Approved", "Approved", "Approved" };
var res = statuses.Where(x => x == "Approved").ToList();
if (res.Count() == statuses.Count())
{
Console.WriteLine("Approved");
}
if (res.Where(x => x == "Rejected").Count() > 0)
{
Console.WriteLine("Rejected");
}
else
{
Console.WriteLine("Submitted");
}
How can I achieve this and improve my logic?