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();
var isAuthenticated = accManager.Authenticate(userId, password);
Console.WriteLine("Invalid UserID or Password!");
Console.WriteLine("Enter User ID:");
userId = Console.ReadLine();
Console.WriteLine("Enter Password:");
password = Console.ReadLine();
isAuthenticated = accManager.Authenticate(userId, password);
for (var i = 0; i < 10000; i++)
var item = i < 4000 ? "A" : i < 8000 ? "B" : "C";
salesRecords.Add(new SalesRecord(item));
Parallel.ForEach(salesRecords, record =>
foreach (SalesRecord record in salesRecords) {
AssignRandomQuantity(record);
Console.WriteLine("Which item do you want to view? (A/B/C):");
var chosenItem = Console.ReadLine();
var itemSales = salesRecords
.Where(sr => sr.Item.Equals(chosenItem))
.OrderByDescending(sr => sr.Qty);
foreach (var sale in itemSales)
Console.WriteLine($"Item {sale.Item}: Qty {sale.Qty}");
private static void AssignRandomQuantity(SalesRecord record)
public static IAccountManager GetAccountManager(string serviceProvider)
switch (serviceProvider.ToLower())
return new AwsAccountManager();
return new AzureAccountManager();
throw new ArgumentException("Invalid service provider");
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 = new AwsService();
public bool Authenticate(string userId, string password)
return awsService.Authenticate(userId, password);
public class AzureAccountManager : IAccountManager
private AzureService azureService;
public AzureAccountManager()
azureService = new AzureService();
public bool Authenticate(string userId, string password)
return azureService.AuthUser(userId, 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)