예제 #1
0
        public IActionResult GetUser(int id)
        {
            User user = _dataRepository.Get(id);

            if (user == null)
            {
                return(NotFound("The User record couldn't be found."));
            }
            return(Ok(user));
        }
예제 #2
0
        public async Task <ActionResult> Index(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(RedirectToAction("Index", "Home"));
            }

            UserId = id;

            var existingUser = await _userDataRepo.Get(id);

            var model = new SurveyResponseViewModel();

            if (existingUser != null)
            {
                model.ScoreboardName = existingUser.ScoreboardName;
            }

            return(View(model));
        }
예제 #3
0
        public async Task <IEnumerable <UserData> > Post(IEnumerable <ScoreData> scores, string p)
        {
            if (p != ConfigurationManager.AppSettings["SyncPass"])
            {
                return(null);
            }

            var users         = (await _userDataRepo.Get()).ToDictionary(x => x.UserId, x => x);
            var usersToUpdate = new HashSet <UserData>();

            foreach (var score in scores)
            {
                UserData user;

                if (users.ContainsKey(score.UserId))
                {
                    user = users[score.UserId];
                }
                else
                {
                    user = new UserData {
                        UserId = score.UserId
                    };
                    users.Add(score.UserId, user);
                    usersToUpdate.Add(user);
                }

                if (user.Score != score.Score)
                {
                    user.Score = score.Score;
                    usersToUpdate.Add(user);
                }
            }

            if (usersToUpdate.Any())
            {
                await _userDataRepo.SaveBatch(usersToUpdate);
            }

            return(users.Values);
        }
예제 #4
0
 public async Task <ActionResult> Index()
 {
     return(View((await _userDataRepo.Get()).OrderByDescending(x => x.Score).ToList()));
 }