public async Task <Cliente> Adicionar(Cliente cliente, CancellationToken ct) { if (!ExecutarValidacao(new ClienteValidation(), cliente)) { return(cliente); } if (_clienteRepository.FindByAsync(f => f.Documento == cliente.Documento, ct).Result.Any()) { Notificar("Já existe um cliente com este documento informado."); return(null); } // https://docs.microsoft.com/en-us/ef/core/miscellaneous/configuring-dbcontext // Using dependency injection, this can be achieved by either registering the context as scoped, and creating scopes(using IServiceScopeFactory) for each thread, or by registering the DbContext as transient (using the overload of AddDbContext which takes a ServiceLifetime parameter). // https://blog.hildenco.com/2018/12/accessing-entity-framework-context-on.html // 1 - forma de trabalhar com concorrencia //using (var scopoe = _scopeFactory.CreateScope()) //{ // var db = scopoe.ServiceProvider.GetRequiredService<LavanderiaContext>(); // await db.Clientes.AddAsync(cliente, ct); // await db.SaveChangesAsync(); //} await _clienteRepository.AddAsync(cliente, ct); await _unitOfWork.CommitAsync(ct); return(cliente); }
public async Task AddAsync(Cliente cliente) { try { cliente.Validar(); await _clienteRepository.AddAsync(cliente); } catch (Exception) { throw; } }
public async Task Save() { var cliente = SetupTests.GetCliente(2); cliente = await _repository.AddAsync(cliente); var result = await _repository.UpdateAsync(cliente); Assert.True(cliente.Equals(result)); }
public async Task <IActionResult> CreateAsync([FromBody] Cliente item) { if (item == null) { return(BadRequest()); } await _clienteRepository.AddAsync(item); return(CreatedAtRoute("GetCliente", new { id = item.IdCliente }, item)); }
public async Task <IActionResult> Incluir([FromBody] Cliente cliente) { try { await _clienteRepository.AddAsync(cliente); return(Ok()); } catch (System.Exception) { return(BadRequest()); } }
public async Task <bool> Criar(ClienteViewModel clienteViewModel) { var cliente = clienteViewModel.MapToEntity(); var clienteId = await _clienteRepository.AddAsync(cliente); if (clienteId <= 0) { return(false); } await _contatoService.Criar(clienteViewModel.Contatos, clienteId); return(true); }
public async Task <ICommandResult> Handle(CriarClienteCommand command, CancellationToken cancellationToken) { if (command.Invalid) { return(new CommandResult(false, "Dados Inválidos!", command.Notifications)); } Cliente cliente = new Cliente(command.Nome); cliente.AddTelefones(command._telefones); if (cliente.Invalid) { return(new CommandResult(false, "Dados Inválidos!", cliente.Notifications)); } await _clienteRepository.AddAsync(cliente); return(new CommandResult(true, $"O Cliente {cliente.Id} - {cliente.Nome} foi criado com sucesso!")); }
public async Task <Cliente> Adicionar(Cliente cliente, CancellationToken ct) { if (!ExecutarValidacao(new ClienteValidation(), cliente)) { return(cliente); } if (_clienteRepository.FindByAsync(f => f.Documento == cliente.Documento, ct).Result.Any()) { Notificar("Já existe um cliente com este documento informado."); return(cliente); } await _clienteRepository.AddAsync(cliente, ct); await _unitOfWork.CommitAsync(ct); return(cliente); }
public async Task <Cliente> Handle(CreateClienteCommand request, CancellationToken cancellationToken) { var cliente = new Cliente { Nombre = request.Nombre, Apellidos = request.Apellidos, FechaNaciemiento = request.FechaNaciemiento, Email = request.Email, Telefono = request.Telefono, Direccion = request.Direccion, DateCreated = request.DateCreated, DateUpdated = request.DateUpdated }; await _Repository.AddAsync(cliente); await _unitOfWork.CompleteAsync(); return(cliente); }
public async Task AdicionarClienteAsync(AdicionarUmClienteDTO obj) { Endereco endereco = new Endereco( obj.Rua, obj.Cidade, obj.Estado, obj.CEP ); Cliente cliente = new Cliente(obj.NomeDoCliente, endereco); if (cliente.Invalid) { //TODO: Arrumar como pegar a validação do Fluent throw new System.Exception(cliente.ValidationResult.RuleSetsExecuted.ToString()); } await _clienteRepository.AddAsync(cliente); _clienteRepository.SaveAsync(); }
public async Task AddAsync(ClienteDto model) { try { var entity = _mapper.Map <Cliente>(model); await _unitOfWork.BeginTransactionAsync(); await _repository.AddAsync(entity); await _repository.SaveChangesAsync(); await _unitOfWork.CommitTransactionAsync(); } catch (Exception e) { await _unitOfWork.RollbackTransactionAsync(); throw; } }
public async Task <ActionResult <Cliente> > Post(Cliente cliente) { await _clienteRepository.AddAsync(cliente); return(cliente); }
public Task <Cliente> AddAsync(Cliente source) { return(_ClienteRepository.AddAsync(source)); }