示例#1
0
        public IActionResult CreateDataTypeClass([FromRoute] string languageId, [FromBody] KClass dataClas)
        {
            try
            {
                var userId = string.Empty;
                if (Request.Headers.ContainsKey("Authorization"))
                {
                    userId = Request.Headers.ContainsKey("Authorization") ? Request.Headers["Authorization"].ToString() : userId;
                }

                var tempCommand = new CreateDatatypeEntityRequestModel()
                {
                    Datatype   = dataClas,
                    UserId     = userId,
                    LanguageId = languageId
                };

                // ClassType should be UserDefined for all user defined class
                tempCommand.Datatype.ClassType = KClassType.UserDefinedClass;

                List <System.ComponentModel.DataAnnotations.ValidationResult> validationResult = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
                if (dataClas == null)
                {
                    validationResult.Add(new System.ComponentModel.DataAnnotations.ValidationResult("DataClass can not be null"));
                }
                else if (string.IsNullOrEmpty(dataClas.Name))
                {
                    validationResult.Add(new System.ComponentModel.DataAnnotations.ValidationResult("Class name can not be null"));
                }

                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(Ok(MongoConnector.CreateDataClass(new CreateDatatypeEntityRequestModel {
                    Datatype = dataClas, LanguageId = languageId, UserId = userId
                })));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }