Exemplo n.º 1
0
        private async Task AddGroupBetPlayerAsync(PlayerGroupBetRequestEntity playerGroupBetRequest)
        {
            Player player = await _context.Players
                            .Include(u => u.User)
                            .FirstOrDefaultAsync(ug => ug.Id == playerGroupBetRequest.RequiredPlayer.Id);

            GroupBet groupBet = await _context.GroupBets
                                .Include(ug => ug.GroupBetPlayers)
                                .FirstOrDefaultAsync(ug => ug.Id == playerGroupBetRequest.GroupBet.Id);



            if (player != null && groupBet != null)
            {
                GroupBetPlayer groupBetPlayer = new GroupBetPlayer
                {
                    GroupBet   = groupBet,
                    Player     = player,
                    IsAccepted = true,
                    IsBlocked  = false,
                    Points     = 0
                };
                _context.GroupBetPlayers.Add(groupBetPlayer);
                _context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostGroupBet([FromBody] GroupBetRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string picturePath = string.Empty;

            if (request.PictureArray != null && request.PictureArray.Length > 0)
            {
                picturePath = _imageHelper.UploadImage(request.PictureArray, "GroupBets");
            }



            var groupBet = new GroupBet
            {
                Admin = await _context.Players
                        .Include(u => u.User)
                        .FirstOrDefaultAsync(p => p.User.Email == request.PlayerEmail),
                CreationDate = request.CreationDate,
                Name         = request.Name,
                Tournament   = await _context.Tournaments.FindAsync(request.TournamentId),
                LogoPath     = picturePath,
            };

            var groupBetPlayer = new GroupBetPlayer
            {
                GroupBet = groupBet,
                Player   = await _context.Players
                           .Include(u => u.User)
                           .FirstOrDefaultAsync(p => p.User.Email == request.PlayerEmail),
                IsAccepted = true,
                IsBlocked  = false,
                Points     = 0
            };


            _context.GroupBets.Add(groupBet);
            _context.GroupBetPlayers.Add(groupBetPlayer);
            await _context.SaveChangesAsync();

            return(Ok(_converterHelper.ToGroupBetResponse(groupBet)));
            //return NoContent();
        }
        public async Task <IActionResult> GetGroupBetPlayerByIds([FromBody] GroupBetPlayerRequest2 groupBetPlayerRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var groupBetPlayer = _context.GroupBetPlayers
                                 .FirstOrDefault(o => o.GroupBet.Id == groupBetPlayerRequest.GroupBetId && o.Player.Id == groupBetPlayerRequest.PlayerId);


            var groupBet = await _context.GroupBets
                           .Include(p => p.Tournament)
                           .Include(p => p.Admin)
                           .ThenInclude(p => p.User)
                           .ThenInclude(p => p.FavoriteTeam)
                           .ThenInclude(p => p.League)
                           .FirstOrDefaultAsync(u => u.Id == groupBetPlayerRequest.GroupBetId);

            var player = await _context.Players
                         .Include(p => p.User)
                         .ThenInclude(p => p.FavoriteTeam)
                         .ThenInclude(p => p.League)
                         .FirstOrDefaultAsync(u => u.Id == groupBetPlayerRequest.PlayerId);

            var groupBetPlayer1 = new GroupBetPlayer
            {
                Id         = groupBetPlayer.Id,
                GroupBet   = groupBet,
                Player     = player,
                IsAccepted = groupBetPlayer.IsAccepted,
                IsBlocked  = groupBetPlayer.IsBlocked,
                Points     = groupBetPlayer.Points
            };

            var groupBetPlayerResponse = _converterHelper.ToGroupBetPlayerResponse(groupBetPlayer1);

            return(Ok(groupBetPlayerResponse.Result));
        }
        public async Task <IActionResult> PostGroupBetPlayer([FromBody] GroupBetPlayerRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var groupBetPlayer = new GroupBetPlayer
            {
                Player = await _context.Players
                         .Include(u => u.User)
                         .FirstOrDefaultAsync(p => p.Id == request.PlayerId),
                IsAccepted = request.IsAccepted,
                IsBlocked  = request.IsBlocked,
                Points     = 0,
                GroupBet   = await _context.GroupBets
                             .FirstOrDefaultAsync(p => p.Id == request.GroupBetId),
            };

            _context.GroupBetPlayers.Add(groupBetPlayer);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemplo n.º 5
0
        public async Task <GroupBetPlayerResponse> ToGroupBetPlayerResponse(GroupBetPlayer groupBetPlayer)
        {
            var player = await _context.Players.FindAsync(groupBetPlayer.Player.Id);

            var groupBet = await ToGroupBetResponse(await _context.GroupBets.FindAsync(groupBetPlayer.GroupBet.Id));

            return(new GroupBetPlayerResponse
            {
                Id = groupBetPlayer.Id,
                GroupBet = groupBet,
                IsAccepted = groupBetPlayer.IsAccepted,
                IsBlocked = groupBetPlayer.IsBlocked,
                //Player = new PlayerResponse2
                //{
                //    FirstName = groupBetPlayer.Player.User.FirstName,
                //    LastName = groupBetPlayer.Player.User.LastName,
                //    NickName = groupBetPlayer.Player.User.NickName,
                //    PicturePath = groupBetPlayer.Player.User.Picture,
                //    Id = groupBetPlayer.Player.Id,
                //    Points = groupBetPlayer.Player.User.Points,
                //    Team = new TeamResponse
                //    {
                //        Id = groupBetPlayer.Player.User.FavoriteTeam.Id,
                //        Initials = groupBetPlayer.Player.User.FavoriteTeam.Initials,
                //        LeagueId = groupBetPlayer.Player.User.FavoriteTeam.League.Id,
                //        LeagueName = groupBetPlayer.Player.User.FavoriteTeam.League.Name,
                //        Name = groupBetPlayer.Player.User.FavoriteTeam.Name,
                //        LogoPath = groupBetPlayer.Player.User.FavoriteTeam.LogoPath,
                //    },
                //    UserId = groupBetPlayer.Player.User.Id,
                //    Predictions = groupBetPlayer.Player.Predictions.Select(h => new PredictionResponse
                //    {
                //        Id = h.Id,
                //        GoalsLocal = h.GoalsLocal,
                //        GoalsVisitor = h.GoalsVisitor,
                //        Points = h.Points,
                //        Match = new MatchResponse
                //        {
                //            Local = new TeamResponse
                //            {
                //                Id = h.Match.Local.Id,
                //                Initials = h.Match.Local.Initials,
                //                LeagueId = h.Match.Local.League.Id,
                //                LeagueName = h.Match.Local.League.Name,
                //                Name = h.Match.Local.Name,
                //                LogoPath = h.Match.Local.LogoPath,
                //            },
                //            Visitor = new TeamResponse
                //            {
                //                Id = h.Match.Visitor.Id,
                //                Initials = h.Match.Visitor.Initials,
                //                LeagueId = h.Match.Visitor.League.Id,
                //                LeagueName = h.Match.Visitor.League.Name,
                //                Name = h.Match.Visitor.Name,
                //                LogoPath = h.Match.Visitor.LogoPath,
                //            },
                //            GoalsLocal = h.GoalsLocal,
                //            GoalsVisitor = h.GoalsVisitor,
                //        }
                //    }).ToList()
                //},

                Points = groupBetPlayer.Points
            });
        }
Exemplo n.º 6
0
        public async Task <IActionResult> PostUserGroupBet([FromBody] AddUserGroupBetRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Player proposalPlayer = await _context.Players
                                    .Include(u => u.User)
                                    .FirstOrDefaultAsync(p => p.Id == request.PlayerId);

            if (proposalPlayer.User == null)
            {
                return(BadRequest("Este Usuario no existe."));
            }

            Player requiredPlayer2 = _converterHelper.ToPlayer(await _userHelper.GetUserAsync(request.Email));


            if (requiredPlayer2.User == null)
            {
                return(BadRequest("Este Usuario no existe en la App."));
            }

            Player requiredPlayer = await _context.Players
                                    .Include(u => u.User)
                                    .FirstOrDefaultAsync(p => p.User.Id == requiredPlayer2.User.Id);

            GroupBet groupBet = await _context.GroupBets
                                .Include(u => u.GroupBetPlayers)
                                .FirstOrDefaultAsync(p => p.Id == request.GroupBetId);



            GroupBetPlayer groupBetPlayer = await _context.GroupBetPlayers
                                            .Include(ug => ug.Player)
                                            .ThenInclude(u => u.User)
                                            .FirstOrDefaultAsync(ug => ug.Player.Id == requiredPlayer.Id && ug.GroupBet.Id == request.GroupBetId);

            if (groupBetPlayer != null)
            {
                {
                    return(BadRequest("Este Usuario ya pertenece al Grupo."));
                }
            }

            PlayerGroupBetRequestEntity playerGroupBetRequestEntity = await _context.PlayerGroupBetRequests
                                                                      .FirstOrDefaultAsync(ug => ug.RequiredPlayer.Id == requiredPlayer.Id && ug.GroupBet.Id == request.GroupBetId && ug.Status == PlayerGroupBetStatus.Pending);

            if (playerGroupBetRequestEntity != null)

            {
                {
                    return(BadRequest("Este Usuario ya tiene una invitación que está pendiente."));
                }
            }

            PlayerGroupBetRequestEntity playerGroupBetRequest = new PlayerGroupBetRequestEntity
            {
                ProposalPlayer = proposalPlayer,
                RequiredPlayer = requiredPlayer,
                GroupBet       = groupBet,
                Status         = PlayerGroupBetStatus.Pending,
                Token          = Guid.NewGuid()
            };

            try
            {
                _context.PlayerGroupBetRequests.Add(playerGroupBetRequest);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            string linkConfirm = Url.Action("ConfirmUserGroup", "Account", new
            {
                requestId = playerGroupBetRequest.Id,
                token     = playerGroupBetRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            string linkReject = Url.Action("RejectUserGroup", "Account", new
            {
                requestId = playerGroupBetRequest.Id,
                token     = playerGroupBetRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            Response response = _mailHelper.SendMail(request.Email, "Solicitud de unirse a un Grupo", $"<h1>Solicitud de unirse a un Grupo</h1>" +
                                                     $"El Usuario: {proposalPlayer.User.FullName} ({proposalPlayer.User.Email}), ha solicitado que sea miembro de su grupo de usuarios {groupBet.Name} en la aplicación FULBO PULENTA. " +
                                                     $"</hr></br></br>Si desea aceptar, haga clic aquí: <a href = \"{linkConfirm}\">Confirmar</a>" +
                                                     $"</hr></br></br> . Si desea rechazar, haga clic aquí: <a href = \"{linkReject}\">Rechazar</a>");

            if (!response.IsSuccess)
            {
                return(BadRequest(response.Message));
            }

            return(Ok("Se ha enviado un correo electrónico al usuario con su solicitud, esperamos a que responda pronto!"));
        }