FlexitimeTracker/FlexitimeUI/FlexitimeAPI/Services/IdentifierService.cs
2023-04-11 20:17:20 +01:00

31 lines
811 B
C#

using System;
using System.Threading.Tasks;
using Flexitime.Objects;
using FlexitimeAPI.Exceptions;
using FlexitimeAPI.Interfaces;
namespace FlexitimeAPI.Services
{
public class IdentifierService : IIdentifierService
{
private readonly IUserService _userService;
public IdentifierService(IUserService userService)
{
_userService = userService;
}
public async Task Associate(Identifier identifier, Guid userId)
{
var user = await _userService.GetById(userId);
if (user == null)
{
throw new InvalidUserIdException(userId);
}
user.AssociatedIdentifiers.Add(identifier);
await _userService.Update(user);
}
}
}