Exemplo n.º 1
0
        public static ConsumerDto ToConsumerDto(this ProxyConsumer proxyConsumer)
        {
            var consumerDto = new ConsumerDto
            {
                Id                    = proxyConsumer.Id,
                ServiceName           = proxyConsumer.GateConsumer.ServiceName,
                TopicName             = proxyConsumer.GateConsumer.TopicName,
                Endpoint              = proxyConsumer.Endpoint,
                IsStarted             = proxyConsumer.GateConsumer.IsStarted,
                MaxConcurrentMessages = proxyConsumer.GateConsumer.MaxConcurrentMessages,
                AbortTime             = proxyConsumer.AbortTime,
                RestartCount          = proxyConsumer.RestartCount,
                RestartDelayInSeconds = proxyConsumer.RestartDelayInSeconds
            };


            if (proxyConsumer.RestartTask != null && proxyConsumer.RestartTask.IsCompletedSuccessfully)
            {
                consumerDto.RestartTaskStatus = "COMPLETED_SUCCESSFULLY";
            }
            if (proxyConsumer.RestartTask != null && proxyConsumer.RestartTask.IsFaulted)
            {
                consumerDto.RestartTaskStatus = "FAULTED";
            }
            if (proxyConsumer.RestartTask != null && !proxyConsumer.RestartTask.IsCompleted)
            {
                consumerDto.RestartTaskStatus = "RUNNING";
            }

            return(consumerDto);
        }
Exemplo n.º 2
0
        public void Can_add_and_load_and_delete_consumer()
        {
            var client = new RestConsumerApi(new AutoResolveScyllaRestClientSettings());

            var consumer = new ConsumerDto()
            {
                Name              = "IntegrationTestConsumerToBeDeleted",
                CanEdit           = true,
                IsAdmin           = false,
                ApiKey            = "asde",
                AvailableJobNames = new List <string>()
                {
                    "hej"
                }
            };

            client.EditConsumer(consumer);

            var fetchedConsumer = client.GetConsumers(consumer.Name);

            fetchedConsumer.First().Should().Be(consumer);

            client.DeleteConsumer(consumer.Name);

            fetchedConsumer = client.GetConsumers(consumer.Name);
            fetchedConsumer.Should().BeEmpty();
        }
Exemplo n.º 3
0
 public IActionResult Put(ConsumerDto consumer)
 {
     try
     {
         return(Ok(_consumerService.Update(consumer)));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(BadRequest("Ocorreu uma falha na alteração de Mesa"));
     }
 }
Exemplo n.º 4
0
 public IActionResult Post(ConsumerDto consumer)
 {
     try
     {
         return(Ok(_consumerService.Save(consumer)));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(BadRequest("Ocorreu uma falha no cadastro de Mesa"));
     }
 }
        //public static ConsumerDto toDto(this IList<Consumer> consumers)
        //{

        //    return new ConsumersOverviewModel()
        //    {
        //        Consumers = consumers,
        //        AvailableJobNames = availableJobs.Select(x=>x.Name).ToList()
        //    };
        //}

        public static Consumer ToDomain(this ConsumerDto dto)
        {
            if (string.IsNullOrEmpty(dto?.Name))
            {
                throw new Exception("A consumer needs to have a name");
            }
            return(new Consumer()
            {
                Name = dto.Name,
                ApiKey = dto.ApiKey,
                IsAdmin = dto.IsAdmin,
                CanEdit = dto.CanEdit,
                Jobs = dto.AvailableJobNames
            });
        }
Exemplo n.º 6
0
        public IResult Update(ConsumerDto consumerDto)
        {
            ConsumerEntity consumer = _consumerRepository.Get(consumerDto.Identification);

            consumer.SetPhoneNumer(consumerDto.PhoneNumber);
            consumer.SetCpf(consumerDto.CPF);
            consumer.SetTable(consumerDto.Table);

            consumer.Validate();

            if (consumer.Invalid)
            {
                return(new ValidateResult(consumer.Notifications, false, "Problemas ao atualizar os dados do cliente"));
            }

            _consumerRepository.Update(consumer);
            return(new ValidateResult(consumer, true, "Cliente atualizado com sucessso"));
        }
Exemplo n.º 7
0
        public IResult Save(ConsumerDto consumerDto)
        {
            ConsumerEntity consumer = new ConsumerEntity(consumerDto);

            if (_consumerRepository.Get(consumer) != null)
            {
                return(new ValidateResult(consumer, false, "Cliente informado ja está vinculado a uma mesa"));
            }

            consumer.Validate();

            if (consumer.Invalid)
            {
                return(new ValidateResult(consumer.Notifications, false, "Problemas ao cadastrar o cliente"));
            }

            _consumerRepository.Add(consumer);
            return(new ValidateResult(consumer, true, "Cliente cadastrado com sucessso"));
        }
Exemplo n.º 8
0
 public ConsumerEntity(ConsumerDto consumerDto)
 {
     PhoneNumber     = consumerDto.PhoneNumber;
     CPF             = consumerDto.CPF;
     ForeignKeyTable = consumerDto.Table;
 }
Exemplo n.º 9
0
 public static Consumer toEntity(this ConsumerDto consumerDto)
 => AutoMapper.Mapper.Map <ConsumerDto, Consumer>(consumerDto);
Exemplo n.º 10
0
 public void EditConsumer(ConsumerDto consumer)
 {
     Put($"{_url}/consumer", consumer);
 }
Exemplo n.º 11
0
 public void EditConsumer([FromBody] ConsumerDto consumer)
 {
     EnsureAdmin();
     _consumerService.SaveOrUpdate(consumer.ToDomain());
 }