public ICommandResult Handle(DeleteServerCommand command) { command.Validate(); if (command.IsInvalid) { return(new DefaultCommandResult(CommandResultStatus.InvalidCommand, command.Notifications)); } try { var server = _serverRepository.GetById(command.ServerId); if (server == null) { return(new DefaultCommandResult(CommandResultStatus.InvalidData, "Nenhum servidor foi localizado")); } _serverRepository.Delete(server); return(new DefaultCommandResult(server.Id)); } catch (Exception e) { Console.WriteLine($"Fail to execute DeleteServerHandler. Fail stack ===> {e.ToString()}"); return(new DefaultCommandResult(CommandResultStatus.Exception)); } }
public async Task RemoveServer(string host) { using (Context.Channel.EnterTypingState()) { var result = await _serverRepository.Delete(Context.Guild.Id, host); if (result) { await ReplyAsync("Server deleted"); } else { await ReplyAsync("Failed to delete server."); } } }
public async Task <DeleteServerCommandResponse> Handle(DeleteServerCommand request, CancellationToken cancellationToken) { if (request.ServerId == Guid.Empty) { return(new DeleteServerCommandResponse(false, "Identificador do servidor é obrigatório.")); } var result = _serverRepository.Delete(request.ServerId); await _serverRepository.SaveChangesAsync(); if (result) { _logger.LogInformation("Servidor {0} excluído.", request.ServerId); return(new DeleteServerCommandResponse(result, null)); } return(new DeleteServerCommandResponse(false, $"Não foi encontrado servidor com identificador {request.ServerId}")); }
public void Remove(Server server) { _serverRepoitory.Delete(server); _unitOfWork.Commit(); }