Skip to content

Commit

Permalink
Merge pull request #204 from kzi-nastava/feat/update-course
Browse files Browse the repository at this point in the history
Update CourseDTO class
  • Loading branch information
darinkaloncar authored Apr 29, 2024
2 parents 9025b70 + 4d44af9 commit c3fd9d7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 97 deletions.
122 changes: 29 additions & 93 deletions LangLang/DTO/CourseDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class CourseDTO : INotifyPropertyChanged, IDataErrorInfo
private List<DayOfWeek> days;
private bool online;
private int maxStudents;
private DateTime startDateTime;
private DateTime startDate;
private bool createdByDirector;
private string time;
private bool mon;
Expand Down Expand Up @@ -143,18 +143,18 @@ public string Time
}
}

public DateTime StartDateTime
public DateTime StartDate
{
get
{
return startDateTime;
return startDate;
}
set
{
if (value != startDateTime)
if (value != startDate)
{
startDateTime = value;
OnPropertyChanged("StartDateTime");
startDate = value;
OnPropertyChanged("StartDate");
}
}
}
Expand Down Expand Up @@ -294,10 +294,10 @@ public string this[string columnName]
if (timeParts.Length != 2) return "Time format must be HH:mm";
else return "";
}
if (columnName == "StartDateTime")
if (columnName == "StartDate")
{
if (startDateTime < DateTime.Now) return "Please enter a valid date. Dates in the past are not allowed.";
if (startDateTime == default) return "Birth date is required";
if (startDate < DateTime.Now) return "Please enter a valid date. Dates in the past are not allowed.";
if (startDate == default) return "Birth date is required";
else return "";
}
if (columnName == "NumberOfWeeks")
Expand All @@ -313,19 +313,21 @@ public string this[string columnName]
return "";
}
}

private string[] _validatedProperties = {"StartDate", "Language", "Level", "NumberOfWeeks", "Time" };

public string ConcatenatedDays
{
get { return string.Join(", ", Days); }
}

private string[] _validatedProperties = { "StartDateTime", "Language", "Level", "NumberOfWeeks", "Time" };

// checks if all properties are valid
public bool IsValid
{
get
{
if (online == false)
// if the course is held in person add validation for maximal number of student, otherwize remove it
if (online == false)
{
_validatedProperties = _validatedProperties.Append("MaxStudents").ToArray();
}
Expand All @@ -345,37 +347,22 @@ public bool IsValid
_validatedProperties = newArray;
}
}
days = new List<DayOfWeek>();
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;
if (this[property] != "") return false;
}

List<DayOfWeek> _days = new List<DayOfWeek>();

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;
days = _days;
return true;
}
}
Expand All @@ -399,7 +386,7 @@ public Course ToCourse()
string[] timeParts = time.Split(':');
int hour = int.Parse(timeParts[0]);
int minute = int.Parse(timeParts[1]);
return new Course(Id, tutorId, language, level, numberOfWeeks, days, online, maxStudents, new DateTime(startDateTime.Year, startDateTime.Month, startDateTime.Day, hour, minute, 0), createdByDirector);
return new Course(Id, tutorId, language, level, numberOfWeeks, days, online, maxStudents, new DateTime(startDate.Year, startDate.Month, startDate.Day, hour, minute, 0), createdByDirector);
}

public CourseDTO(Course course)
Expand All @@ -412,59 +399,8 @@ public CourseDTO(Course course)
TutorId = course.TutorId;
Days = course.Days;
NumberOfStudents = course.NumberOfStudents;
StringBuilder sbDays = new StringBuilder();
if (Days.Contains(DayOfWeek.Monday))
{
Mon = true;
sbDays.Append("Mon ");
}
else
{
Mon = false;
}
if (Days.Contains(DayOfWeek.Tuesday))
{
Tue = true;
sbDays.Append("Tue ");
}
else
{
Tue = false;
}
if (Days.Contains(DayOfWeek.Wednesday))
{
Wed = true;
sbDays.Append("Wed ");
}
else
{
Wed = false;
}
if (Days.Contains(DayOfWeek.Thursday))
{
Thu = true;
sbDays.Append("Thu ");
}
else
{
Thu = false;
}
if (Days.Contains(DayOfWeek.Friday))
{
Fri = true;
sbDays.Append("Fri ");
}
else
{
Fri = false;
}
// Deletes the last white space from stringbuilder
if (sbDays.Length > 0)
{
sbDays.Remove(sbDays.Length - 1, 1);
}
StringDays = sbDays.ToString();
StartDateTime = course.StartDateTime;
StringDays = ConcatenatedDays;
StartDate = course.StartDateTime;
NumberOfWeeks = course.NumberOfWeeks.ToString();
MaxStudents = course.MaxStudents.ToString();
Time = course.StartDateTime.ToString("HH:mm");
Expand Down
2 changes: 1 addition & 1 deletion LangLang/View/CourseGUI/CourseCreateWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
</Label.Background>
</Label>
<DatePicker Margin="5,0,5,0" x:Name="startDateDp" Background="#FFFFDDDD"
SelectedDate="{Binding Path=Course.StartDateTime, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, StringFormat={}{0:MM/dd/yyyy}}"
SelectedDate="{Binding Path=Course.StartDate, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, StringFormat={}{0:MM/dd/yyyy}}"
Validation.ErrorTemplate="{StaticResource ValidationTemplate}" Grid.ColumnSpan="2" />

<Label Margin="5,20,5,0" x:Name="classTimeLbl" Content="Class time" FontStyle="Italic" Foreground="Black" RenderTransformOrigin="0.5,0.5" FontFamily="Arial" FontWeight="Bold">
Expand Down
2 changes: 1 addition & 1 deletion LangLang/View/CourseGUI/CourseUpdateWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
</Label.Background>
</Label>
<DatePicker Margin="5,0,5,0" x:Name="startDateDp" Background="#FFFFDDDD"
SelectedDate="{Binding Path=Course.StartDateTime, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
SelectedDate="{Binding Path=Course.StartDate, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
Validation.ErrorTemplate="{StaticResource ValidationTemplate}" Grid.ColumnSpan="2" />

<Label Margin="5,20,5,0" x:Name="classTimeLbl" Content="Class time" FontStyle="Italic" Foreground="Black" RenderTransformOrigin="0.5,0.5" FontFamily="Arial" FontWeight="Bold">
Expand Down
2 changes: 1 addition & 1 deletion LangLang/View/TutorWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</StackPanel>

<!--table for courses-->
<DataGrid EnableRowVirtualization="False" CanUserAddRows="False" AutoGenerateColumns="False" x:Name="coursesTable" Margin="15,45,15,0" SelectedItem="{Binding SelectedCourse, UpdateSourceTrigger=PropertyChanged}" SelectionChanged="coursesTable_SelectionChanged">
<DataGrid EnableRowVirtualization="False" CanUserAddRows="False" AutoGenerateColumns="False" x:Name="coursesTable" Margin="15,45,15,0" SelectedItem="{Binding SelectedCourse, UpdateSourceTrigger=PropertyChanged}" SelectionChanged="CoursesTable_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn x:Name="idColumn" IsReadOnly="True" Header="Id" Binding="{Binding Id}"/>
<DataGridTextColumn IsReadOnly="True" Header="Language" Binding="{Binding Language}"/>
Expand Down
20 changes: 19 additions & 1 deletion LangLang/View/TutorWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,25 @@ private void CourseDeleteBtn_Click(object sender, RoutedEventArgs e)
MessageBox.Show("Selected course cannot be deleted, it has already started or there are less than 7 days before course start.");
}
}
private void coursesTable_SelectionChanged(object sender, SelectionChangedEventArgs e)

private void CoursesTable_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (SelectedCourse == null)
{
disableButtonsCourse();
}
else
{
enableButtonsCourse();
}
}

private void disableButtonsCourse()
{
courseUpdateBtn.IsEnabled = false;
courseDeleteBtn.IsEnabled = false;
}
private void enableButtonsCourse()
{
courseUpdateBtn.IsEnabled = true;
courseDeleteBtn.IsEnabled = true;
Expand Down

0 comments on commit c3fd9d7

Please sign in to comment.