static void Main(string[] args) { //Method to display colum week for August 5 to 11 Console.WriteLine("August 5 to 11"); //Gets the date for week August 5 to 11 2018 DateTime dt2 = new DateTime(2018, 08, 05); //Iterate through days for week of August 5 to 11 and convert days to string format short spelling of day and numeric day of week var result = Enumerable.Range(0, 7).Select(i => dt2.AddDays(i).ToString("ddd d")); //Display colum for week of 5-11 and show in console DisplayDaysOfWeek(result.ToArray()); //Generic list of string to hold values for dates of the week of August 5 to 11 2018 and hous worked List <string> daysWorked = new List <string>(); //Iterate through days for week of August 5 to 11 foreach (var item in Enumerable.Range(0, 7).Select(i => dt2.AddDays(i).ToString())) { //Method that gets hours worked for in hours.cs GetStaff() method parse date to get matching date var viewHours = GetStaffHours.GetStaff().Where(d => DateTime.Parse(d.StartDate).Date == DateTime.Parse(item).Date).FirstOrDefault(); //If a date is found add to Generic list of string daysWorked if (viewHours != null) { //Subtract timespan from EndDate - StartDate to get positive hours worked for that day TimeSpan duration = DateTime.Parse(viewHours.EndDate).Subtract(DateTime.Parse(viewHours.StartDate)); //Add hours to list daysWorked.Add($"{duration.Hours}"); } else { //Else the day was not found to have startdate set - for no hours found daysWorked.Add($"-"); } } //Display Peter hours work for the week of 5-11 and show in console DisplayHoursWorked(daysWorked.ToArray()); }
//method returns hours worked public static List <Hours> GetHours(GetStaffHours staff) { List <Hours> staffHours = new List <Hours>() { new Hours() { StaffID = 2, StartDate = "8/8/18 7:00 AM", EndDate = "8/8/18 1:00 PM" }, new Hours() { StaffID = 2, StartDate = "8/9/18 10:00 AM", EndDate = "8/9/18 6:00 PM " }, new Hours() { StaffID = 2, StartDate = "8/10/18 8:00 AM", EndDate = "8/10/18 2:00 PM" }, }; return(staffHours); }