diff --git a/LangLang/Repositories/SqlRepositories/CourseRepository.cs b/LangLang/Repositories/SqlRepositories/CourseRepository.cs index 7bb2a67..0052725 100644 --- a/LangLang/Repositories/SqlRepositories/CourseRepository.cs +++ b/LangLang/Repositories/SqlRepositories/CourseRepository.cs @@ -1,5 +1,6 @@ using LangLang.Domain.Models; using LangLang.Domain.RepositoryInterfaces; +using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Linq; @@ -32,10 +33,17 @@ public void Add(Course course) public void Update(Course course) { + var existingCourse = _databaseContext.Course.Find(course.Id); + if (existingCourse != null) + { + _databaseContext.Entry(existingCourse).State = EntityState.Detached; + } + _databaseContext.Course.Update(course); _databaseContext.SaveChanges(); } + public void Delete(Course course) { var existingCourse = _databaseContext.Course.Find(course.Id); diff --git a/LangLang/WPF/Views/TutorView/AdditionalWindows/CourseView/CourseUpdateWindow.xaml.cs b/LangLang/WPF/Views/TutorView/AdditionalWindows/CourseView/CourseUpdateWindow.xaml.cs index 10b3dce..8dabdfe 100644 --- a/LangLang/WPF/Views/TutorView/AdditionalWindows/CourseView/CourseUpdateWindow.xaml.cs +++ b/LangLang/WPF/Views/TutorView/AdditionalWindows/CourseView/CourseUpdateWindow.xaml.cs @@ -21,7 +21,7 @@ public CourseUpdateWindow(Courses parent, Course course) CourseUpdateVM = new(course); DataContext = CourseUpdateVM; - languageLvlCb.ItemsSource = Enum.GetValues(typeof(LanguageLevel)); + languageLvlCb.ItemsSource = Enum.GetValues(typeof(Level)); } private void CourseUpdateBtn_Click(object sender, RoutedEventArgs e) diff --git a/LangLang/WPF/Views/TutorView/Tabs/Courses.xaml.cs b/LangLang/WPF/Views/TutorView/Tabs/Courses.xaml.cs index 99b91de..60283bd 100644 --- a/LangLang/WPF/Views/TutorView/Tabs/Courses.xaml.cs +++ b/LangLang/WPF/Views/TutorView/Tabs/Courses.xaml.cs @@ -63,7 +63,7 @@ private void CourseSearchWindowBtn_Click(object sender, RoutedEventArgs e) private void CourseUpdateWindowBtn_Click(object sender, RoutedEventArgs e) { - CoursesViewModel.Update(); + CoursesViewModel.UpdateCourse(); } private void CourseDeleteBtn_Click(object sender, RoutedEventArgs e)