public async Task <IActionResult> CreateUserMeasure(int userId,
                                                            UserMeasureForCreationDto userMeasureForCreationDto)
        {
            var sender = await _repo.GetUser(userId);

            if (sender.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var message = _mapper.Map <UserMeasure>(userMeasureForCreationDto);

            _repo.Add(message);


            if (await _repo.SaveAll())
            {
                var messageToReturn = _mapper.Map <UserMeasureToReturnDto>(message);
                return(CreatedAtRoute("GetUserMeasure",
                                      new { userId, id = message.Id }, messageToReturn));
            }

            // await _repo.SaveAll();

            // return Ok();

            throw new Exception("Creating the userMeasure failed on save");
        }
示例#2
0
        public async Task <IActionResult> GetUsers([FromQuery] UserParams userParams)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var userFromRepo = await _repo.GetUser(currentUserId);

            userParams.UserId = currentUserId;
            if (string.IsNullOrEmpty(userParams.Gender))
            {
                userParams.Gender = userFromRepo.Gender == "male" ? "female" : "male";
            }

            var users = await _repo.GetUsers(userParams);

            var usersToReturn = _mapper.Map <IEnumerable <UserForListDto> >(users);

            Response.AddPagination(users.CurrentPage, users.PageSize,
                                   users.TotalCount, users.TotalPages);

            return(Ok(usersToReturn));
        }