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"));
            }
        }
Beispiel #2
0
        /// <summary>Save gender.</summary>
        /// <param name = "model">gender model.</param>
        /// <returns>The <see cref = "GenderModel"/>.</returns>
        private RawResponseModel <GenderModel> SaveRow(GenderModel model)
        {
            if (model == null)
            {
                return(new RawResponseModel <GenderModel>(null, "model can't be null!", false));
            }

            ////region CustomCodeBlockBeforeSave#
            ////endregion CustomCodeBlockBeforeSave#
            var result    = _logic.Save(model);
            var primaryId = result.Data.Id;

            ////region CustomCodeBlockSubICollectionSave#
            ////endregion CustomCodeBlockSubICollectionSave#
            return(result);
        }