using CoviDok.BLL; using CoviDok.BLL.User.Managers; using CoviDok.Data.Model; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace CoviDok.Data.MySQL { public class MySqlChildHandler : IChildHandler { private readonly MySqlContext context = new MySqlContext(); public async Task AddChild(Child child) { context.Children.Add(child); await context.SaveChangesAsync(); return child.Id; } public async Task GetChild(int id) { return await context.Children.FindAsync(id); } public List GetChildren(int parentID) { return (from c in context.Children where c.ParentId == parentID select c).ToList(); } public async Task UpdateChild(int id, Child newData) { Child child = await context.Children.FindAsync(id); context.Entry(child).State = Microsoft.EntityFrameworkCore.EntityState.Modified; PropertyCopier.Copy(newData, child); await context.SaveChangesAsync(); } } }