private ControllerClass TransformToControllerClass(Data.Entity entityConfig, CodeGenerationModel genModel, EntityClass entityClass, ManagerInterface managerInterface) { var data = new ControllerClass(); data.Name = $"{entityClass.Name}Controller"; data.Namespace = $"{genModel.BaseNamespace}.Api.Controllers"; data.Partial = entityConfig.PartialWebApi; data.PrivateConstructor = entityConfig.PrivateWebApiConstructor; data.WebApiRoutePrefix = entityConfig.WebApiRoutePrefix; data.Usings.Add("Microsoft.AspNetCore.Mvc"); data.Usings.Add("System"); data.Usings.Add("System.Net"); data.Usings.Add("Beef"); data.Usings.Add("Beef.AspNetCore.WebApi"); data.Usings.Add(entityClass.Namespace); data.Usings.Add(managerInterface.Namespace); data.Operations = entityConfig.Operations.Select(o => { var op = CreateOperation <ControllerOperationModel>(o, entityClass); op.WebApiRoute = o.WebApiRoute; if (op.IsGet || op.IsDelete) { op.WebApiRoute = op.WebApiRoute ?? String.Join('/', op.Parameters.Select(o => $"{{{o.Name}}}")); } if (op.IsGetColl) { op.WebApiRoute = op.WebApiRoute ?? ""; op.HasPagingArgs = o.PagingArgs; } if (op.IsUpdate) { op.Parameters.AddRange(entityClass.Properties.Where(o => o.UnqiueKey).Select(o => new OperationParameter { Name = o.Name.ToCamelCase(), Type = o.Type, EntityProperty = o.Name })); op.WebApiRoute = op.WebApiRoute ?? String.Join('/', op.Parameters.Skip(1).Select(o => $"{{{o.Name}}}")); } return(op); }).ToList(); return(data); }
private ServiceAgentClass TransformToServiceAgentClass(Data.Entity entityConfig, CodeGenerationModel genModel, EntityClass entityClass, ControllerClass controllerClass) { var data = new ServiceAgentClass(); data.Name = $"{entityClass.Name}ServiceAgent"; data.Namespace = $"{genModel.BaseNamespace}.Common.ServiceAgents"; data.Partial = false; data.PrivateConstructor = false; data.Usings.Add("Beef.WebApi"); data.Usings.Add(entityClass.Namespace); data.Usings.Add("Microsoft.Extensions.Options"); data.Usings.Add("System"); data.Usings.Add("System.Threading.Tasks"); data.Operations = entityConfig.Operations.Select(o => { var op = CreateOperation <ControllerOperationModel>(o, entityClass); var webOp = controllerClass.Operations.First(w => w.Name == op.Name); op.WebApiRoute = string.Join("/", new string[] { controllerClass.WebApiRoutePrefix, webOp.WebApiRoute }.Where(o => o != null)); op.HasPagingArgs = webOp.HasPagingArgs; if (op.IsGetColl && o.PagingArgs) { op.Parameters.Add(new OperationParameter { Name = "pagingArgs", Type = "PagingArgs?" }); data.Usings.Add("Beef.Entities"); } return(op); }).ToList(); return(data); }