public void AddWorkingOptionForDay(int scheduleID, int employeeID, DateTime date, IWorkingOption workingOption) { CheckInputStrings(SymbolPattern, workingOption.Symbol); ISchedulePresentationData schedule = GetScheduleFromId(scheduleID); int indexOfDate = schedule.GetIndexOfDate(date); List <WorkingPlan> workingPlans = GetWorkingPlans(); foreach (WorkingPlan plan in workingPlans) { if (plan.ScheduleID == scheduleID && plan.EmployeeID == employeeID) { for (int i = 0; i < plan.WorkingOptions.Count; i++) { if (i == indexOfDate) { plan.WorkingOptions[i] = workingOption; break; } } } } SaveWorkingPlans(workingPlans); }
public ISchedule LoadSchedule(int id) { // Get basic information about schedule ISchedulePresentationData schedule = GetScheduleFromId(id); ISchedule output = new ScheduleModel(schedule.Id, schedule.Name, schedule.StartingDay, schedule.LastDay); // Get list of employees (without available working options for now) List <WorkingPlan> plans = GetWorkingPlans(); List <IEmployeePresentationData> employeeData = GetEmployees(); List <IEmployee> employeesWithoutWorkingPlan = common.GetEmployeesWithoutWorkingPlan(plans, employeeData, output); // Fill in the list of employees with available options List <IEmployee> employees = new List <IEmployee>(); List <WorkingOptionOfEmployee> workingOptionOfEmployees = GetWorkingOptionOfEmployees(); List <IWorkingOption> workingOptions = GetWorkingOptions(); common.FillEmployeesWithWorkingOptions(employees, employeesWithoutWorkingPlan, workingOptionOfEmployees, workingOptions, output); // Add each employee to output schedule employees.ForEach(e => output.AddEmployee(e)); // Get working plan for each employee common.GetWorkingPlanForEmployees(employees, plans, output); return(output); }
public static int GetIndexOfDate(this ISchedulePresentationData schedule, DateTime date) { int i = 0; for (DateTime day = schedule.StartingDay; day <= schedule.LastDay; day = day.AddDays(1)) { if (day.Day == date.Day && day.Month == date.Month && day.Year == date.Year) { return(i); } i++; } throw new ArgumentException("Such date does not exist in the schedule"); }
public static int GetNumberOfDays(this ISchedulePresentationData schedule) { return((schedule.LastDay - schedule.StartingDay).Days + 1); }