From 893fc8d3b54d5aa811c02b7ffa5d57a297e58f7f Mon Sep 17 00:00:00 2001 From: Daniel Gyulai Date: Thu, 19 Nov 2020 17:20:28 +0100 Subject: [PATCH] Change Update method on MySql handlers --- CoviDok/Data/MySQL/MySqlAssistantHandler.cs | 5 ++--- CoviDok/Data/MySQL/MySqlCaseHandler.cs | 3 +-- CoviDok/Data/MySQL/MySqlChildHandler.cs | 3 +-- CoviDok/Data/MySQL/MySqlDoctorHandler.cs | 3 +-- CoviDok/Data/MySQL/MySqlParentHandler.cs | 3 +-- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/CoviDok/Data/MySQL/MySqlAssistantHandler.cs b/CoviDok/Data/MySQL/MySqlAssistantHandler.cs index 4adabac..bb9fff9 100644 --- a/CoviDok/Data/MySQL/MySqlAssistantHandler.cs +++ b/CoviDok/Data/MySQL/MySqlAssistantHandler.cs @@ -19,9 +19,8 @@ namespace CoviDok.Data.MySQL } public async Task SetAssistant(int id, Assistant value) - { - Assistant ast = new Assistant { Id = id }; - context.Attach(ast); + { + Assistant ast = await context.Assistants.FindAsync(id); context.Entry(ast).State = EntityState.Modified; PropertyCopier.Copy(value, ast); await context.SaveChangesAsync(); diff --git a/CoviDok/Data/MySQL/MySqlCaseHandler.cs b/CoviDok/Data/MySQL/MySqlCaseHandler.cs index 4b80337..b186371 100644 --- a/CoviDok/Data/MySQL/MySqlCaseHandler.cs +++ b/CoviDok/Data/MySQL/MySqlCaseHandler.cs @@ -76,8 +76,7 @@ namespace CoviDok.Data.MySQL public async Task UpdateCase(int id, Case Case, Update update) { - Case c = new Case { Id = id }; - context.Attach(c); + Case c = await context.Cases.FindAsync(id); context.Entry(c).State = Microsoft.EntityFrameworkCore.EntityState.Modified; string[] forbidden = { "Updates" }; PropertyCopier.Copy(Case, c, forbidden); diff --git a/CoviDok/Data/MySQL/MySqlChildHandler.cs b/CoviDok/Data/MySQL/MySqlChildHandler.cs index c55b473..4a20120 100644 --- a/CoviDok/Data/MySQL/MySqlChildHandler.cs +++ b/CoviDok/Data/MySQL/MySqlChildHandler.cs @@ -30,8 +30,7 @@ namespace CoviDok.Data.MySQL public async Task UpdateChild(int id, Child newData) { - Child child = new Child { Id = id }; - context.Attach(child); + Child child = await context.Children.FindAsync(id); context.Entry(child).State = Microsoft.EntityFrameworkCore.EntityState.Modified; PropertyCopier.Copy(newData, child); await context.SaveChangesAsync(); diff --git a/CoviDok/Data/MySQL/MySqlDoctorHandler.cs b/CoviDok/Data/MySQL/MySqlDoctorHandler.cs index d03e637..7fefe8e 100644 --- a/CoviDok/Data/MySQL/MySqlDoctorHandler.cs +++ b/CoviDok/Data/MySQL/MySqlDoctorHandler.cs @@ -52,8 +52,7 @@ namespace CoviDok.Data.MySQL public async Task UpdateDoctor(int id, Doctor value) { - Doctor doctor = new Doctor { Id = id }; - context.Attach(doctor); + Doctor doctor = await context.Doctors.FindAsync(id); context.Entry(doctor).State = Microsoft.EntityFrameworkCore.EntityState.Modified; PropertyCopier.Copy(value, doctor); await context.SaveChangesAsync(); diff --git a/CoviDok/Data/MySQL/MySqlParentHandler.cs b/CoviDok/Data/MySQL/MySqlParentHandler.cs index b5ceda0..6241127 100644 --- a/CoviDok/Data/MySQL/MySqlParentHandler.cs +++ b/CoviDok/Data/MySQL/MySqlParentHandler.cs @@ -29,8 +29,7 @@ namespace CoviDok.Data.MySQL public async Task UpdateParent(int id, Parent value) { - Parent Parent = new Parent { Id = id }; - context.Attach(Parent); + Parent Parent = await context.Parents.FindAsync(id); context.Entry(Parent).State = Microsoft.EntityFrameworkCore.EntityState.Modified; PropertyCopier.Copy(value, Parent); await context.SaveChangesAsync();