Exemple #1
0
        public IActionResult GetUser(int userId)
        {
            var userFromRepo = _croudSeekRepository.GetUser(userId);

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

            return(Ok(_mapper.Map <UserDto>(userFromRepo)));
        }
        public ActionResult <IEnumerable <QuestDto> > GetQuests()
        {
            var user           = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value;
            var userEntity     = _croudSeekRepository.GetUsers().Where((u) => u.Name == user).FirstOrDefault();
            var questsFromRepo = _croudSeekRepository.GetQuests().Where(q => q.OwnerId == userEntity?.Id || !q.IsPrivate);
            var questDtos      = _mapper.Map <IEnumerable <QuestDto> >(questsFromRepo).Select((q) =>
            {
                q.CanEdit           = true;
                var questUserEntity = _croudSeekRepository.GetUser(q.OwnerId);
                q.IsOwner           = questUserEntity?.Name == user;
                return(q);
            });

            return(Ok(questDtos));
        }
        public ActionResult <IEnumerable <DataPointDto> > GetDataPointsForQuest(int questId)
        {
            if (!_croudSeekRepository.QuestExists(questId))
            {
                return(NotFound());
            }
            var user       = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value;
            var userEntity = _croudSeekRepository.GetUsers().Where((u) => u.Name == user).FirstOrDefault();

            var dataPointsForQuestFromRepo = _croudSeekRepository.GetDataPointsByQuest(questId).Where(dp => dp.OwnerId == userEntity?.Id || !dp.IsPrivate);
            var result = Ok(_mapper.Map <IEnumerable <DataPointDto> >(dataPointsForQuestFromRepo).Select((dp) =>
            {
                var dpEntity = _croudSeekRepository.GetUser(dp.OwnerId);
                dp.CanEdit   = dpEntity?.Name == user;
                dp.IsOwner   = dpEntity?.Name == user;
                return(dp);
            }));

            return(result);
        }
        public ActionResult <UserWeightDto> CreateUserWeight(UserWeightForCreationDto userWeight)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var userFromRepo = _croudSeekRepository.GetUser(userWeight.UserId);

            if (userFromRepo == null)
            {
                return(NotFound());
            }
            var userWeightEntity = _mapper.Map <Entities.UserWeight>(userWeight);

            _croudSeekRepository.AddUserWeight(userWeightEntity);
            _croudSeekRepository.Save();

            var userWeightToReturn = _mapper.Map <UserWeightDto>(userWeightEntity);

            return(CreatedAtRoute("GetUserWeight",
                                  new { userWeightId = userWeightToReturn.Id },
                                  userWeightToReturn));
        }