Update
This commit is contained in:
@@ -21,4 +21,8 @@ public interface IOfferingSessionService
|
||||
Task SaveProofAsync(int id, Stream content, string fileName);
|
||||
Task<(Stream stream, string contentType)?> OpenProofAsync(int id);
|
||||
Task DeleteProofAsync(int id);
|
||||
|
||||
// Date-keyed variants for the anonymous mobile page (knows the date, not the id).
|
||||
Task SaveProofForDateAsync(DateOnly date, Stream content, string fileName);
|
||||
Task<(Stream stream, string contentType)?> OpenProofForDateAsync(DateOnly date);
|
||||
}
|
||||
|
||||
@@ -183,6 +183,7 @@ public class OfferingSessionService : IOfferingSessionService
|
||||
Status = session.Status,
|
||||
SystemTotal = session.SystemTotal,
|
||||
LineCount = lines.Count,
|
||||
HasProof = session.ProofPdfPath != null,
|
||||
Lines = await BuildLineDtosAsync(lines),
|
||||
};
|
||||
}
|
||||
@@ -339,6 +340,39 @@ public class OfferingSessionService : IOfferingSessionService
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// ── Date-keyed proof (anonymous mobile page knows the date, not the id) ──
|
||||
|
||||
// Attach a proof PDF to the date's session, creating a Draft session if none
|
||||
// exists yet (the volunteer may snap the count sheet before any line is keyed).
|
||||
public async Task SaveProofForDateAsync(DateOnly date, Stream content, string fileName)
|
||||
{
|
||||
var session = await _db.OfferingSessions.FirstOrDefaultAsync(s => s.SessionDate == date);
|
||||
if (session is null)
|
||||
{
|
||||
session = new OfferingSession { SessionDate = date, Status = "Draft" };
|
||||
_db.OfferingSessions.Add(session);
|
||||
try
|
||||
{
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
// Lost the create race — another phone inserted today's session first.
|
||||
_db.ChangeTracker.Clear();
|
||||
session = await _db.OfferingSessions.FirstAsync(s => s.SessionDate == date);
|
||||
}
|
||||
}
|
||||
await SaveProofAsync(session.Id, content, fileName);
|
||||
}
|
||||
|
||||
public async Task<(Stream stream, string contentType)?> OpenProofForDateAsync(DateOnly date)
|
||||
{
|
||||
var session = await _db.OfferingSessions.AsNoTracking()
|
||||
.FirstOrDefaultAsync(s => s.SessionDate == date);
|
||||
if (session is null) return null;
|
||||
return await OpenProofAsync(session.Id);
|
||||
}
|
||||
|
||||
private static Giving MapLine(OfferingGivingLineRequest line, DateOnly sessionDate) => new()
|
||||
{
|
||||
MemberId = line.IsAnonymous ? null : line.MemberId,
|
||||
|
||||
Reference in New Issue
Block a user