コード例 #1
0
        public IActionResult Post([FromBody] Goal item)
        {
            try
            {
                if (item == null || !ModelState.IsValid || item.GoalId != 0 || item.User != null)
                {
                    return(BadRequest(ErrorCode.DataProvidedIsInvalid.ToString()));
                }

                var email    = User.FindFirstValue(ClaimTypes.Email);
                var userItem = _userRepository.Find(email);
                if (userItem == null)
                {
                    return(BadRequest(ErrorCode.DataProvidedIsInvalid.ToString()));
                }

                item.UserId = userItem.UserId;

                _goalRepository.Insert(item);
            }
            catch (Exception)
            {
                return(BadRequest(ErrorCode.CouldNotCreateItem.ToString()));
            }

            return(Ok(item));
        }