Hi
Is there any sample code for Approval Process in c#
Thanks
Hi
Is there any sample code for Approval Process in c#
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Gowtham CpRank #1,552 · 1K reputationPosted Aug 19, 2024, 1:50 AM EDT
Hi Ramco Ramco,
For an approval system in C# where an employee's leave needs to be approved first by their boss and then by HR, you can use the following sample code:
using System; public class LeaveRequest { public string EmployeeName { get; set; } public int DaysRequested { get; set; } public ApprovalStatus BossApproval { get; private set; } public ApprovalStatus HRApproval { get; private set; } public LeaveRequest(string employeeName, int daysRequested) { EmployeeName = employeeName; DaysRequested = daysRequested; BossApproval = ApprovalStatus.Pending; HRApproval = ApprovalStatus.Pending; } public void ApproveByBoss() { if (BossApproval == ApprovalStatus.Pending) { BossApproval = ApprovalStatus.Approved; Console.WriteLine($"Leave request for {EmployeeName} approved by boss."); } else { Console.WriteLine("Boss has already approved this leave."); } } public void ApproveByHR() { if (BossApproval == ApprovalStatus.Approved && HRApproval == ApprovalStatus.Pending) { HRApproval = ApprovalStatus.Approved; Console.WriteLine($"Leave request for {EmployeeName} approved by HR."); } else if (BossApproval == ApprovalStatus.Pending) { Console.WriteLine("Boss approval is required before HR can approve."); } else { Console.WriteLine("HR has already approved this leave."); } } public void DisplayStatus() { Console.WriteLine($"Employee: {EmployeeName}"); Console.WriteLine($"Days Requested: {DaysRequested}"); Console.WriteLine($"Boss Approval: {BossApproval}"); Console.WriteLine($"HR Approval: {HRApproval}"); } } public enum ApprovalStatus { Pending, Approved, Rejected } class Program { static void Main() { LeaveRequest leaveRequest = new LeaveRequest("Jane Smith", 3); leaveRequest.DisplayStatus(); leaveRequest.ApproveByBoss(); leaveRequest.ApproveByHR(); leaveRequest.DisplayStatus(); } }Hope it helps!
Gowtham CpRank #1,552 · 1K reputationPosted Aug 18, 2024, 12:54 PM EDT
Could you please provide more specifics about the approval process you're referring to? Are you looking for a basic workflow, integration with a particular system, or something else? This will help me provide you with the most relevant code examples.
Ramco RamcoRank #462 · 5.4K reputationPosted Aug 18, 2024, 11:45 PM EDT
Hi Gowtham Cp
Suppose employee leave to be approved by his boss first and then H.R. Is there any Approval Work System which can be easily integrated with c#
Thanks