Browse Source

Add Children query by parentID

master
Daniel Gyulai 4 years ago
parent
commit
b24c8606ff
  1. 1
      CoviDok/BLL/User/Handlers/IChildHandler.cs
  2. 10
      CoviDok/BLL/User/Managers/ChildManager.cs
  3. 8
      CoviDok/Controllers/ChildController.cs
  4. 5
      CoviDok/Data/MySQL/MySqlChildHandler.cs

1
CoviDok/BLL/User/Handlers/IChildHandler.cs

@ -13,5 +13,6 @@ namespace CoviDok.BLL.User.Managers
public Task<Child> GetChild(int id);
public Task UpdateChild(int id, Child newData);
public Task<int> AddChild(Child newChild);
public List<Child> GetChildren(int parentID);
}
}

10
CoviDok/BLL/User/Managers/ChildManager.cs

@ -26,6 +26,16 @@ namespace CoviDok.Data.MySQL
throw new UnauthorizedAccessException();
}
}
public List<PublicChild> ChildrenOfParent(int parentID)
{
List<PublicChild> ret = new List<PublicChild>();
foreach (Child child in handler.GetChildren(parentID))
{
ret.Add(child.ToPublic());
}
return ret;
}
public async Task UpdateChild(Session s, int id, PublicChild newData)
{

8
CoviDok/Controllers/ChildController.cs

@ -66,6 +66,14 @@ namespace CoviDok.Controllers
}
}
[HttpPost("parent")]
public async Task<ActionResult<List<PublicChild>>> GetChildrenOfParent(AuthGet auth)
{
Session s = await Handler.GetSession(auth.SessionID);
if (s == null) return Unauthorized();
return ChildManager.ChildrenOfParent(s.ID);
}
// POST: api/Child
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.

5
CoviDok/Data/MySQL/MySqlChildHandler.cs

@ -23,6 +23,11 @@ namespace CoviDok.Data.MySQL
return await context.Children.FindAsync(id);
}
public List<Child> 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 = new Child { Id = id };

Loading…
Cancel
Save