Exemple #1
0
        public async Task <bool> Handle(AddSupplierCommand request, CancellationToken cancellationToken)
        {
            var company = _companyRepository.Find(request.CompanyID);

            if (company == null)
            {
                await _bus.RaiseEvent(new DomainErrorNotification("NotAllowed", "Company informed does not exists."));

                return(false);
            }

            if (await _supplierRepository.ExistsSupplierWithCPFCNPJ(request.CpfCnpj))
            {
                await _bus.RaiseEvent(new DomainErrorNotification("Conflict", "Supplier with informed CPF/CNPJ already exists."));

                return(false);
            }

            if (company.UF.ToString().Equals("PR") && CPF.IsCpf(request.CpfCnpj) && request.BirthDate.Value.Age() < 18)
            {
                await _bus.RaiseEvent(new DomainErrorNotification("NotAllowed", "Underage Supplier not permmited."));

                return(false);
            }

            _repository.Add(new Supplier(request.Name, (CPFCNPJ)request.CpfCnpj, request.Phones, company, request.SupplierID, request.BirthDate, (RG)request.Rg));
            return(Commit());
        }
        public async Task <MutationInfo> Add([Inject] IMediator mediator, [Inject] IRequestInfo requestInfo, NonNull <AddSupplierParameters> parameters)
        {
            var command = new AddSupplierCommand
            {
                Id          = Guid.NewGuid(),
                Name        = parameters.Value.Name,
                ContactInfo = parameters.Value.ContactInfo,
                Headers     = new CommandHeaders(correlationId: Guid.NewGuid(), identity: requestInfo.Identity, remoteIpAddress: requestInfo.IpAddress)
            };

            var result = await mediator.Send(command);

            return(MutationInfo.FromCommand(command));
        }
Exemple #3
0
 public Task Post([FromBody] AddSupplierCommand command)
 {
     return(_mediator.Send(command));
 }