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");
        }
Exemple #2
0
        public async Task <IActionResult> UpdateUser(int id, UserForUpdateDto userForUpdateDto)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userFromRepo = await _repo.GetUser(id);

            _mapper.Map(userForUpdateDto, userFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new System.Exception($"Updating user {id} failed on save");
        }