private static void UpdateLeave() { try { List <Leave> leaves = PrintLevesForUpdation(); if (leaves.Count == 0) { return; } Console.WriteLine("Enter LeaveId you want to update"); int leaveId = int.Parse(Console.ReadLine()); Leave Updateleave = FileHandler.GetLeave(leaveId); if (Updateleave != null) { switch (UpdateLeaveMenuListOne()) { case 1: Updateleave.LeaveStatus = LeaveStatus.PENDING; break; case 2: Updateleave.LeaveStatus = LeaveStatus.APPROVED; break; case 3: Updateleave.LeaveStatus = LeaveStatus.REJECTED; break; } Updateleave.UpdateLeave(); } else { Console.WriteLine("Record not found for given leaveId! Enter valid leaveId"); } } catch (FormatException) { Console.WriteLine("Input type is not valid! Must be a number"); } }
public void ReadDataFromFile(int empId, Leave leave) { Employee emp = GetEmployee(empId); WriteDataToTheFile(leave.GetLeaveId(), emp.GetEmpId(), emp.GetCreator(), leave.GetManagerName(), leave.GetTitle(), leave.GetDescripation(), leave.GetStartDate(), leave.GetEndDate(), leave.GetStatus()); }
public static void LoadLeaves() { if (File.Exists(InputArguments.OUT_FILE) && (new FileInfo(InputArguments.OUT_FILE)).Length > 0) { TextFieldParser parser = new TextFieldParser(InputArguments.OUT_FILE); parser.SetDelimiters(new string[] { "," }); parser.HasFieldsEnclosedInQuotes = false; Int32 id; DateTime startDate; DateTime endDate; LeaveStatus leaveStatus; try { // Skip over header line. parser.ReadLine(); while (!parser.EndOfData) { string[] fields = parser.ReadFields(); if (fields.Length == 8) { try { id = Int32.Parse(fields[0]); } catch (Exception e) { Console.WriteLine("Invalid Id in record, skipping line. Reason: {}", e.Message); continue; } try { startDate = DateTime.ParseExact(fields[5], InputArguments.DATE_FORMAT, InputArguments.DATE_CULTURE_PROVIDER); } catch (Exception e) { Console.WriteLine("Invalid start date in record, skipping line. Reason: {}", e.Message); continue; } try { endDate = DateTime.ParseExact(fields[6], InputArguments.DATE_FORMAT, InputArguments.DATE_CULTURE_PROVIDER); } catch (Exception e) { Console.WriteLine("Invalid end date in record, skipping line. Reason: {}", e.Message); continue; } try { leaveStatus = (LeaveStatus)Enum.Parse(typeof(LeaveStatus), fields[7], true); } catch (Exception e) { Console.WriteLine("Invalid leave status in record, skipping line. Reason: {}", e.Message); continue; } Leave leave = new Leave( id, fields[1], fields[2], fields[3], fields[4], startDate, endDate, leaveStatus ); } else { Console.WriteLine("Invalid line, skipping"); continue; } } } catch (Exception e) { throw new Exception("Error parsing leaves.csv.", e); } } }
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); }