コード例 #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();
            }
        }
コード例 #2
0
 public GroupBet Get(GroupBet groupBet)
 {
     if (groupBet.Id == 0)
     {
         throw new IdentifierUndefinedException();
     }
     return(_groupBetRepository.Get(groupBet.Id));
 }
コード例 #3
0
 public void Delete(GroupBet groupBet)
 {
     if (groupBet.Id == 0)
     {
         throw new IdentifierUndefinedException();
     }
     _groupBetRepository.Delete(groupBet);
 }
コード例 #4
0
        public static GroupBet InvalidGroupBetOrganizer()
        {
            GroupBet groupBet = new GroupBet();

            groupBet.Id         = 1;
            groupBet.CreateDate = DateTime.Now.AddDays(-1);
            groupBet.Organizer  = "";

            return(groupBet);
        }
コード例 #5
0
        public static GroupBet InvalidCreateGroupBetDate()
        {
            GroupBet groupBet = new GroupBet();

            groupBet.Id         = 1;
            groupBet.CreateDate = DateTime.Now.AddDays(1);
            groupBet.Organizer  = "Organizador";

            return(groupBet);
        }
コード例 #6
0
        public static GroupBet ValidGroupBetWithId()
        {
            GroupBet groupBet = new GroupBet();

            groupBet.Id         = 1;
            groupBet.CreateDate = DateTime.Now.AddDays(-1);
            groupBet.Organizer  = "Organizador";

            return(groupBet);
        }
コード例 #7
0
        public void GroupBet_EmptyBets_ShouldFail()
        {
            //Cenário
            _groupBet = ObjectMother.GroupBetEmptyBets();

            //Ação
            Action act = () => _groupBet.Validate();

            //Verificar
            act.Should().Throw <GroupBetEmptyBetsException>();
        }
コード例 #8
0
        public static GroupBet GroupBetEmptyBets()
        {
            GroupBet groupBet = new GroupBet();

            groupBet.Id         = 1;
            groupBet.CreateDate = DateTime.Now.AddDays(-1);
            groupBet.Organizer  = "Organizador";
            groupBet.Bets       = new List <Bet>();

            return(groupBet);
        }
コード例 #9
0
        public void GroupBet_Get_ShouldBeOk()
        {
            //Cenário
            _mockGroupBetRepository.Setup(rp => rp.Get(_groupBet.Id)).Returns(_groupBet);

            //Ação
            GroupBet getGroupBet = _groupBetService.Get(_groupBet);

            //Verificar
            getGroupBet.Should().Be(_groupBet);
            _mockGroupBetRepository.Verify(rp => rp.Get(_groupBet.Id));
        }
コード例 #10
0
        public void GroupBet_Add_ShouldBeOk()
        {
            //Cenário
            _mockGroupBetRepository.Setup(rp => rp.Save(_groupBet)).Returns(_groupBet);

            //Ação
            GroupBet savedGroupBet = _groupBetService.Add(_groupBet);

            //Verificar
            savedGroupBet.Should().Be(_groupBet);
            _mockGroupBetRepository.Verify(rp => rp.Save(_groupBet));
        }
コード例 #11
0
        public void GroupBet_Update_ShouldBeOk()
        {
            //cenário
            _groupBet.Organizer = "Lotérica";
            _mockGroupBetRepository.Setup(rp => rp.Update(_groupBet)).Returns(_groupBet);

            //Ação
            GroupBet updatedGroupBet = _groupBetService.Update(_groupBet);

            //Verificar
            updatedGroupBet.Should().Be(_groupBet);
            _mockGroupBetRepository.Verify(rp => rp.Update(_groupBet));
        }
コード例 #12
0
ファイル: ConverterHelper.cs プロジェクト: LuisPulenta/Soccer
 public GroupBetViewModel ToGroupBetViewModel(GroupBet groupBet)
 {
     return(new GroupBetViewModel
     {
         Id = groupBet.Id,
         LogoPath = groupBet.LogoPath,
         Name = groupBet.Name,
         Admin = groupBet.Admin,
         CreationDate = groupBet.CreationDate,
         GroupBetPlayers = groupBet.GroupBetPlayers,
         Tournament = groupBet.Tournament
     });
 }
コード例 #13
0
        public static GroupBet GroupBetWithBet()
        {
            GroupBet groupBet = new GroupBet();

            groupBet.Id         = 1;
            groupBet.CreateDate = DateTime.Now.AddDays(-1);
            groupBet.Organizer  = "Organizador";
            groupBet.Bets       = new List <Bet>()
            {
                ValidBetWithContest()
            };

            return(groupBet);
        }
コード例 #14
0
        public void GroupBet_ValidBets_ShouldBeOk()
        {
            //Cenário
            _groupBet      = ObjectMother.ValidGroupBetWithId();
            _groupBet.Bets = new List <Bet> {
                _bet.Object
            };

            //Ação
            Action act = () => _groupBet.Validate();

            //Verificar
            act.Should().NotThrow <GroupBetEmptyBetsException>();
        }
コード例 #15
0
        public void GroupBet_InvalidOrganizer_ShouldFail()
        {
            //Cenário
            _groupBet      = ObjectMother.InvalidGroupBetOrganizer();
            _groupBet.Bets = new List <Bet>()
            {
                _bet.Object
            };

            //Ação
            Action act = () => _groupBet.Validate();

            //Verificar
            act.Should().Throw <InvalidOrganizerException>();
        }
コード例 #16
0
ファイル: ConverterHelper.cs プロジェクト: LuisPulenta/Soccer
        public async Task <GroupBetResponse> ToGroupBetResponse(GroupBet groupBet)
        {
            var player = await _context.Players.FindAsync(groupBet.Admin.Id);

            var tournament = await _context.Tournaments.FindAsync(groupBet.Tournament.Id);

            return(new GroupBetResponse
            {
                Id = groupBet.Id,
                Name = groupBet.Name,
                Admin = ToPlayerResponse(player),
                CreationDate = groupBet.CreationDate,
                LogoPath = groupBet.LogoPath,
                Tournament = ToTournamentResponse(tournament)
            });
        }
コード例 #17
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();
        }
コード例 #18
0
        // GET: GroupBets/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            GroupBet GroupBetEntity = await _context.GroupBets.FindAsync(id);

            if (GroupBetEntity == null)
            {
                return(NotFound());
            }

            GroupBetViewModel model = _converterHelper.ToGroupBetViewModel(GroupBetEntity);

            return(View(model));
        }
コード例 #19
0
        public async Task <IActionResult> Edit(GroupBetViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (ModelState.IsValid)
                {
                    var path = model.LogoPath;

                    if (model.LogoFile != null)
                    {
                        path = await _imageHelper.UploadImageAsync(model.LogoFile, "GroupBets");
                    }

                    GroupBet GroupBet = _converterHelper.ToGroupBet(model, path, false);
                    _context.Update(GroupBet);
                    try
                    {
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    catch (Exception ex)
                    {
                        if (ex.InnerException.Message.Contains("duplicate"))
                        {
                            ModelState.AddModelError(string.Empty, "Este Grupo ya existe");
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, ex.InnerException.Message);
                        }
                    }
                }
            }
            return(View(model));
        }
コード例 #20
0
 public GroupBet Add(GroupBet groupBet)
 {
     groupBet.Validate();
     return(_groupBetRepository.Save(groupBet));
 }
コード例 #21
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!"));
        }
コード例 #22
0
 public void Initialize()
 {
     _groupBet = ObjectMother.GroupBetWithBet();
     _mockGroupBetRepository = new Mock <IGroupBetRepository>();
     _groupBetService        = new GroupBetService(_mockGroupBetRepository.Object);
 }
コード例 #23
0
 public GroupBet Update(GroupBet groupBet)
 {
     groupBet.Validate();
     return(_groupBetRepository.Update(groupBet));
 }
コード例 #24
0
 public void TearDown()
 {
     _groupBet = null;
 }
コード例 #25
0
 public void Initialize()
 {
     _groupBet = new GroupBet();
     _bet      = new Mock <Bet>();
 }
コード例 #26
0
        public async Task <IActionResult> GetPlayersForGroupBet([FromBody] PlayersForGroupBetRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            GroupBet groupBet = await _context.GroupBets.FindAsync(request.GroupBetId);

            if (groupBet == null)
            {
                return(BadRequest("Este Grupo de Apuestas no existe."));
            }

            Player player = await _context.Players
                            .Include(u => u.User.FavoriteTeam)
                            .ThenInclude(l => l.League)
                            .Include(u => u.Predictions)
                            .ThenInclude(p => p.Match)
                            .ThenInclude(m => m.Local)
                            .ThenInclude(l => l.League)
                            .Include(u => u.Predictions)
                            .ThenInclude(p => p.Match)
                            .ThenInclude(m => m.Visitor)
                            .ThenInclude(l => l.League)
                            .Include(u => u.Predictions)
                            .ThenInclude(p => p.Match)
                            .ThenInclude(p => p.Group)
                            .ThenInclude(p => p.Tournament)
                            .FirstOrDefaultAsync(u => u.User.Id == request.ToString());

            if (player == null)
            {
                return(BadRequest("Este Usurio no existe."));
            }

            // Add precitions already done
            List <PredictionResponse> predictionResponses = new List <PredictionResponse>();

            //foreach (PredictionEntity predictionEntity in player.Predictions)
            //{
            //    if (predictionEntity.Match.Group.Tournament.Id == request.TournamentId)
            //    {
            //        predictionResponses.Add(_converterHelper.ToPredictionResponse(predictionEntity));
            //    }
            //}

            //// Add precitions undone
            //List<MatchEntity> matches = await _context.Matches
            //    .Include(m => m.Local)
            //    .Include(m => m.Visitor)
            //    .Where(m => m.Group.Tournament.Id == request.TournamentId)
            //    .ToListAsync();
            //foreach (MatchEntity matchEntity in matches)
            //{
            //    PredictionResponse predictionResponse = predictionResponses.FirstOrDefault(pr => pr.Match.Id == matchEntity.Id);
            //    if (predictionResponse == null)
            //    {
            //        predictionResponses.Add(new PredictionResponse
            //        {
            //            Match = _converterHelper.ToMatchResponse(matchEntity),
            //        });
            //    }
            //}

            return(Ok(predictionResponses.OrderBy(pr => pr.Id).ThenBy(pr => pr.Match.Date)));
        }