public ActionResult <CommonResponeModel> Create(TrainingCourseCreateRequestModel model) { var databaseObject = model.MapTo <TrainingCourse>(); //empty code if (string.IsNullOrEmpty(databaseObject.Code)) { var code = entityCenterRepository.GetCodeByEntity(nameof(TrainingCourse)); if (string.IsNullOrEmpty(code)) { Result = new ErrorResult(ActionType.Insert, AppGlobal.MakeCodeError); return(GetCommonRespone()); } databaseObject.Code = code; } //check exist in db if (trainingCourseRepository.IsExistCode(databaseObject.Code)) { Result = new ErrorResult(ActionType.Insert, AppGlobal.ExistCodeError); return(GetCommonRespone()); } databaseObject.InitBeforeSave(RequestUsername, InitType.Create); int result = trainingCourseRepository.Insert(databaseObject); if (result > 0) { Result = new SuccessResultFactory().Factory(ActionType.Insert); } else { Result = new ErrorResultFactory().Factory(ActionType.Insert); } return(GetCommonRespone()); }