45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Flexitime.Objects.API;
|
|
using FlexitimeAPI.Exceptions;
|
|
using FlexitimeAPI.Helpers;
|
|
using FlexitimeAPI.Interfaces;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
|
|
namespace FlexitimeAPI.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class IdentifierController : ControllerBase
|
|
{
|
|
private readonly IIdentifierService _identifierService;
|
|
|
|
public IdentifierController(IIdentifierService identifierService)
|
|
{
|
|
_identifierService = identifierService;
|
|
}
|
|
|
|
[Authorize] //permission?
|
|
[HttpPost]
|
|
public async Task<IActionResult> Associate(AssociateIdentifierRequest associateIdentifierRequest)
|
|
{
|
|
try
|
|
{
|
|
await _identifierService.Associate(associateIdentifierRequest.Identifier,
|
|
associateIdentifierRequest.UserId);
|
|
return Ok();
|
|
}
|
|
catch (InvalidUserIdException iUidEx)
|
|
{
|
|
var modelStateDictionary = new ModelStateDictionary();
|
|
modelStateDictionary.AddModelError(nameof(Flexitime.Objects.User.Id), iUidEx.Message);
|
|
|
|
return BadRequest(modelStateDictionary);
|
|
}
|
|
}
|
|
}
|
|
}
|