using System.Collections.Generic;
using System.Threading.Tasks;
private static List<SalesRecord> salesRecords = new();
public static void Main()
var currentServiceProvider = "AWS";
var accManager = GetAccountManager(currentServiceProvider);
Console.WriteLine("Enter User ID:");
var userId = Console.ReadLine();
Console.WriteLine("Enter Password:");
var password = Console.ReadLine();
if (!accManager.Authenticate(userId, password))
Console.WriteLine("Authentication failed. Exiting...");
for (var i = 0; i < 10000; i++)
var item = i < 4000 ? "A" : i < 8000 ? "B" : "C";
salesRecords.Add(new SalesRecord(item));
Random random = new Random();
Parallel.For(0, salesRecords.Count, i =>
salesRecords[i].Qty = random.Next(1, 101);
Console.WriteLine("Which item do you want to view? (A/B/C):");
var chosenItem = Console.ReadLine();
string chosenItemCode = chosenItem;
var selectedRecords = salesRecords
.Where(record => record.Item == chosenItemCode)
.OrderByDescending(record => record.Qty)
.Select(record => new { record.Item, record.Qty });
foreach (var record in selectedRecords)
Console.WriteLine($"Item Code: {record}, Qty: {record.Qty}");
public static IAccountManager GetAccountManager(string serviceProvider)
if (serviceProvider == "AWS")
return new AwsAccountManager(new AwsService());
else if (serviceProvider == "Azure")
return new AzureAccountManager(new AzureService());
throw new ArgumentException("Invalid serviceProvider");
public struct SalesRecord
public string Item { get; set; }
public int Qty { get; set; }
public SalesRecord(string item)
public interface IAccountManager
public bool Authenticate(string userId, string password);
public class AwsAccountManager : IAccountManager
private AwsService awsService;
public AwsAccountManager(AwsService awsService)
this.awsService = awsService;
public bool Authenticate(string username, string password)
return awsService.Authenticate(username, password);
public class AzureAccountManager : IAccountManager
private AzureService azureService;
public AzureAccountManager(AzureService azureService)
this.azureService = azureService;
public bool Authenticate(string username, string password)
return azureService.AuthUser(username, password);
public bool Authenticate(string userId, string password)
return userId == "aws" && password == "abc123";
public bool DeleteUser(string userId)
public class AzureService
public bool AuthUser(string userId, string password)
return userId == "azure" && password == "abc321";
public bool RemoveUser(string userId)