コード例 #1
0
        public async Task <ActionResult <VotingView> > Create(
            CancellationToken cancellationToken,
            [FromBody] CreateVotingBinding binding)
        {
            var house = await _houseRepository.GetByAddress(User.GetAddress(), cancellationToken);

            var voting = new Voting(Guid.NewGuid(), binding.Title, house);

            binding.Variants.ForEach(o =>
            {
                voting.AddVariant(new Variant(Guid.NewGuid(), o, voting));
            });

            await _votingRepository.Save(voting, cancellationToken);

            return(Ok(new VotingView
            {
                Id = voting.Id,
                Title = voting.Title,
                IsClosed = voting.IsClosed,
                Variants = voting.Variants.Select(o => new VariantView
                {
                    Id = o.Id,
                    Title = o.Title
                }).ToList()
            }));
        }