public static void ListMyLeaves(string employeeId) { Int32 id; try { id = Int32.Parse(employeeId); } catch (Exception e) { throw new Exception("Invalid employee Id:" + employeeId, e); } string employeeName = EmployeeCatalog.GetEmployeeName(id); if (employeeName == null) { throw new Exception("Invalid employee Id:" + employeeId); } foreach (Leave leave in leaves) { if (leave.creator.Equals(employeeName)) { Console.WriteLine(leave); } } }
public static void UpdateLeave(string employeeId, string leaveRecordId, string status) { Int32 id; LeaveStatus leaveStatus; try { id = Int32.Parse(employeeId); } catch (Exception e) { throw new Exception("Invalid employee Id:" + employeeId, e); } Int32 leaveRecId; try { leaveRecId = Int32.Parse(leaveRecordId); } catch (Exception e) { throw new Exception("Invalid leave record Id:" + leaveRecordId, e); } try { leaveStatus = (LeaveStatus)Enum.Parse(typeof(LeaveStatus), status, true); } catch (Exception e) { throw new Exception("Invalid leave status.", e); } string managerName = EmployeeCatalog.GetEmployeeName(id); foreach (Leave leave in leaves) { if (leave.manager.Equals(managerName) && leave.id == leaveRecId) { leave.leaveStatus = leaveStatus; } } }
public static void CreateLeave( string employeeId, string managerName, string title, string description, string startDate, string endDate ) { Int32 id; DateTime startDt; DateTime endDt; try { id = Int32.Parse(employeeId); } catch (Exception e) { throw new Exception("Invalid employee Id:" + employeeId, e); } if (null == managerName || managerName.Length == 0) { throw new Exception("Invalid manager name:" + managerName); } if (null == description || description.Length == 0) { throw new Exception("Invalid description:" + description); } if (null == title || title.Length == 0) { throw new Exception("Invalid title:" + title); } if (null == startDate || startDate.Length == 0) { throw new Exception("Invalid start date:" + startDate); } try { startDt = DateTime.ParseExact(startDate, InputArguments.DATE_FORMAT, InputArguments.DATE_CULTURE_PROVIDER); } catch (Exception e) { throw new Exception("Invalid start date:" + startDate, e); } if (null == endDate || endDate.Length == 0) { throw new Exception("Invalid end date:" + endDate); } try { endDt = DateTime.ParseExact(endDate, InputArguments.DATE_FORMAT, InputArguments.DATE_CULTURE_PROVIDER); } catch (Exception e) { throw new Exception("Invalid end date:" + endDate, e); } string employeeName = EmployeeCatalog.GetEmployeeName(id); if (employeeName == null) { throw new Exception("Invalid employee Id:" + employeeId); } Int32 managerId = EmployeeCatalog.GetManagerId(id); if (managerId == -1) { throw new Exception("No manager for employee Id:" + employeeId); } string managerNm = EmployeeCatalog.GetEmployeeName(managerId); if (!managerName.Equals(managerNm)) { throw new Exception("Wrong manager name input:" + managerName + ", expected: " + managerNm); } Int32 leaveRecordId = leaves.Count + 1; Leave newLeave = new Leave( leaveRecordId, employeeName, managerName, title, description, startDt, endDt, LeaveStatus.Pending ); leaves.Add(newLeave); }
static void Main(string[] args) { EmployeeCatalog.LoadEmployees(); // EmployeeCatalog.PrintEmployeeManager(); // EmployeeCatalog.PrintManagerEmployees(); LeaveService.LoadLeaves(); Console.WriteLine("Enter employee Id"); string employeeId = Console.ReadLine(); Console.WriteLine("Choices:"); Console.WriteLine("CreateLeave:AssignTo,Title,Description,StartDate,EndDate"); Console.WriteLine("ListMyLeaves:"); Console.WriteLine("UpdateLeave:"); Console.WriteLine("SearchLeavesByTitle:"); Console.WriteLine("SearchLeavesByStatus:"); Console.WriteLine("Quit:"); string choice = Console.ReadLine(); string leaveRecordId; string assignTo; string title; string description; string startDate; string endDate; string status; while (!choice.Equals("Quit")) { switch (choice) { case "CreateLeave": Console.WriteLine("assignTo:"); assignTo = Console.ReadLine(); Console.WriteLine("title:"); title = Console.ReadLine(); Console.WriteLine("description:"); description = Console.ReadLine(); Console.WriteLine("startDate:"); startDate = Console.ReadLine(); Console.WriteLine("endDate:"); endDate = Console.ReadLine(); LeaveService.CreateLeave (employeeId, assignTo, title, description, startDate, endDate); Console.WriteLine("Leave created successfully"); break; case "ListMyLeaves": LeaveService.ListMyLeaves(employeeId); Console.WriteLine("Leaves listed successfully"); break; case "UpdateLeave": Console.WriteLine("leaveRecordId:"); leaveRecordId = Console.ReadLine(); Console.WriteLine("status:"); status = Console.ReadLine(); LeaveService.UpdateLeave(employeeId, leaveRecordId, status); Console.WriteLine("Leave status updated successfully"); break; case "SearchLeavesByTitle": Console.WriteLine("title:"); title = Console.ReadLine(); LeaveService.SearchLeavesByTitle(title); Console.WriteLine("Leaves searched by title successfully"); break; case "SearchLeavesByStatus": Console.WriteLine("status:"); status = Console.ReadLine(); LeaveService.SearchLeavesByStatus(status); Console.WriteLine("Leaves searched by status successfully"); break; default: Console.WriteLine("Invalid choice"); break; } Console.WriteLine("Enter next choice:"); choice = Console.ReadLine(); } LeaveService.SaveLeaves(); Console.WriteLine("Exiting Leave Tracker"); System.Environment.Exit(0); }