Esempio n. 1
0
        public override string Execute()
        {
            Console.WriteLine($"Trying to update property \"{Name}\"...");

            string message;

            var project = _projectService.GetProjectByName(Project).Result;

            if (project != null)
            {
                var model = _projectDataModelService.GetProjectDataModelByName(project.Id, Model).Result;

                if (model != null)
                {
                    var property = _projectDataModelService.GetProjectDataModelPropertyByName(project.Id, model.Id, Name).Result;

                    int?   relatedModelId = null;
                    string relationalType = null;
                    if (!string.IsNullOrEmpty(Relational))
                    {
                        var relatedModel = _projectDataModelService.GetProjectDataModelByName(project.Id, Relational).Result;

                        if (relatedModel != null)
                        {
                            relatedModelId = relatedModel.Id;
                            relationalType = RelationalType;
                        }
                        else
                        {
                            message = $"Related model {Relational} was not found";
                            Logger.LogInformation(message);
                            return(message);
                        }
                    }

                    if (property != null)
                    {
                        _projectDataModelService.UpdateProjectDataModelProperty(project.Id, model.Id, property.Id, new UpdateProjectDataModelPropertyDto
                        {
                            Id          = property.Id,
                            Name        = Rename ?? property.Name,
                            Label       = Label ?? property.Label,
                            DataType    = Type ?? property.DataType,
                            IsRequired  = Required ?? property.IsRequired,
                            ControlType = ControlType ?? property.ControlType,
                            RelatedProjectDataModelId = relatedModelId ?? property.RelatedProjectDataModelId,
                            RelationalType            = relationalType ?? property.RelationalType,
                            IsManaged = Managed ?? property.IsManaged
                        }).Wait();

                        message = $"Property {Name} has been updated successfully";
                        return(message);
                    }
                }
            }

            message = $"Failed to update property {Name}. Make sure the project, model, and property names are correct.";

            return(message);
        }