public List<DriverWithOrdersDTO> GetCurrentDriversLastMonth(int id)
{
var allDrivers = this.GetDriversWithOrdersLastMonth().ToList();
var i = 0;
for (; i < allDrivers.Count; i++)
if (allDrivers[i].Driver.Id == id)
break;
var currentDriverIndex = i;
var firstDriverIndex = i - 3;
var lastDriverIndex = i + 3;
while (firstDriverIndex < 0)
{
firstDriverIndex++;
lastDriverIndex++;
}
while (lastDriverIndex >= allDrivers.Count)
{
firstDriverIndex--;
lastDriverIndex--;
}
while (firstDriverIndex < 0)
firstDriverIndex++;
var currentDrivers = new List<DriverWithOrdersDTO>();
for (i = firstDriverIndex; i <= lastDriverIndex; i++)
{
var newDriver = allDrivers[i];
newDriver.Index = i + 1;
currentDrivers.Add(newDriver);
}
return currentDrivers;
}