Try-Catch zu UserController hinzugefügt
This commit is contained in:
parent
2687837f2b
commit
3a0edfe956
@ -2,8 +2,6 @@ using DigitalData.Core.API;
|
|||||||
using DigitalData.UserManager.Application.Contracts;
|
using DigitalData.UserManager.Application.Contracts;
|
||||||
using DigitalData.UserManager.Application.DTOs.User;
|
using DigitalData.UserManager.Application.DTOs.User;
|
||||||
using DigitalData.UserManager.Domain.Entities;
|
using DigitalData.UserManager.Domain.Entities;
|
||||||
using DigitalData.UserManager.Infrastructure.Contracts;
|
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@ -18,41 +16,73 @@ namespace DigitalData.UserManager.API.Controllers
|
|||||||
|
|
||||||
[HttpGet("ByModuleId/{moduleId}")]
|
[HttpGet("ByModuleId/{moduleId}")]
|
||||||
public async Task<IActionResult> GetByModuleId([FromRoute] int moduleId, [FromQuery]bool assigned = true)
|
public async Task<IActionResult> GetByModuleId([FromRoute] int moduleId, [FromQuery]bool assigned = true)
|
||||||
{
|
{
|
||||||
var result = assigned ? await _service.ReadByModuleIdAsync(moduleId) : await _service.ReadUnassignedByModuleIdAsync(moduleId);
|
try
|
||||||
return Ok(result);
|
{
|
||||||
|
var result = assigned ? await _service.ReadByModuleIdAsync(moduleId) : await _service.ReadUnassignedByModuleIdAsync(moduleId);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "{Message}", ex.Message);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("ByGroupId/{groupId}")]
|
[HttpGet("ByGroupId/{groupId}")]
|
||||||
public async Task<IActionResult> GetByGroupId([FromRoute] int groupId, [FromQuery] bool assigned = true)
|
public async Task<IActionResult> GetByGroupId([FromRoute] int groupId, [FromQuery] bool assigned = true)
|
||||||
{
|
{
|
||||||
var result = assigned ? await _service.ReadByGroupIdAsync(groupId) : await _service.ReadUnassignedByGroupIdAsync(groupId); ;
|
try
|
||||||
return Ok(result);
|
{
|
||||||
|
var result = assigned ? await _service.ReadByGroupIdAsync(groupId) : await _service.ReadUnassignedByGroupIdAsync(groupId); ;
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "{Message}", ex.Message);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("ByDir")]
|
[HttpPost("ByDir")]
|
||||||
public async Task<IActionResult> CreateByDir(UserPrincipalDto upDto)
|
public async Task<IActionResult> CreateByDir(UserPrincipalDto upDto)
|
||||||
{
|
{
|
||||||
var result = await _service.CreateAsync(upDto);
|
try
|
||||||
if (result.IsSuccess)
|
|
||||||
{
|
{
|
||||||
var createdResource = new { Id = result.Data };
|
var result = await _service.CreateAsync(upDto);
|
||||||
var actionName = nameof(GetById);
|
if (result.IsSuccess)
|
||||||
var routeValues = new { id = createdResource.Id };
|
{
|
||||||
return CreatedAtAction(actionName, routeValues, createdResource);
|
var createdResource = new { Id = result.Data };
|
||||||
|
var actionName = nameof(GetById);
|
||||||
|
var routeValues = new { id = createdResource.Id };
|
||||||
|
return CreatedAtAction(actionName, routeValues, createdResource);
|
||||||
|
}
|
||||||
|
return BadRequest(result);
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "{Message}", ex.Message);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
}
|
}
|
||||||
return BadRequest(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("ByUsername/{username}")]
|
[HttpGet("ByUsername/{username}")]
|
||||||
public virtual async Task<IActionResult> GetByUsername([FromRoute] string username)
|
public virtual async Task<IActionResult> GetByUsername([FromRoute] string username)
|
||||||
{
|
{
|
||||||
var result = await _service.ReadByUsernameAsync(username);
|
try
|
||||||
if (result.IsSuccess)
|
|
||||||
{
|
{
|
||||||
return Ok(result);
|
var result = await _service.ReadByUsernameAsync(username);
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
return NotFound(result);
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "{Message}", ex.Message);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
}
|
}
|
||||||
return NotFound(result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user