private static void SearchByStatus() { Console.WriteLine("Enter status to seacrh(Pending/Approved/Rejected)"); var statusString = Console.ReadLine(); var status = EnumStringMap.ToEnum(statusString); if (status == Status.Other) { Console.WriteLine("Enter valid status"); return; } var leaves = Leave.GetByStatus(status); Console.WriteLine(); if (leaves.Count < 1) { Console.WriteLine("Not Found any matching leave"); return; } leaves.ForEach(leave => { Console.WriteLine(leave); }); }
public static List <Leave> ReadLeaves() { var leaves = new List <Leave>(); if (!Directory.Exists(Constants.LeaveCsvPath)) { Console.WriteLine("Please provide correct path"); return(leaves); } var csvFiles = Directory.GetFiles(Constants.LeaveCsvPath, "*.csv", SearchOption.TopDirectoryOnly); if (csvFiles.Length < 1) { return(leaves); } var line = ""; try { using (var sr = new StreamReader(csvFiles[0])) { var header = sr.ReadLine(); // To ignore headers in csv File. while ((line = sr.ReadLine()) != null) { var coloms = line.Split(","); var leave = new Leave() { Id = int.Parse(coloms[0]), Creator = new UserBase { Name = coloms[1] }, Manager = new UserBase { Name = coloms[2] }, Title = coloms[3], Description = coloms[4], StartDate = DateTime.Parse(coloms[5]), EndDate = DateTime.Parse(coloms[6]), Status = EnumStringMap.ToEnum(coloms[7]) }; leaves.Add(leave); } } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } return(leaves); }