protected override void AddTemplateParameters(IDictionary <string, object> templateParameters)
        {
            base.AddTemplateParameters(templateParameters);
            CodeType      codeType = base.Model.ModelType.CodeType;
            ModelMetadata codeModelModelMetadatum = new CodeModelModelMetadata(codeType);

            if ((int)codeModelModelMetadatum.PrimaryKeys.Length == 0)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "The entity type '{0}' has no key defined. Define a key for this entity type.", codeType.Name));
            }
            templateParameters.Add("ModelMetadata", codeModelModelMetadatum);
            List <CodeType> codeTypes = new List <CodeType>()
            {
                codeType
            };

            templateParameters.Add("RequiredNamespaces", base.GetRequiredNamespaces(codeTypes));
            templateParameters.Add("ModelTypeNamespace", (codeType.Namespace != null ? codeType.Namespace.FullName : string.Empty));
            templateParameters.Add("ModelTypeName", codeType.Name);
            templateParameters.Add("UseAsync", base.Model.IsAsyncSelected);
            IEntityFrameworkService service = base.Context.ServiceProvider.GetService <IEntityFrameworkService>();
            string pluralizedWord           = service.GetPluralizedWord(codeType.Name, CultureInfo.InvariantCulture);

            templateParameters.Add("EntitySetName", pluralizedWord);
            CodeDomProvider codeDomProvider = ValidationUtil.GenerateCodeDomProvider(ProjectExtensions.GetCodeLanguage(base.Model.ActiveProject));
            string          str             = codeDomProvider.CreateEscapedIdentifier(codeType.Name.ToLowerInvariantFirstChar());
            string          str1            = codeDomProvider.CreateEscapedIdentifier(pluralizedWord.ToLowerInvariantFirstChar());

            templateParameters.Add("ModelVariable", str);
            templateParameters.Add("EntitySetVariable", str1);
            templateParameters.Add("ODataModificationMessage", "The WebApiConfig class may require additional changes to add a route for this controller. Merge these statements into the Register method of the WebApiConfig class as applicable. Note that OData URLs are case sensitive.");

            templateParameters.Add("IsLegacyOdataVersion", base.Framework.IsODataLegacy(base.Context));
        }
        public string GenerateControllerName(string modelClassName)
        {
            if (string.IsNullOrWhiteSpace(modelClassName))
            {
                return(null);
            }
            IEntityFrameworkService service = base.Context.ServiceProvider.GetService <IEntityFrameworkService>();
            string pluralizedWord           = service.GetPluralizedWord(modelClassName, CultureInfo.GetCultureInfo(1033)) ?? modelClassName;

            return(base.GetGeneratedName(string.Concat(pluralizedWord, "{0}", MvcProjectUtil.ControllerSuffix), base.CodeFileExtension));
        }
Exemple #3
0
        public string GenerateControllerName(string modelClassName)
        {
            if (String.IsNullOrWhiteSpace(modelClassName))
            {
                return(null);
            }

            IEntityFrameworkService efService = Context.ServiceProvider.GetService <IEntityFrameworkService>();
            string controllerRootName         = efService.GetPluralizedWord(modelClassName, CultureInfo.GetCultureInfo(1033));

            if (controllerRootName == null)
            {
                controllerRootName = modelClassName;
            }

            return(GetGeneratedName(controllerRootName + "{0}" + MvcProjectUtil.ControllerSuffix, CodeFileExtension));
        }
Exemple #4
0
        protected override void AddTemplateParameters(IDictionary <string, object> templateParameters)
        {
            base.AddTemplateParameters(templateParameters);

            CodeType      codeType = Model.ModelType.CodeType;
            ModelMetadata metadata = new CodeModelModelMetadata(codeType);

            if (metadata.PrimaryKeys.Length == 0)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.NoKeyDefinedError, codeType.Name));
            }
            templateParameters.Add("ModelMetadata", metadata);

            HashSet <string> requiredNamespaces = GetRequiredNamespaces(new List <CodeType>()
            {
                codeType
            });

            templateParameters.Add("RequiredNamespaces", requiredNamespaces);

            string modelTypeNamespace = codeType.Namespace != null ? codeType.Namespace.FullName : String.Empty;

            templateParameters.Add("ModelTypeNamespace", modelTypeNamespace);
            templateParameters.Add("ModelTypeName", codeType.Name);
            templateParameters.Add("UseAsync", Model.IsAsyncSelected);

            IEntityFrameworkService efService = Context.ServiceProvider.GetService <IEntityFrameworkService>();
            string entitySetName = efService.GetPluralizedWord(codeType.Name, CultureInfo.InvariantCulture);

            templateParameters.Add("EntitySetName", entitySetName);

            CodeDomProvider provider          = ValidationUtil.GenerateCodeDomProvider(Model.ActiveProject.GetCodeLanguage());
            string          modelVariable     = provider.CreateEscapedIdentifier(codeType.Name.ToLowerInvariantFirstChar());
            string          entitySetVariable = provider.CreateEscapedIdentifier(entitySetName.ToLowerInvariantFirstChar());

            templateParameters.Add("ModelVariable", modelVariable);
            templateParameters.Add("EntitySetVariable", entitySetVariable);

            templateParameters.Add("ODataModificationMessage", Resources.ScaffoldODataModificationMessage);
            templateParameters.Add("IsLegacyOdataVersion", Framework.IsODataLegacy(Context));
        }