public Int32 Delete(BANCO item, LOG log) { using (DbContextTransaction transaction = Db.Database.BeginTransaction(IsolationLevel.ReadCommitted)) { try { _logRepository.Add(log); _baseRepository.Remove(item); transaction.Commit(); return(0); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }
public Task <CommandResult> Handle(RemoveBancoCommand command, CancellationToken cancellationToken) { if (!command.IsValid()) { NotifyCommandErrors(command); return(Response()); } Banco banco = _bancoRepository.GetById(command.Id); _bancoRepository.Remove(banco); if (Commit()) { _mediator.Publish(new RemovedBancoEvent()); } return(Response()); }
public async Task <BancoResponse> DeleteAsync(int bancoId) { var existingBanco = await _bancoRepository.FindByIdAsync(bancoId); if (existingBanco == null) { return(new BancoResponse(_localizer["BancoNotFound"])); } try { _bancoRepository.Remove(existingBanco); await _unitOfWork.CompleteAsync(); return(new BancoResponse(existingBanco)); } catch (Exception ex) { // Do some logging stuff // return new BancoResponse($"An error occurred when deleting the banco: {ex.Message}"); return(new BancoResponse(_localizer["BancoErrorEliminando"] + ex.Message)); } }