Skip to content

Commit

Permalink
Merge pull request #468 from kzi-nastava/fix/update-course
Browse files Browse the repository at this point in the history
Fix: entity tracking issue and correct method invocation
  • Loading branch information
natasakasikovic authored Jun 16, 2024
2 parents 7803f1b + fe9ce0a commit fa8ca7c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions LangLang/Repositories/SqlRepositories/CourseRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using LangLang.Domain.Models;
using LangLang.Domain.RepositoryInterfaces;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion LangLang/WPF/Views/TutorView/Tabs/Courses.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fa8ca7c

Please sign in to comment.