Ejemplo n.º 1
0
        public static RankingDTO GetTeamScoreByTeamId(string teamId)
        {
            RankingDTO rtn = new RankingDTO();

            try
            {
                WebClient client = new WebClient();

                client.Headers["User-Agent"] = "Mozilla / 5.0(Linux; Android 6.0.1; MotoG3 Build/ MPI24.107 - 55) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 51.0.2704.81 Mobile Safari/ 537.36";

                string data = client.DownloadString(ENGINE_API + "teamScore?teamId=" + teamId);

                JObject currencyJson = JObject.Parse(data);

                rtn = new RankingDTO()
                {
                    PlayerId   = currencyJson.Root["id"].Value <string>(),
                    PlayerName = currencyJson.Root["nick"].Value <string>(),
                    Score      = (int?)currencyJson.Root["score"]
                };
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return(rtn);
        }
Ejemplo n.º 2
0
        public void RankingTemPartida()
        {
            // Arrange
            RankingController controller = new RankingController();

            // Act
            RankingDTO result = controller.Get();

            // Assert
            Assert.IsTrue(result.MatchId > 0);
        }
Ejemplo n.º 3
0
        public void Awards()
        {
            // Arrange
            RankingController controller = new RankingController();

            // Act
            RankingDTO result = controller.Get();

            // Assert
            Assert.IsNotNull(result.Awards);
        }
Ejemplo n.º 4
0
        public void ObterRanking()
        {
            // Arrange
            RankingController controller = new RankingController();

            // Act
            RankingDTO result = controller.Get();

            // Assert
            Assert.IsNotNull(result);
        }
Ejemplo n.º 5
0
        public void RankingTemPersonagens()
        {
            // Arrange
            RankingController controller = new RankingController();

            // Act
            RankingDTO result = controller.Get();

            // Assert
            Assert.IsNotNull(result.RankingItens);
            Assert.IsTrue(result.RankingItens.All(x => x.PlayerId > 0));
        }
Ejemplo n.º 6
0
        public void RankingTemKillsOuDeaths()
        {
            // Arrange
            RankingController controller = new RankingController();

            // Act
            RankingDTO result = controller.Get();

            // Assert
            Assert.IsNotNull(result.RankingItens);

            Assert.IsTrue(result.RankingItens.Any(x => x.Kills > 0 || x.Deaths > 0));
        }
Ejemplo n.º 7
0
 public static Ranking ConstructFromDto(RankingDTO dto)
 {
     return(new Ranking()
     {
         Id = dto.id,
         Rank = dto.rank,
         Type = dto.type,
         TypeDescription = dto.type_string,
         RankingType = dto.ranking_type,
         Format = dto.format,
         Year = dto.year,
         Season = dto.season
     });
 }
        public ActionResult UpdateRanking(RankingViewModel ranking)
        {
            var        mapper = new MapperConfiguration(cfg => cfg.CreateMap <RankingViewModel, RankingDTO>()).CreateMapper();
            RankingDTO result = mapper.Map <RankingViewModel, RankingDTO>(ranking);

            try
            {
                _rankingService.UpdateRanking(result);
                return(Ok());
            }
            catch
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
        }
Ejemplo n.º 9
0
        private void assignToRanking(List <RankingDTO> rankingsToAssign, Client client)
        {
            RankingDTO RankingToAssign = rankingsToAssign.Find(Ranking => Ranking.RankingName.Contains(client.Ranking));

            if (RankingToAssign != null && RankingToAssign.Clients.Count < RankingToAssign.MaxNumberOfClients)
            {
                RankingToAssign.Clients.Add(new ClientDTO()
                {
                    Name    = client.Name,
                    Ci      = client.Ci,
                    Address = client.Address,
                    Phone   = client.Phone,
                    Ranking = client.Ranking,
                    Code    = client.Code
                });
            }
        }
Ejemplo n.º 10
0
        public static RankingDTO GetGlobalScoreInEpisodeByEpisodeAndPlayer(string episodeId, string playerId)
        {
            RankingDTO dto = new RankingDTO();

            try
            {
                WebClient client = new WebClient();

                client.Headers["User-Agent"] = "Mozilla / 5.0(Linux; Android 6.0.1; MotoG3 Build/ MPI24.107 - 55) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 51.0.2704.81 Mobile Safari/ 537.36";

                string data = client.DownloadString(ENGINE_API + "playerGlobalEpisodeScore?episodeId=" + episodeId + "&playerId=" + playerId);

                dto.Score = int.Parse(data);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return(dto);
        }
Ejemplo n.º 11
0
 public ActionResult <Ranking> PostRanking(RankingDTO rankingDTO)
 {
     try
     {
         Ranking ranking = new Ranking(rankingDTO.Naam);
         if (rankingDTO.Gebieden.Count() != 0)
         {
             rankingDTO.Gebieden.ToList().ForEach(gebiedRankingDTO =>
             {
                 Gebied gebied = _gebiedRepository.GetById(gebiedRankingDTO.GebiedId);
                 ranking.AddGebied(gebied, gebiedRankingDTO.Positie);
             });
         }
         _rankingRepository.Add(ranking);
         _rankingRepository.SaveChanges();
         return(CreatedAtAction(nameof(GetRanking), new { id = ranking.Id }, ranking));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 12
0
        public RankingDTO RankingWithPoint(int point)
        {
            var rank = new RankingDTO();

            if (point > 0 && point <= WsConstant.Level.Bronze)
            {
                rank.Point       = point;
                rank.CurrentRank = WsConstant.Level.Bronze;
                rank.RankPercent = Math.Round((double)(point * 100) / WsConstant.Level.Bronze, 2);
            }
            else if (point > WsConstant.Level.Bronze && point <= WsConstant.Level.Silver)
            {
                rank.Point       = point;
                rank.CurrentRank = WsConstant.Level.Silver;
                rank.RankPercent = Math.Round((double)(point * 100) / WsConstant.Level.Silver, 2);
            }
            else if (point > WsConstant.Level.Silver && point <= WsConstant.Level.Golden)
            {
                rank.Point       = point;
                rank.CurrentRank = WsConstant.Level.Golden;
                rank.RankPercent = Math.Round((double)(point * 100) / WsConstant.Level.Golden, 2);
            }
            else if (point > WsConstant.Level.Golden && point <= WsConstant.Level.Plantium)
            {
                rank.Point       = point;
                rank.CurrentRank = WsConstant.Level.Plantium;
                rank.RankPercent = Math.Round((double)(point * 100) / WsConstant.Level.Plantium, 2);
            }
            else if (point > WsConstant.Level.Golden && point <= WsConstant.Level.Diamon)
            {
                rank.Point       = point;
                rank.CurrentRank = WsConstant.Level.Diamon;
                rank.RankPercent = Math.Round((double)(point * 100) / WsConstant.Level.Diamon, 2);
            }

            return(rank);
        }
Ejemplo n.º 13
0
        public OrganizationBasicInfo GetFullOrganizationBasicInformation(int orgId)
        {
            OrganizationBasicInfo organizationBasic = new OrganizationBasicInfo();

            try
            {
                Organization org = GetOrganizationById(orgId);

                organizationBasic.OrganizationId = orgId;
                if (org != null)
                {
                    organizationBasic.OrganizationName = org.OrganizationName;
                    organizationBasic.Introduction     = org.Introduction;
                    organizationBasic.LogoUrl          = org.LogoUrl;
                    organizationBasic.Phone            = org.Phone;
                    organizationBasic.Email            = org.Email;
                    organizationBasic.Address          = org.Address;
                    organizationBasic.IsActive         = org.IsActive;
                    organizationBasic.IsVerify         = org.IsVerify;
                    organizationBasic.CreatedDate      = org.CreatedDate.ToString("H:mm:ss dd/MM/yy");
                    organizationBasic.Point            = org.Point;
                    using (var db = new Ws_DataContext())
                    {
                        organizationBasic.CreatorName   = db.Organizations.Where(x => x.OrganizationId == orgId).SingleOrDefault().Ws_User.UserName;
                        organizationBasic.NumberOfEvent = db.Events.Where(x => x.CreatorID == organizationBasic.OrganizationId).Count();
                    }

                    WsRanking  ranking = new WsRanking();
                    RankingDTO rank    = ranking.RankingWithPoint(org.Point);
                    if (rank.CurrentRank == 0)
                    {
                        organizationBasic.CurrentRank = "Mới";
                    }
                    else if (rank.CurrentRank == 200)
                    {
                        organizationBasic.CurrentRank = "Đồng";
                    }
                    else if (rank.CurrentRank == 500)
                    {
                        organizationBasic.CurrentRank = "Bạc";
                    }
                    else if (rank.CurrentRank == 2000)
                    {
                        organizationBasic.CurrentRank = "Vàng";
                    }
                    else if (rank.CurrentRank == 5000)
                    {
                        organizationBasic.CurrentRank = "Bạch Kim";
                    }
                    else if (rank.CurrentRank == 10000)
                    {
                        organizationBasic.CurrentRank = "Kim Cương";
                    }
                    //get creator
                    using (var db = new UserDAL())
                    {
                        organizationBasic.Creator = db.GetFullInforOfUserAsBasicUser(orgId);
                    }
                }
            }
            catch (Exception)
            {
                //throw;
            }

            return(organizationBasic);
        }
Ejemplo n.º 14
0
        public ActionResult Search(JQueryDataTableRequest jqueryTableRequest, string episodeId, string teamId, int workerTypeId = 0)
        {
            if (jqueryTableRequest != null)
            {
                if (Request["episodeId"] != null && !string.IsNullOrWhiteSpace(Request["episodeId"]) && !Request["episodeId"].Equals("undefined"))
                {
                    episodeId = Request["episodeId"];
                }

                if (Request["teamId"] != null && !string.IsNullOrWhiteSpace(Request["teamId"]) && !Request["teamId"].Equals("undefined"))
                {
                    teamId = Request["teamId"];
                }

                if (Request["workerTypeId"] != null && !string.IsNullOrWhiteSpace(Request["workerTypeId"]) && !Request["workerTypeId"].Equals("undefined"))
                {
                    workerTypeId = int.Parse(Request["workerTypeId"]);
                }

                string filter = "";

                string[] searchTerms = jqueryTableRequest.Search.Split(new string[] { "#;$#" }, StringSplitOptions.None);
                filter = searchTerms[0];

                List <RankingDTO> searchResult = null;

                if (episodeId != null && !episodeId.Equals(""))
                {
                    if (teamId != null && !teamId.Equals(""))
                    {
                        TeamEntity team = TeamRepository.Instance.GetByIdExterno(teamId);

                        WorkerTypeEntity workerType = WorkerTypeRepository.Instance.GetById(team.WorkerTypeId);

                        if (workerType.ProfileName.Equals(Profiles.LIDER))
                        {
                            List <RankingDTO> rankingDTOList = new List <RankingDTO>();

                            //List<PlayerRunEntity> playerRunList = PlayerRunRepository.Instance.GetByEpisodeAndTeam(episodeId.ToString(), teamId);
                            GetAllDTO runnersDTO = RunEngineService.Instance.GetRunsByTeamId(teamId);

                            // buscar lista de run ao inves da tabela
                            foreach (RunEngineDTO item in runnersDTO.List.run)
                            {
                                RankingDTO dto = new RankingDTO();

                                WorkerDTO worker = WorkerRepository.Instance.GetDTOById(item.PlayerId);
                                //run .get player ID

                                dto            = EngineBIZ.GetGlobalScoreInEpisodeByEpisodeAndPlayer(episodeId.ToString(), worker.ExternalId);
                                dto.LogoId     = worker.LogoId;
                                dto.PlayerId   = worker.ExternalId;
                                dto.PlayerName = worker.Name;

                                dto.LogoId = worker.LogoId;

                                rankingDTOList.Add(dto);
                            }

                            searchResult = rankingDTOList;
                        }
                        else
                        {
                            List <RankingDTO> rankingDTOList = new List <RankingDTO>();

                            GetAllDTO runnersDTO = RunEngineService.Instance.GetRunsByTeamId(teamId);
                            foreach (RunEngineDTO item in runnersDTO.List.run)

                            {
                                RankingDTO dto = new RankingDTO();

                                WorkerDTO worker = WorkerRepository.Instance.GetDTOById(item.PlayerId);

                                dto = EngineBIZ.GetScoreByRun(item.Id);

                                dto.PlayerName = worker.Name;
                                dto.LogoId     = worker.LogoId;

                                rankingDTOList.Add(dto);
                            }

                            searchResult = rankingDTOList;
                        }
                    }
                    else
                    {
                        List <EngineTeamDTO> teamsFromEngine = new List <EngineTeamDTO>();

                        List <TeamEntity> teams = new List <TeamEntity>();

                        teamsFromEngine.AddRange(EngineBIZ.GetTeamsByEpisode(episodeId.ToString()));

                        if (workerTypeId > 0)
                        {
                            foreach (EngineTeamDTO item in teamsFromEngine)
                            {
                                TeamEntity team = new TeamEntity();
                                team = TeamRepository.Instance.GetByIdExterno(item.IdExterno);
                                teams.Add(team);
                            }

                            var teamsVar = from n in teams
                                           where n.WorkerTypeId == workerTypeId
                                           select n;

                            teams = teamsVar.ToList();
                        }
                        else
                        {
                            foreach (EngineTeamDTO item in teamsFromEngine)
                            {
                                TeamEntity team = new TeamEntity();
                                team = TeamRepository.Instance.GetByIdExterno(item.IdExterno);
                                teams.Add(team);
                            }
                        }

                        List <RankingDTO> rankingDTOList = new List <RankingDTO>();

                        foreach (TeamEntity team in teams)
                        {
                            if (team != null)
                            {
                                WorkerTypeEntity workerType = WorkerTypeRepository.Instance.GetById(team.WorkerTypeId);

                                RankingDTO rankingDTO = new RankingDTO();

                                if (workerType.ProfileName.Equals(Profiles.LIDER))
                                {
                                    WorkerEntity sponsor = WorkerRepository.Instance.GetById(team.SponsorId);

                                    rankingDTO            = EngineBIZ.GetGlobalScoreInEpisodeByEpisodeAndPlayer(episodeId.ToString(), sponsor.ExternalId);
                                    rankingDTO.LogoId     = team.LogoId;
                                    rankingDTO.PlayerId   = team.ExternalId;
                                    rankingDTO.PlayerName = team.TeamName;
                                }
                                else
                                {
                                    rankingDTO        = EngineBIZ.GetTeamScoreByTeamId(team.ExternalId);
                                    rankingDTO.LogoId = team.LogoId;
                                }

                                rankingDTOList.Add(rankingDTO);
                            }
                        }
                        searchResult = rankingDTOList;
                    }
                }
                else
                {
                    searchResult = new List <RankingDTO>();
                }

                var searchedQueryList = new List <RankingDTO>();

                searchedQueryList = searchResult;

                if (!string.IsNullOrWhiteSpace(filter))
                {
                    filter = filter.ToLowerInvariant().Trim();
                    var searchedQuery = from n in searchResult
                                        where (n.PlayerName != null && n.PlayerName.ToLowerInvariant().Trim().Contains(filter))
                                        orderby n.Score descending
                                        select n;

                    searchedQueryList = searchedQuery.ToList();
                }
                else
                {
                    var searchedQuery = from n in searchResult
                                        orderby n.Score descending
                                        select n;

                    searchedQueryList = searchedQuery.ToList();
                }

                int index = Int32.Parse(jqueryTableRequest.Order);

                JQueryDataTableResponse response = null;

                if (jqueryTableRequest.Type.Equals("asc"))
                {
                    response = new JQueryDataTableResponse()
                    {
                        Draw            = jqueryTableRequest.Draw,
                        RecordsTotal    = (jqueryTableRequest.Page + 1) * 10 - (10 - searchedQueryList.Count),
                        RecordsFiltered = (jqueryTableRequest.Page + 1) * 10 + 1,
                        Data            = searchedQueryList.Select(r => new string[] { r.PlayerId != null ? r.PlayerId.ToString() : "", r.PlayerName + ";" + r.LogoId.ToString(), r.Score != null ? r.Score.Value.ToString() : 0.ToString() }).ToArray().OrderBy(item => item[index]).ToArray()
                    };
                }
                else
                {
                    response = new JQueryDataTableResponse()
                    {
                        Draw            = jqueryTableRequest.Draw,
                        RecordsTotal    = (jqueryTableRequest.Page + 1) * 10 - (10 - searchedQueryList.Count),
                        RecordsFiltered = (jqueryTableRequest.Page + 1) * 10 + 1,
                        Data            = searchedQueryList.Select(r => new string[] { r.PlayerId != null ? r.PlayerId.ToString() : "", r.PlayerName + ";" + r.LogoId.ToString(), r.Score != null ? r.Score.Value.ToString() : 0.ToString() }).ToArray().OrderByDescending(item => item[index]).ToArray()
                    };
                }

                return(new DataContractResult()
                {
                    Data = response, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }

            return(Json(null, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Get full information of User
        /// #Note: If you add new field to UserBasicInfoDTO model -
        ///        Please write code to set that information in this function
        /// </summary>
        /// <param name="userId"></param>
        /// <returns>UserBasicInfoDTO</returns>
        public UserBasicInfoDTO GetFullInforOfUserAsBasicUser(int userId)
        {
            UserBasicInfoDTO currentUser = new UserBasicInfoDTO();

            int     numberEventDonatedIn = 0;
            decimal totalMoneyDonatedIn  = 0;
            decimal lastDonateMoney      = 0;
            string  lastDonateDate       = "";

            int numberOfPost = 0;

            try
            {
                Ws_User          wsUser          = GetUserById(userId);
                User_Information userInformation = GetUserInformation(userId);

                //Get infomation about donation of this user
                using (var db = new DonationDAL())
                {
                    numberEventDonatedIn = db.GetNumberEventDonatedInByUsingUserId(userId);
                    totalMoneyDonatedIn  = db.GetTotalMoneyDonatedInByUsingUserId(userId);

                    Donation lastDonation = db.GetLastDonateInformation(userId);

                    if (lastDonation != null)
                    {
                        lastDonateMoney = lastDonation.DonatedMoney;
                        lastDonateDate  = lastDonation.DonatedDate.ToString("H:mm:ss dd/MM/yy");
                    }
                }

                //Get number of post for current user
                using (var db = new ThreadDAL())
                {
                    numberOfPost = db.GetNumberOfPostPerUser(userId);
                }
                using (var db = new OrganizationDAL())
                {
                    Organization org = db.GetOrganizationById(userId);
                    if (org != null)
                    {
                        currentUser.OrganazationName = org.OrganizationName;
                    }

                    if (currentUser.OrganazationName == "")
                    {
                        currentUser.OrganazationName = "Chưa có";
                    }
                }
                using (var db = new Ws_DataContext())
                {
                    currentUser.JoinedDate = db.Ws_User.Where(x => x.UserID == userId).SingleOrDefault().CreatedDate.ToString("dd/mm/yyyy");
                }

                //get ranking information
                WsRanking  ranking = new WsRanking();
                RankingDTO rank    = new RankingDTO();


                //Set information for user which want to get
                currentUser.UserId      = userId;
                currentUser.UserName    = wsUser.UserName;
                currentUser.AccountType = wsUser.AccountType;
                currentUser.IsActive    = wsUser.IsActive;
                currentUser.IsVerify    = wsUser.IsVerify;

                currentUser.Email = wsUser.Email;
                if (userInformation != null)
                {
                    rank = ranking.RankingWithPoint(userInformation.Point);
                    currentUser.FacebookUri   = userInformation.FacebookUrl;
                    currentUser.FullName      = userInformation.FullName;
                    currentUser.ProfileImage  = userInformation.ProfileImage;
                    currentUser.Gender        = userInformation.Gender;
                    currentUser.Phone         = userInformation.Phone;
                    currentUser.Address       = userInformation.UserAddress;
                    currentUser.UserSignature = userInformation.UserSignature;

                    if (userInformation.DoB != null)
                    {
                        currentUser.DOB = userInformation.DoB.Value.ToString("dd/MM/yyyy");
                    }

                    currentUser.Country     = userInformation.Country;
                    currentUser.FacebookUri = userInformation.FacebookUrl;
                    currentUser.CreateDate  = wsUser.CreatedDate.ToString("dd/MM/yyyy");
                    currentUser.Point       = userInformation.Point;
                }

                currentUser.NumberOfPost = numberOfPost;

                if (rank.CurrentRank == 0)
                {
                    currentUser.CurrentRank = "Mới";
                }
                else if (rank.CurrentRank == 200)
                {
                    currentUser.CurrentRank = "Đồng";
                }
                else if (rank.CurrentRank == 500)
                {
                    currentUser.CurrentRank = "Bạc";
                }
                else if (rank.CurrentRank == 2000)
                {
                    currentUser.CurrentRank = "Vàng";
                }
                else if (rank.CurrentRank == 5000)
                {
                    currentUser.CurrentRank = "Bạch Kim";
                }
                else if (rank.CurrentRank == 10000)
                {
                    currentUser.CurrentRank = "Kim Cương";
                }

                currentUser.RankPercent          = rank.RankPercent;
                currentUser.NumberEventDonatedIn = numberEventDonatedIn;
                currentUser.TotalMoneyDonatedIn  = totalMoneyDonatedIn;
                currentUser.LastDonateMoney      = lastDonateMoney;
                currentUser.LastDonateDate       = lastDonateDate;
            }
            catch (Exception)
            {
                //throw;
            }

            return(currentUser);
        }