Exemplo n.º 1
0
        public ProviderServiceDTO CreateProviderService(ProviderServiceDTO providerServiceDTO)
        {
            try
            {
                if (providerServiceDTO.Amount <= 0)
                {
                    return(null);
                }

                var provider = _context.ServiceProviders.Get(providerServiceDTO.ServiceProviderId);
                var card     = _context.BankCards.Get(providerServiceDTO.BankCardId);

                if (provider == null || card == null)
                {
                    return(null);
                }

                var service = new Service
                {
                    Amount            = providerServiceDTO.Amount,
                    BankCardId        = card.Id,
                    ServiceProviderId = provider.Id,
                };

                _context.Services.Add(service);
                _context.Save();

                return(service.Adapt <ProviderServiceDTO>());
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                throw;
            }
        }