예제 #1
0
        public void AddDaySchedule(DayScheduleVM vm)
        {
            //  Console.WriteLine("{0}, {1} to {2} on day {3}", EmpList.ElementAt(vm.EmployeeIndex).Name, vm.StartTime, vm.EndTime, WeekDates.ElementAt(vm.DayIndex - 1));

            var currentDay      = WeekDates.ElementAt(vm.DayIndex - 1);
            var currentEmployee = EmployeeSchedules.ElementAt(vm.EmployeeIndex).employee;

            Schedule schdl = new Schedule(currentDay.Month, currentDay.Day, currentDay.Year, vm.StartTime, vm.EndTime);

            //get new schedule id from database
            var scheduleId = ScheduleTableDB.AddSchedule(schdl);

            //add employee id and schedule id to linking table
            EmployeeScheduleTableDB.AddEmployeeSchedule(currentEmployee.EmployeeId, scheduleId);
        }
예제 #2
0
        public void GetEmployeeSchedules()
        {
            var schdl_list = EmployeeScheduleTableDB.GetAllEmployeeSchedules();
            var emp_list   = EmployeeTableDB.GetAllEmployees();

            dictionary = new Dictionary <int, EmployeeSchedule>();

            ////add all employees to dictionary
            foreach (var employee in emp_list)
            {
                if (!dictionary.ContainsKey(employee.EmployeeId))
                {
                    dictionary.Add(employee.EmployeeId, new EmployeeSchedule(employee));
                }
            }


            //add all employee schedules to dictionary
            foreach (var schdl in schdl_list)
            {
                Schedule schedule = ScheduleTableDB.GetScheduleById(schdl.Item2);

                if (dictionary.ContainsKey(schdl.Item1))
                {
                    //place schedule in correct day slot
                    for (int i = 0; i < WeekDates.Count; i++)
                    {
                        if (WeekDates[i].Day == schedule.Day && WeekDates[i].Month == schedule.Month && WeekDates[i].Year == schedule.Year)
                        {
                            dictionary[schdl.Item1].days.RemoveAt(i);
                            dictionary[schdl.Item1].days.Insert(i, schedule);
                        }
                    }
                }
            }

            //empty out current schedules
            EmployeeSchedules.Clear();

            foreach (var emp in dictionary)
            {
                EmployeeSchedules.Add(emp.Value);
            }
        }