コード例 #1
0
        public IActionResult CreateGender([FromBody] Gender gender)
        {
            try
            {
                if (gender.IsEntityNull())
                {
                    return(BadRequest("Gender object is null"));
                }

                if (!gender.IsEntityEmpty())
                {
                    return(BadRequest("For create, the Id must be null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                _genderService.CreateGender(gender);
                _genderService.Save();

                return(CreatedAtRoute("GenderById", new { id = gender.Id.Value }, gender));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in call : api/gender/CreateGender", gender);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }