using CoviDok.BLL; using CoviDok.BLL.Sessions; 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(); } public bool IsAuthorized(Session s, Child c) { if (s.Id == c.DoctorId || s.Id == c.ParentId) return true; // Ha van olyan Asszisztens, akinek; // - a dokija egyezik az ügy dokijával // - azonosítója a bejelentezett user azonosítója return (context.Assistants.Any(a => a.Id == s.Id && a.DoctorId == c.DoctorId)); } } }