feat(attendance): add SetCountsAsync to set all three age groups for a date
This commit is contained in:
@@ -82,6 +82,24 @@ public class MealAttendanceService : IMealAttendanceService
|
||||
return await ReadAsync(date);
|
||||
}
|
||||
|
||||
public async Task<AttendanceCountsDto> SetCountsAsync(DateOnly date, int adult, int youth, int kid)
|
||||
{
|
||||
var row = await _db.MealAttendances.FirstOrDefaultAsync(a => a.AttendanceDate == date);
|
||||
if (row is null)
|
||||
{
|
||||
row = new MealAttendance { AttendanceDate = date };
|
||||
_db.MealAttendances.Add(row);
|
||||
}
|
||||
|
||||
// Counts can never be negative; clamp before writing.
|
||||
row.AdultCount = adult < 0 ? 0 : adult;
|
||||
row.YouthCount = youth < 0 ? 0 : youth;
|
||||
row.KidCount = kid < 0 ? 0 : kid;
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
return ToDto(row);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<AttendanceCountsDto>> GetRangeAsync(DateOnly from, DateOnly to)
|
||||
{
|
||||
var rows = await _db.MealAttendances.AsNoTracking()
|
||||
|
||||
Reference in New Issue
Block a user