forked from ReiMerc/skantravels
30 lines
907 B
C#
30 lines
907 B
C#
using AuthorizationService.Models;
|
|
using AuthorizationService.Persistence.Repositories;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace AuthorizationService.Application.Users.Commands
|
|
{
|
|
public class DeleteUser
|
|
{
|
|
private readonly IUserRepository _repository;
|
|
|
|
public DeleteUser(IUserRepository repository)
|
|
{
|
|
_repository = repository;
|
|
}
|
|
|
|
public async Task<IActionResult> Handle(string id)
|
|
{
|
|
User currentUser = await _repository.QueryUserByIdAsync(id);
|
|
if (currentUser == null)
|
|
return new ConflictObjectResult(new { message = "User dosent exist." });
|
|
|
|
bool success = await _repository.DeleteUserAsync(id);
|
|
if (success)
|
|
return new OkResult();
|
|
else
|
|
return new StatusCodeResult(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
}
|