コード例 #1
0
        public IActionResult Post([FromBody] Credentials credentials)
        {
            try
            {
                if (credentials == null || !ModelState.IsValid)
                {
                    return(BadRequest(ErrorCode.SomeFieldsRequired.ToString()));
                }
                bool itemExists = _credentialsRepository.DoesItemExist(credentials.username);
                if (itemExists)
                {
                    return(StatusCode(StatusCodes.Status409Conflict, ErrorCode.ItemInUse.ToString()));
                }

                _credentialsRepository.Post(credentials);
            }
            catch (Exception)
            {
                return(BadRequest(ErrorCode.CouldNotCreateItem.ToString()));
            }
            return(Ok(credentials));
        }