public Timetable(Timetable timetable)
 {
     Monday = timetable.Monday;
     Tuesday = timetable.Tuesday;
     Wednesday = timetable.Wednesday;
     Thursday = timetable.Thursday;
     Friday = timetable.Friday;
     Saturday = timetable.Saturday;
     Sunday = timetable.Sunday;
 }
        public Timetable On(DateTime date)
        {
            var overridesForDay =
                _overrides.GetByQuery(o => (o.User.Id == Default.User.Id && o.EffectiveAt.Date == date.Date));

            if (!overridesForDay.Any())
            {
                return Default;
            }

            var toOverride = new Timetable(Default);
            var overrideSchedule = overridesForDay.First();
            return toOverride.OverrideDay(overrideSchedule.EffectiveAt.DayOfWeek, overrideSchedule.WorkingHours);
        }
        private void CreateSchedule(object sender, EventArgs args)
        {
            Dictionary<string, object> timetableProperties = _view.GetModelPropertiesMap();

            var timetable = new Timetable()
            {
                Monday = new Tuple<int, int>(Convert.ToInt32((string) timetableProperties["mondayStart"]),
                    Convert.ToInt32((string) timetableProperties["mondayEnd"])),
                Tuesday = new Tuple<int, int>(Convert.ToInt32((string) timetableProperties["tuesdayStart"]),
                    Convert.ToInt32((string) timetableProperties["tuesdayEnd"])),
                Wednesday = new Tuple<int, int>(Convert.ToInt32((string) timetableProperties["wednesdayStart"]),
                    Convert.ToInt32((string) timetableProperties["wednesdayEnd"])),
                Friday = new Tuple<int, int>(Convert.ToInt32((string) timetableProperties["thursdayStart"]),
                    Convert.ToInt32((string) timetableProperties["thursdayEnd"])),
                Saturday = new Tuple<int, int>(Convert.ToInt32((string) timetableProperties["saturdayStart"]),
                    Convert.ToInt32((string) timetableProperties["saturdayEnd"])),
                Sunday = new Tuple<int, int>(Convert.ToInt32((string) timetableProperties["sundayStart"]),
                    Convert.ToInt32((string) timetableProperties["sundayEnd"])),
                User = _user
            };

            _timetableRepository.Save(timetable);
            _view.PrintMessageBoxAndClose("Schedule for user " + _user.Name + " " + _user.Surname + " created!");
        }
 public SpecifySchedule(Repository<TimetableOverride> overrides, Timetable defaultTimetable)
 {
     _overrides = overrides;
     Default = defaultTimetable;
 }
        private void applyChanges()
        {
            if (listView1.SelectedItems != null && users != null && timetables != null && timetablesOverride != null)
            {
                bool found = false;
                Library_Enterprise_University_Project.DataInterface.Entities.User user;
                int spacePosition = 0;
                string userString = "";
                for (int i = 0; i < listView1.Items.Count; i++)
                {
                    if (listView1.Items[i].Selected)
                    {
                        userString = listView1.Items[i].Text;
                        break;
                    }
                }
                for (int i = 0; i < userString.Length; i++)
                {
                    if (userString.ElementAt(i).Equals(' '))
                    {
                        spacePosition = i;
                        break;
                    }
                }
                if (userString.Length != 0)
                {
                    name = userString.Substring(0, spacePosition);
                    surname = userString.Substring(spacePosition + 1);
                    foreach (Library_Enterprise_University_Project.DataInterface.Entities.User tmpUser in users)
                    {
                        if (tmpUser.Role == Role.Librarian && tmpUser.Name.Equals(name) &&
                            tmpUser.Surname.Equals(surname))
                        {
                            user = tmpUser;
                        if(timetablesOverride.Count()>0)foreach (TimetableOverride timetableOverride in timetablesOverride)
                            {
                                if (timetableOverride.User.Equals(user) &&
                                    timetableOverride.EffectiveAt.Equals(dateTimePicker1.Value.Date))
                                {
                                    comboBox1.SelectedIndex =
                                        comboBox1.FindString("" + timetableOverride.WorkingHours.Item1);
                                    comboBox2.SelectedIndex =
                                        comboBox2.FindString("" + timetableOverride.WorkingHours.Item2);
                                    found = true;
                                    break;
                                }
                            }

                            if (!found && timetables.Count()>0)
                            {
                                foreach (Timetable timetable in timetables)
                                {
                                    if (timetable.User.Equals(user))
                                    {
                                        DayOfWeek day = dateTimePicker1.Value.DayOfWeek;
                                        Tuple<int, int> hours = timetable.GetTupleForDayOfWeek(day);
                                        string from;
                                        if (hours.Item1 < 10) from = "0" + hours.Item1;
                                        else from = "" + hours.Item1;
                                        string to = hours.Item2 + "";
                                        if (hours.Item2 < 10) to = "0" + hours.Item2;
                                        else to = "" + hours.Item2;
                                        comboBox1.SelectedIndex = comboBox1.FindString("" + from);
                                        comboBox2.SelectedIndex = comboBox2.FindString("" + to);
                                        timetableToSave = timetable;
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }