Esempio n. 1
0
        public async Task <IActionResult> AddVote([FromRoute] long id, [FromBody] AddVoteDto addVoteDto)
        {
            // TODO Add validation that the dates are in valid format
            var eventModified = await Events.AddVotesAsync(addVoteDto.ToEventEntity(id)).ConfigureAwait(false);

            return(Ok(eventModified.ToEventShowDto()));
        }
Esempio n. 2
0
        public async Task AddVotes_Event_ReturnsCorrectResult()
        {
            const string nameToBeTestedWith         = "TEST_NAME";
            const string dateToBeTestedWith         = "2010-01-01";
            const string personVotingToBeTestedWith = "TEST_PERSON";

            await WithTestDatabase.Run(async context =>
            {
                var repository = new EventRepository(context);

                var entityToBeAdded = new EventEntity
                {
                    Name         = nameToBeTestedWith,
                    DateEntities = new List <DateEntity>
                    {
                        new DateEntity
                        {
                            Date = dateToBeTestedWith
                        }
                    }
                };
                var addedId     = await repository.CreateEventAsync(entityToBeAdded);
                var addedEntity = await repository.GetAsync(addedId);

                Assert.Empty(DomainLogic.GetAllEventParticipants(addedEntity));

                var votes = new AddVoteDto
                {
                    Name  = personVotingToBeTestedWith,
                    Votes = new List <string> {
                        dateToBeTestedWith
                    }
                };
                var modifiedEvent = await repository.AddVotesAsync(votes.ToEventEntity(addedId));

                Assert.Single(DomainLogic.GetAllEventParticipants(modifiedEvent));

                var suitableDates = DomainLogic.CalculateSuitableDatesForEvent(modifiedEvent.DateEntities,
                                                                               DomainLogic.GetAllEventParticipants(modifiedEvent));
                Assert.Single(suitableDates);
                Assert.Equal(suitableDates.Select(s => s.Date).Single(), dateToBeTestedWith);
            });
        }
Esempio n. 3
0
 /// <summary>
 /// Converts the DTO containing the votes given to an entity.
 /// </summary>
 /// <param name="dto">The dto to convert.</param>
 /// <param name="id">Id of the event</param>
 /// <returns></returns>
 public static EventEntity ToEventEntity(this AddVoteDto dto, long id)
 {
     return(dto == null
         ? null
         : new EventEntity
     {
         Id = id,
         DateEntities = dto.Votes.Select(d => new DateEntity
         {
             Date = d,
             VoteEntities = new List <VoteEntity>
             {
                 new VoteEntity
                 {
                     PersonName = dto.Name
                 }
             }
         }).ToList()
     });
 }