Exemple #1
0
 public Poll(DescriptionVO description)
 {
     Description  = description;
     _optionsPoll = new List <OptionPoll>();
     //caso tenha erro de description na classe descriptionVO, ele é adicionado aqui.
     AddNotifications(description);
 }
        public void Poll_whenCreateObject3_returnNotification()
        {
            DescriptionVO description = new DescriptionVO("");
            Poll          poll        = new Poll(description);

            DescriptionVO option1     = new DescriptionVO("poll 1");
            DescriptionVO option2     = new DescriptionVO("poll 1");
            OptionPoll    optionPoll1 = new OptionPoll(option1);
            OptionPoll    optionPoll2 = new OptionPoll(option2);

            poll.addOptions(optionPoll1);
            poll.addOptions(optionPoll2);

            Assert.AreEqual(3, poll.Notifications.Count);
        }
        public async Task <ICommandResult> Handle(CreatePollCommand command)
        {
            try
            {
                // fail fast validation
                command.Validate();
                if (command.Invalid)
                {
                    return(new GenericCommandResult(true, "Enquete inválida", command.Notifications));
                }

                DescriptionVO description = new DescriptionVO(command.Poll_Description);
                Poll          poll        = new Poll(description);

                List <OptionPoll> opt = new List <OptionPoll>();
                foreach (var item in command.Options)
                {
                    DescriptionVO vo     = new DescriptionVO(item);
                    OptionPoll    option = new OptionPoll(vo);
                    poll.addOptions(option);
                }

                await _pollRepository.Create(poll);

                if (Commit())
                {
                    return(new GenericCommandResult(true, "Enquete gravada com sucesso", new CreatePollCommandResult(poll.Id)));
                }
                else
                {
                    return(new GenericCommandResult(false, "Falha ao gravar enquete", null));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("CreatePollCommand --> ", ex);
                return(new GenericCommandResult(false, "Falha ao gravar enquete", null));
            }
        }
 public OptionPoll(DescriptionVO description)
 {
     Description = description;
     //caso tenha erro de description na classe descriptionVO, ele é adicionado aqui.
     AddNotifications(description);
 }