Uebungsaufgaben/Semester3/DotNET/Aufgabenblatt4/Aufgabe11/SalesRepresentativeRepository.cs
2024-12-19 23:55:07 +01:00

132 lines
4.7 KiB
C#

namespace Aufgabe11
{
public class SalesRepresentativeRepository
{
public List<(string FirstName, string LastName, string Company, decimal SalesVolume)>
GetSalesRepsFromBadenWuerttemberg(List<SalesRepresentative> salesRepresentatives)
{
if (salesRepresentatives != null)
{
var results =
from representative in salesRepresentatives
where representative.Area == "Baden-Württemberg"
orderby representative.Company
select (FirstName: representative.FirstName,
LastName: representative.LastName,
Company: representative.Company,
SalesVolume: representative.SalesVolume);
return results.ToList();
}
else
{
return new List<(string FirstName, string LastName, string Company, decimal SalesVolume)>();
}
}
public List<SalesRepresentative> GetSalesRepsFromBadenWuerttembergNew(List<SalesRepresentative> salesRepresentatives)
{
if (salesRepresentatives != null)
{
var results =
from representative in salesRepresentatives
where representative.Area == "Baden-Württemberg"
orderby representative.Company
select representative;
return results.ToList();
}
else
{
return new List<SalesRepresentative>();
}
}
public List<(string FirstName, string LastName, string Company, string Area, decimal SalesVolume)>
GetSalesRepsGroupedByCompany(List<SalesRepresentative> salesRepresentatives)
{
if (salesRepresentatives != null)
{
var results =
from representative in salesRepresentatives
where representative.SalesVolume >= 10000
orderby representative.Company, representative.SalesVolume descending
select (FirstName: representative.FirstName,
LastName: representative.LastName,
Company: representative.Company,
Area: representative.Area,
SalesVolume: representative.SalesVolume);
return results.ToList();
}
else
{
return new List<(string FirstName, string LastName, string Company, string Area, decimal SalesVolume)>();
}
}
public List<SalesRepresentative> GetSalesRepsGroupedByCompanyNew(List<SalesRepresentative> salesRepresentatives)
{
if (salesRepresentatives != null)
{
var results =
from representative in salesRepresentatives
where representative.SalesVolume >= 10000
orderby representative.Company, representative.SalesVolume descending
select representative;
return results.ToList();
}
else
{
return new List<SalesRepresentative>();
}
}
public List<(string FirstName, string LastName, string Company, string Area, decimal SalesVolume)>
GetTopTenLosers(List<SalesRepresentative> salesRepresentatives)
{
if (salesRepresentatives != null)
{
var results =
from representative in salesRepresentatives
orderby representative.SalesVolume
select (FirstName: representative.FirstName,
LastName: representative.LastName,
Company: representative.Company,
Area: representative.Area,
SalesVolume: representative.SalesVolume);
results = results.Take(10);
return results.ToList();
}
else
{
return new List<(string FirstName, string LastName, string Company, string Area, decimal SalesVolume)>();
}
}
public List<SalesRepresentative> GetTopTenLosersNew(List<SalesRepresentative> salesRepresentatives)
{
if (salesRepresentatives != null)
{
var results = salesRepresentatives
.OrderBy(representative => representative.SalesVolume)
.Take(10)
.ToList();
return results;
}
else
{
return new List<SalesRepresentative>();
}
}
}
}