Browse Source

Change Update method on MySql handlers

master
Daniel Gyulai 4 years ago
parent
commit
893fc8d3b5
  1. 5
      CoviDok/Data/MySQL/MySqlAssistantHandler.cs
  2. 3
      CoviDok/Data/MySQL/MySqlCaseHandler.cs
  3. 3
      CoviDok/Data/MySQL/MySqlChildHandler.cs
  4. 3
      CoviDok/Data/MySQL/MySqlDoctorHandler.cs
  5. 3
      CoviDok/Data/MySQL/MySqlParentHandler.cs

5
CoviDok/Data/MySQL/MySqlAssistantHandler.cs

@ -19,9 +19,8 @@ namespace CoviDok.Data.MySQL
} }
public async Task SetAssistant(int id, Assistant value) public async Task SetAssistant(int id, Assistant value)
{ {
Assistant ast = new Assistant { Id = id }; Assistant ast = await context.Assistants.FindAsync(id);
context.Attach(ast);
context.Entry(ast).State = EntityState.Modified; context.Entry(ast).State = EntityState.Modified;
PropertyCopier<Assistant>.Copy(value, ast); PropertyCopier<Assistant>.Copy(value, ast);
await context.SaveChangesAsync(); await context.SaveChangesAsync();

3
CoviDok/Data/MySQL/MySqlCaseHandler.cs

@ -76,8 +76,7 @@ namespace CoviDok.Data.MySQL
public async Task UpdateCase(int id, Case Case, Update update) public async Task UpdateCase(int id, Case Case, Update update)
{ {
Case c = new Case { Id = id }; Case c = await context.Cases.FindAsync(id);
context.Attach(c);
context.Entry(c).State = Microsoft.EntityFrameworkCore.EntityState.Modified; context.Entry(c).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
string[] forbidden = { "Updates" }; string[] forbidden = { "Updates" };
PropertyCopier<Case>.Copy(Case, c, forbidden); PropertyCopier<Case>.Copy(Case, c, forbidden);

3
CoviDok/Data/MySQL/MySqlChildHandler.cs

@ -30,8 +30,7 @@ namespace CoviDok.Data.MySQL
public async Task UpdateChild(int id, Child newData) public async Task UpdateChild(int id, Child newData)
{ {
Child child = new Child { Id = id }; Child child = await context.Children.FindAsync(id);
context.Attach(child);
context.Entry(child).State = Microsoft.EntityFrameworkCore.EntityState.Modified; context.Entry(child).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
PropertyCopier<Child>.Copy(newData, child); PropertyCopier<Child>.Copy(newData, child);
await context.SaveChangesAsync(); await context.SaveChangesAsync();

3
CoviDok/Data/MySQL/MySqlDoctorHandler.cs

@ -52,8 +52,7 @@ namespace CoviDok.Data.MySQL
public async Task UpdateDoctor(int id, Doctor value) public async Task UpdateDoctor(int id, Doctor value)
{ {
Doctor doctor = new Doctor { Id = id }; Doctor doctor = await context.Doctors.FindAsync(id);
context.Attach(doctor);
context.Entry(doctor).State = Microsoft.EntityFrameworkCore.EntityState.Modified; context.Entry(doctor).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
PropertyCopier<Doctor>.Copy(value, doctor); PropertyCopier<Doctor>.Copy(value, doctor);
await context.SaveChangesAsync(); await context.SaveChangesAsync();

3
CoviDok/Data/MySQL/MySqlParentHandler.cs

@ -29,8 +29,7 @@ namespace CoviDok.Data.MySQL
public async Task UpdateParent(int id, Parent value) public async Task UpdateParent(int id, Parent value)
{ {
Parent Parent = new Parent { Id = id }; Parent Parent = await context.Parents.FindAsync(id);
context.Attach(Parent);
context.Entry(Parent).State = Microsoft.EntityFrameworkCore.EntityState.Modified; context.Entry(Parent).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
PropertyCopier<Parent>.Copy(value, Parent); PropertyCopier<Parent>.Copy(value, Parent);
await context.SaveChangesAsync(); await context.SaveChangesAsync();

Loading…
Cancel
Save