Esempio n. 1
0
        protected virtual async Task Create(LeaderboardDto input)
        {
            Leaderboard comment = MappingProfile.MappingConfigurationSetups().Map <Leaderboard>(input);

            _context.Leaderboard.Add(comment);
            await _context.SaveChangesAsync();
        }
Esempio n. 2
0
        public void AddOrUpdate(LeaderboardDto leaderboardDto, DateTime scoreDate)
        {
            string sql  = string.Empty;
            var    user = _userRepository.GetByUsername(leaderboardDto.Username);

            if (user == null)
            {
                sql = @" DECLARE @id INT;
                         BEGIN TRY
                         BEGIN TRANSACTION
                         INSERT INTO Users(Username)  VALUES(@Username) set @id = (SELECT SCOPE_IDENTITY())
                         INSERT INTO UserScores(UserId, Score, ScoreDate, CreateDate) VALUES(@id, @Score, @ScoreDate, @CreateDate)
                         COMMIT TRANSACTION
                         END TRY
                         BEGIN CATCH
                         ROLLBACK TRANSACTION
                         END CATCH";

                _unitOfWork.Connection.Query <int>(sql,
                                                   new
                {
                    Username   = leaderboardDto.Username,
                    Score      = leaderboardDto.Score,
                    ScoreDate  = scoreDate,
                    CreateDate = DateTime.Now
                }
                                                   ).FirstOrDefault();
            }
            else
            {
                bool updateFlag = GetByDate(scoreDate, user.Id);
                if (updateFlag)
                {
                    sql = "UPDATE UserScores Set Score = @Score, UpdateDate = @UpdateDate WHERE UserId = @UserId";
                    _unitOfWork.Connection.Query <int>(sql,
                                                       new
                    {
                        UserId     = user.Id,
                        Score      = leaderboardDto.Score,
                        Updatedate = DateTime.Now
                    }
                                                       ).FirstOrDefault();
                }
                else
                {
                    sql = "INSERT INTO UserScores(UserId, Score, ScoreDate, CreateDate) VALUES(@id, @Score, @ScoreDate, @CreateDate)";
                    _unitOfWork.Connection.Query <int>(sql,
                                                       new
                    {
                        id         = user.Id,
                        Score      = leaderboardDto.Score,
                        ScoreDate  = scoreDate,
                        CreateDate = DateTime.Now
                    }
                                                       ).FirstOrDefault();
                }
            }
        }
Esempio n. 3
0
        protected virtual async Task Update(LeaderboardDto input)
        {
            var leaderboard = await _context.Leaderboard.Where(x => x.Id == input.Id).FirstOrDefaultAsync();

            if (leaderboard != null)
            {
                Leaderboard leaderboardDto = MappingProfile.MappingConfigurationSetups().Map <Leaderboard>(input);
                _context.Leaderboard.Update(leaderboardDto);
                await _context.SaveChangesAsync();
            }
        }
Esempio n. 4
0
 public async Task CreateOrEditLeaderboard(LeaderboardDto input)
 {
     if (input.Id == 0)
     {
         await Create(input);
     }
     else
     {
         await Update(input);
     }
 }
Esempio n. 5
0
        public async Task <LeaderboardDto> GetLeaderboardForEdit(LeaderboardDto input)
        {
            var leaderboard = await _context.Leaderboard.Where(x => x.Id == input.Id).FirstOrDefaultAsync();

            if (leaderboard != null)
            {
                Leaderboard leaderboardDto = MappingProfile.MappingConfigurationSetups().Map <Leaderboard>(input);
                _context.Leaderboard.Update(leaderboardDto);
                await _context.SaveChangesAsync();

                return(MappingProfile.MappingConfigurationSetups().Map <LeaderboardDto>(leaderboardDto));
            }
            return(new LeaderboardDto());
        }
        public IActionResult InitializeNewLeadeboard([FromBody] LeaderboardDto leaderboardDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!_isAdmin)
            {
                return(Unauthorized());
            }
            _leaderboard = new Leaderboard(leaderboardDto.Entries, leaderboardDto.Size);
            _hubContext.Clients.All.SendAsync("Update");
            return(Redirect(Request.Headers["Referer"]));
        }
        public ActionResult Post([FromBody] LeaderboardDto LeaderboardDto)
        {
            try
            {
                if (LeaderboardDto == null)
                {
                    return(NotFound());
                }

                applicationServiceLeaderboard.Add(LeaderboardDto);
                return(Ok());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    private IEnumerator GetLeaderboard(Action onOk, Action onFail)
    {
        UnityWebRequest www = UnityWebRequest.Get(string.Format("{0}:{1}/api/leaderboard", _serverPath, _port));

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.responseCode != 200)
        {
            StartCoroutine(ShowError(www.error));
            onFail();
        }
        else
        {
            Debug.Log(www.responseCode);
            Debug.Log(www.downloadHandler.text);
            LeaderboardDto lbDto = JsonUtility.FromJson <LeaderboardDto>(www.downloadHandler.text);
            LeaderboardModel = new LeaderboardModel(lbDto);
            onOk();
        }

        _getLeaderboardCoroutine = null;
    }
Esempio n. 9
0
        public List <LeaderboardDto> GetAllLeaderboard(LeaderboardDto input)
        {
            var query = (from leaderboard in _context.Leaderboard.ToList()
                         join topic in _context.Topic.ToList()
                         on leaderboard.TopicId equals topic.Id

                         join questionCategory in _context.QuestionCategory.ToList()
                         on leaderboard.QuestionCategoryId equals questionCategory.Id

                         select new LeaderboardDto
            {
                TopicName = topic.Name,
                QuestionCategoryName = questionCategory.Name,
                Id = leaderboard.Id,
                DateCreated = leaderboard.DateCreated,
                Status = leaderboard.Status,
                UserId = leaderboard.UserId,
                Score = leaderboard.Score
            }).ToList().Skip((input.PagedResultDto.Page - 1) * input.PagedResultDto.SkipCount).Take(input.PagedResultDto.MaxResultCount);

            // Map Records
            List <LeaderboardDto> ratingDto = MappingProfile.MappingConfigurationSetups().Map <List <LeaderboardDto> >(query);

            //Apply Sort
            ratingDto = Sort(input.PagedResultDto.Sort, input.PagedResultDto.SortOrder, ratingDto);

            // Apply search
            if (!string.IsNullOrEmpty(input.PagedResultDto.Search))
            {
                ratingDto = ratingDto.Where(p => p.Status != null && p.Status.ToLower().ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower()) ||
                                            p.TopicName != null && p.TopicName.ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower()) ||
                                            p.DateCreated != null && p.DateCreated.ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower()) ||
                                            p.QuestionCategoryName != null && p.QuestionCategoryName.ToString().ToLower().ToString().Contains(input.PagedResultDto.Search.ToLower()) ||
                                            p.Score != null && p.Score.ToString().ToLower().ToString().Contains(input.PagedResultDto.Search.ToLower())
                                            ).ToList();
            }
            return(ratingDto);
        }
Esempio n. 10
0
        public void Add(LeaderboardDto leaderboardDto)
        {
            var leaderboard = mapper.Map <Leaderboard>(leaderboardDto);

            leaderboardService.Add(leaderboard);
        }
Esempio n. 11
0
 public List <LeaderboardDto> GetAllLeaderboard(LeaderboardDto input)
 {
     return(_unitOfWork.Leaderboards.GetAllLeaderboard(input));
 }
Esempio n. 12
0
 public async Task GetLeaderboardForEdit(LeaderboardDto input)
 {
     await _unitOfWork.Leaderboards.GetLeaderboardForEdit(input);
 }
Esempio n. 13
0
 public async Task CreateOrEditLeaderboard(LeaderboardDto input)
 {
     await _unitOfWork.Leaderboards.CreateOrEditLeaderboard(input);
 }
Esempio n. 14
0
 public LeaderboardModel(LeaderboardDto leaderboard)
 {
     _playerResultModels = leaderboard.leaderboard;
 }