Exemple #1
0
        public async Task EnrollAsync(string gatherId, string userId)
        {
            var gather = await this.gatherRepository.GetByIdAsync(gatherId);

            var user = await this.userRepository.GetByIdAsync(userId);

            var gatherUser = new GatherUser
            {
                Gather = gather,
                User   = user
            };

            await this.gatherUserRepository.AddAsync(gatherUser);

            gather.Players.Add(gatherUser);
            this.gatherRepository.Update(gather);

            await this.gatherRepository.SaveChangesAsync();
        }
Exemple #2
0
        private void SeedGathers(FootballizeDbContext dbContext, User user, List <Pitch> fields)
        {
            var gathers = new List <Gather>();


            for (int i = 0; i < 10; i++)
            {
                var index  = i % 2 == 0 ? 1 : 0;
                var gather = new Gather
                {
                    Pitch       = fields[index],
                    Creator     = user,
                    StartingAt  = DateTime.Now.AddDays(1),
                    Description =
                        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse lectus nisi, dictum vitae euismod vel, elementum eu nunc. Maecenas feugiat orci enim, a euismod mauris sollicitudin et.",
                    TeamFormat     = TeamFormat.FivePlusOne,
                    Title          = $"Game {(i + 1)}",
                    MaximumPlayers = 12
                };

                var player = new GatherUser
                {
                    Gather = gather,
                    User   = user
                };

                gather.Players.Add(player);
                gathers.Add(gather);
            }


            foreach (Gather gather in gathers)
            {
                if (!dbContext.Gathers.Any(x => x.Title == gather.Title))
                {
                    dbContext.Gathers.Add(gather);
                }
            }
        }