private void BtnWorkingHourSave_Click(object sender, RoutedEventArgs e) { if (ProjectsList.SelectedItem == null) { MessageBox.Show("No project selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (EmployeePicker.SelectedItem == null) { MessageBox.Show("No employee selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (WorkDatePicker.SelectedDate == null || WorkDatePicker.SelectedDate > DateTime.Now) { MessageBox.Show("No date selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (!int.TryParse(StartingHourBox.Text, out int startingHour) || !int.TryParse(EndingHourBox.Text, out int endingHour)) { MessageBox.Show("No hour selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (startingHour > 24 || startingHour < 0 || endingHour > 24 || startingHour < 0 || (endingHour <= startingHour)) { MessageBox.Show("Wrong hours", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } Project project = Projects.GetProjects().Where(x => x.Name == ProjectsList.SelectedItem.ToString()).First(); WorkTime wt = new WorkTime(project, (DateTime)WorkDatePicker.SelectedDate, startingHour, endingHour); string[] name = EmployeePicker.SelectedItem.ToString().Split(' '); Employee emp = EmployeeController.Employees.Where(x => x.FirstName == name[0] && x.LastName == name[1]).First(); emp.AddWorkTime(wt); EmployeeController.SerializeEmployee(emp); MessageBox.Show("WorkTime saved!", "Saved", MessageBoxButton.OK); }
public void AddWorkTime(WorkTime wt) { WorkTimes.Add(wt); }