Skip to content

Commit

Permalink
[Update] CourseDTO class
Browse files Browse the repository at this point in the history
  • Loading branch information
darinkaloncar committed Apr 1, 2024
1 parent d72bb76 commit b0ed147
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 54 deletions.
124 changes: 114 additions & 10 deletions LangLang/DTO/CourseDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,99 @@ public class CourseDTO : INotifyPropertyChanged, IDataErrorInfo
{

public int Id { get; set; }
public string ErrorStringForMaxStudents = "";
private int tutorId;
private string language;
private LanguageLevel level;
private int numberOfWeeks;
private List<DayOfWeek> days;
private List<DayOfWeek> days = new List<DayOfWeek>();
private bool online;
private int maxStudents;
private DateTime startDateTime;
private bool createdByDirector;
private string time;
private bool mon;
private bool tue;
private bool wed;
private bool thu;
private bool fri;


public bool Mon
{
get
{
return mon;
}
set
{
if (value != mon)
{
mon = value;
OnPropertyChanged("Mon");
}
}
}
public bool Tue
{
get
{
return tue;
}
set
{
if (value != tue)
{
tue = value;
OnPropertyChanged("Tue");
}
}
}
public bool Wed
{
get
{
return wed;
}
set
{
if (value != wed)
{
wed = value;
OnPropertyChanged("Wed");
}
}
}

public bool Thu
{
get
{
return thu;
}
set
{
if (value != thu)
{
thu = value;
OnPropertyChanged("Thu");
}
}
}
public bool Fri
{
get
{
return fri;
}
set
{
if (value != fri)
{
fri = value;
OnPropertyChanged("Fri");
}
}
}
public string Language
{
get
Expand Down Expand Up @@ -160,17 +241,17 @@ public int TutorId
}
}

public bool Online
public bool NotOnline
{
get
{
return online;
return !online;
}
set
{
if (value != online)
if (value == online)
{
online = value;
online = !value;
OnPropertyChanged("Online");
}
}
Expand Down Expand Up @@ -224,7 +305,7 @@ public string this[string columnName]
}
if (columnName == "MaxStudents")
{
if (!int.TryParse(MaxStudents, out int _maxStudents) || _maxStudents <= 0) return ErrorStringForMaxStudents;
if (!int.TryParse(MaxStudents, out int _maxStudents) || _maxStudents <= 0) return "Maximal number of students must be a positive number";
else return "";
}
return "";
Expand All @@ -238,7 +319,31 @@ public bool IsValid
{
get
{
foreach (var property in _validatedProperties)
if (mon)
{
days.Add(DayOfWeek.Monday);
}
if (tue)
{
days.Add(DayOfWeek.Tuesday);
}
if (wed)
{
days.Add(DayOfWeek.Wednesday);
}
if (thu)
{
days.Add(DayOfWeek.Thursday);
}
if (fri)
{
days.Add(DayOfWeek.Friday);
}
if (days.Count == 0)
{
return false;
}
foreach (var property in _validatedProperties)
{
if (this[property] != "")
return false;
Expand All @@ -252,7 +357,6 @@ public bool IsValid

public CourseDTO()
{
days = new List<DayOfWeek>();
}

public Course ToCourse()
Expand All @@ -268,7 +372,7 @@ public CourseDTO(Course course)
this.Id = course.Id;
Language = course.Language;
Level = course.Level;
Online = course.Online;
NotOnline = !course.Online;
CreatedByDirector = course.CreatedByDirector;
TutorId = course.TutorId;
Days = course.Days;
Expand Down
12 changes: 6 additions & 6 deletions LangLang/View/CourseGUI/CourseCreateWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@
</Label.Background>
</Label>
<ListBox x:Name="myListBox" SelectionMode="Multiple" Background="#FFFFF3F3" Margin="5,0,5,0" FontStyle="Italic" Foreground="Black" RenderTransformOrigin="0.5,0.5" FontFamily="Arial" FontWeight="Bold">
<CheckBox x:Name="mon" Content="Monday"/>
<CheckBox x:Name="tue" Content="Tuesday"/>
<CheckBox x:Name="wed" Content="Wednesday"/>
<CheckBox x:Name="thu" Content="Thursday"/>
<CheckBox x:Name="fri" Content="Friday"/>
<CheckBox IsChecked="{Binding Course.Mon, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" x:Name="mon" Content="Monday"/>
<CheckBox IsChecked="{Binding Course.Tue, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" x:Name="tue" Content="Tuesday"/>
<CheckBox IsChecked="{Binding Course.Wed, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" x:Name="wed" Content="Wednesday"/>
<CheckBox IsChecked="{Binding Course.Thu, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" x:Name="thu" Content="Thursday"/>
<CheckBox IsChecked="{Binding Course.Fri, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" x:Name="fri" Content="Friday"/>
</ListBox>

<!--label name and box for max number of students-->
Expand Down Expand Up @@ -239,7 +239,7 @@
</TextBox>

<!--label and box for online/live-->
<CheckBox Unchecked="ClasssroomCb_Unchecked" Checked="ClasssroomCb_Checked" x:Name="classsroomCb" Margin="5,20,5,0" Content="In Classroom" FontStyle="Italic" Foreground="Black" RenderTransformOrigin="0.5,0.5" FontFamily="Arial" FontWeight="Bold" />
<CheckBox IsChecked="{Binding Course.NotOnline, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True }" Unchecked="ClasssroomCb_Unchecked" Checked="ClasssroomCb_Checked" x:Name="classsroomCb" Margin="5,20,5,0" Content="In Classroom" FontStyle="Italic" Foreground="Black" RenderTransformOrigin="0.5,0.5" FontFamily="Arial" FontWeight="Bold" />

<!--button for create-->
<Button Click="CourseCreateBtn_Click" Margin="0,10,0,0" Height="30" Width="60" x:Name="courseCreateBtn" Content="Create" BorderBrush="White" Background="#FFFFDBDB" Foreground="#FF514141" FontFamily="Segoe UI Black"/>
Expand Down
49 changes: 11 additions & 38 deletions LangLang/View/CourseGUI/CourseCreateWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,25 @@ public CourseCreateWindow(CourseController courseController)
InitializeComponent();
DataContext = this;
languageLvlCb.ItemsSource = Enum.GetValues(typeof(LanguageLevel));
maxNumOfStudentsTb.IsEnabled = false;
classsroomCb.IsChecked = false;
mon.IsChecked = false;
tue.IsChecked = false;
wed.IsChecked = false;
thu.IsChecked = false;
fri.IsChecked = false;
}

private void CourseCreateBtn_Click(object sender, RoutedEventArgs e)
{
List<DayOfWeek> days = new List<DayOfWeek>();
if (mon.IsChecked == true)
{
days.Add(DayOfWeek.Monday);
}
if (tue.IsChecked == true)
{
days.Add(DayOfWeek.Tuesday);
}
if (wed.IsChecked == true)
{
days.Add(DayOfWeek.Wednesday);
}
if (thu.IsChecked == true)
{
days.Add(DayOfWeek.Thursday);
}
if (fri.IsChecked == true)
{
days.Add(DayOfWeek.Friday);
}
if (days.Count != 0)
if (Course.IsValid)
{
Course.Days = days;
Course.Online = classsroomCb.IsChecked == false;
if (Course.IsValid)
{
courseController.Add(Course.ToCourse());
MessageBox.Show("Success!");
Close();
}
else
{
MessageBox.Show("Something went wrong. Please check all fields in registration form.");
}
courseController.Add(Course.ToCourse());
MessageBox.Show("Success!");
Close();
}
else
{
MessageBox.Show("At least one day must be checked.");
MessageBox.Show("Something went wrong. Please check all fields in registration form.");
}

}
Expand All @@ -84,13 +59,11 @@ private void CourseCreateBtn_Click(object sender, RoutedEventArgs e)
private void ClasssroomCb_Checked(object sender, RoutedEventArgs e)
{
maxNumOfStudentsTb.IsEnabled = true;
Course.ErrorStringForMaxStudents = "";
}

private void ClasssroomCb_Unchecked(object sender, RoutedEventArgs e)
{
maxNumOfStudentsTb.IsEnabled = false;
Course.ErrorStringForMaxStudents = "Maximal number of students must be a positive number";
}
}
}

0 comments on commit b0ed147

Please sign in to comment.