Пример #1
0
        private static string GenerateBasicUpdateSnippet(EntityItemModel selectedEntityInfo, List <WebAPIAttributeItemModel> selectedAttributes, APIOperationTypes opType, AssociationInfo association, bool addFields)
        {
            StringBuilder snippetTextBuilder = new StringBuilder();

            snippetTextBuilder.AppendLine("/*This is a sample basic update snippet using the PATCH operator. You need to specify the ID of the record being updated and the JSON data object for the fields you want to update.*/");

            string        json       = addFields ? GenerateJsonFromFields(selectedAttributes, APIOperationTypes.BasicUpdate) : "";
            StringBuilder jsonObject = new StringBuilder();

            jsonObject.AppendLine("var dataObject={");
            jsonObject.AppendLine(json);
            jsonObject.AppendLine("};");


            snippetTextBuilder.AppendLine(jsonObject.ToString());


            snippetTextBuilder.AppendLine("webapi.safeAjax({");
            snippetTextBuilder.AppendLine("\ttype: \"PATCH\",");
            snippetTextBuilder.AppendLine("\turl: \"/_api/" + selectedEntityInfo.CollectionName + "(00000000-0000-0000-0000-000000000000)\",");
            snippetTextBuilder.AppendLine("\tcontentType:\"application/json\",");
            snippetTextBuilder.AppendLine("\tdata: JSON.stringify(dataObject),");
            snippetTextBuilder.AppendLine("\tsuccess: function(res) {");
            snippetTextBuilder.AppendLine("\t\tconsole.log(res)");
            snippetTextBuilder.AppendLine("\t}");
            snippetTextBuilder.AppendLine("});");


            return(snippetTextBuilder.ToString());
        }
Пример #2
0
        private static string GenerateBasicCreateSnippet(EntityItemModel selectedEntityInfo, List <WebAPIAttributeItemModel> selectedAttributes, APIOperationTypes opType, AssociationInfo association, bool addFields)
        {
            string        json               = addFields ? GenerateJsonFromFields(selectedAttributes, opType) : "";
            StringBuilder jsonObject         = new StringBuilder();
            StringBuilder snippetTextBuilder = new StringBuilder();

            snippetTextBuilder.AppendLine("/*This is a sample create snippet using the POST operator. Use this snippet inside your record creation logic. Replace or modify the data object properties per your needs. Make sure that these properies are enabled for web api.*/");


            jsonObject.AppendLine("var dataObject={");
            jsonObject.AppendLine(json);
            jsonObject.AppendLine("};");


            snippetTextBuilder.AppendLine(jsonObject.ToString());


            snippetTextBuilder.AppendLine("webapi.safeAjax({");
            snippetTextBuilder.AppendLine("\ttype: \"POST\",");
            snippetTextBuilder.AppendLine("\turl: \"/_api/" + selectedEntityInfo.CollectionName + "\",");
            snippetTextBuilder.AppendLine("\tcontentType:\"application/json\",");
            snippetTextBuilder.AppendLine("\tdata: JSON.stringify(dataObject),");
            snippetTextBuilder.AppendLine("\tsuccess: function(res, status, xhr) {");
            snippetTextBuilder.AppendLine("\t\t//print id of newly created entity record");
            snippetTextBuilder.AppendLine("\t\tconsole.log(\"entityID: \" + xhr.getResponseHeader(\"entityid\"))");
            snippetTextBuilder.AppendLine("\t}");
            snippetTextBuilder.AppendLine("});");


            return(snippetTextBuilder.ToString());
        }
Пример #3
0
        public static string GenerateSnippet(EntityItemModel selectedEntityInfo, List <WebAPIAttributeItemModel> selectedAttributes, APIOperationTypes opType, AssociationInfo association, bool addFields)
        {
            switch (opType)
            {
            case APIOperationTypes.BasicCreate:
                return(GenerateBasicCreateSnippet(selectedEntityInfo, selectedAttributes, opType, association, addFields));

            case APIOperationTypes.UpdateSingle:
                return(GenerateUpdateSingleSnippet(selectedEntityInfo, selectedAttributes, addFields));

            case APIOperationTypes.BasicUpdate:
                return(GenerateBasicUpdateSnippet(selectedEntityInfo, selectedAttributes, opType, association, addFields));

            case APIOperationTypes.BasicDelete:
                return(GenerateBasicDeleteSnippet(selectedEntityInfo, selectedAttributes));

            case APIOperationTypes.DeleteSingle:
                return(GenerateDeleteSingleSnippet(selectedEntityInfo, selectedAttributes, addFields));

            case APIOperationTypes.AssociateDisassociate:

                break;

            default:
                throw new NotImplementedException("This operation is not implemented yet");
            }

            return("");
        }