dotnet-digital-ops/DigitalOps.CQRS/Services/TimeEntry/TimeEntryService.cs

30 lines
944 B
C#

using DigitalOps.Authority.Services;
using DigitalOps.CQRS.Services.TimeEntry.Options;
using DigitalOps.Dal;
using DigitalOps.Dal.DbEntity;
namespace DigitalOps.CQRS.Services.TimeEntry;
public class TimeEntryService(MainDbContext dbContext, UserIdentityService userIdentityService)
{
public async Task AddTimeEntryAsync(AddTimeEntryOptions options, CancellationToken cancellationToken = default)
{
var user = await userIdentityService.GetUserOrDefaultAsync(cancellationToken);
if (user is null)
return;
var timeEntry = new ProjectTimeEntry
{
ProjectId = options.ProjectId,
EntryUserId = user.Id,
UserId = options.ForUser ?? user.Id,
Description = options.Description,
Offset = options.Offset,
StartedAt = options.StartAt,
EndedAt = options.EndAt
};
dbContext.ProjectTimeEntries.Add(timeEntry);
await dbContext.SaveChangesAsync(cancellationToken);
}
}