Ejemplo n.º 1
0
        public async Task <Response> Handle(Command request, CancellationToken cancellationToken)
        {
            var newCampaign = new Domain.Entities.Campaign()
            {
                Name        = request.Name,
                Description = request.Description,
                StartDate   = request.StartDate,
                EndDate     = request.EndDate,
                Closed      = request.Closed,
                CreatedBy   = request.CreatedBy,
                MaxVotes    = request.MaxVotes
            };

            dbContext.Campaigns.Add(newCampaign);

            await dbContext.SaveChangesAsync();

            return(new SuccessResponse <CampaignModel>(new CampaignModel()
            {
                Id = newCampaign.Id,
                Name = newCampaign.Name,
                Description = newCampaign.Description,
                StartDate = newCampaign.StartDate,
                EndDate = newCampaign.EndDate,
                Closed = newCampaign.Closed,
                CreatedBy = newCampaign.CreatedBy,
                MaxVotes = newCampaign.MaxVotes
            }));
        }
Ejemplo n.º 2
0
        public async Task <Response> Handle(Command request, CancellationToken cancellationToken)
        {
            dbContext.CampaignVotes.AddRange(request.CampaignIdList?.Select(x => new Domain.Entities.CampaignVote()
            {
                CampaignId     = request.CampaignId,
                CampaignItemId = x,
                VoterName      = request.VoterName,
                ReferenceDate  = DateTime.Now
            }));

            await dbContext.SaveChangesAsync();

            return(new SuccessResponse("Vote casted"));
        }