Skip to content

Instantly share code, notes, and snippets.

View ssukhpinder's full-sized avatar
🏠
Working from home

Sukhpinder Singh ssukhpinder

🏠
Working from home
View GitHub Profile
@ssukhpinder
ssukhpinder / happy-holi-2024.markdown
Last active March 25, 2024 08:56
Happy Holi - 2024
IHostEnvironment env = hostingContext.HostingEnvironment;
configuration
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true);
public static int OccupancyTypeTollFare(Object vehicleType) => vehicleType switch
{
Car { PassengerCount: 0 } => 100 + 10,
Car { PassengerCount: 1 } => 100,
Car { PassengerCount: 2 } => 100 - 10,
Car c => 100 - 20,
Taxi { Fare: 0 } => 100 + 10,
Taxi { Fare: 1 } => 100,
Taxi { Fare: 2 } => 100 - 10,
Taxi t => 100 - 20,
ClaimApprover junior = new Manager();
ClaimApprover sukhpinder = new Manager();
ClaimApprover singh = new SeniorManager();
junior.SetHierarchy(sukhpinder);
sukhpinder.SetHierarchy(singh);
Claim c1 = new Claim() { amount = 999, Id = 1001 };
Claim c2 = new Claim() { amount = 10001, Id = 1002 };
junior.ApproveRequest(c1);
public class SeniorManager : ClaimApprover
{
public override void ApproveRequest(Claim claim)
{
if (claim.amount > 1000 && claim.amount <= 10000)
{
System.Console.WriteLine($"Claim reference {claim.Id} with amount {claim.amount} is approved by Senior Manager");
}
else
{
public class Manager : ClaimApprover
{
public override void ApproveRequest(Claim claim)
{
if (claim.amount >= 100 && claim.amount <= 1000)
{
System.Console.WriteLine($"Claim reference {claim.Id} with amount {claim.amount} is approved by Manager");
}
else if (claimApprover != null)
{
public class Junior : ClaimApprover
{
public override void ApproveRequest(Claim claim)
{
System.Console.WriteLine("Cannot approve");
}
}
public abstract class ClaimApprover
{
protected ClaimApprover claimApprover;
public void SetHierarchy(ClaimApprover claimApprover)
{
this.claimApprover = claimApprover;
}
public abstract void ApproveRequest(Claim claim);
}
static void Main(string[] args)
{
Chatroom chatroom = new Chatroom();
User Jennifer = new UserPersona(Username.Jennifer.ToString());
User Ashley = new UserPersona(Username.Ashley.ToString());
User David = new UserPersona(Username.David.ToString());
User Scott = new UserPersona(Username.Scott.ToString());
chatroom.Register(Jennifer);
chatroom.Register(Ashley);
class UserPersona : User
{
public UserPersona(string name) : base(name) { }
public override void DM(string from, string message) => base.DM(from, message);
}