public bool Match(ClassModel domainModel, OperationModel operationModel)
        {
            var lowerDomainName    = domainModel.Name.ToLower();
            var lowerOperationName = operationModel.Name.ToLower();

            if (operationModel.Parameters.Count() != 1)
            {
                return(false);
            }

            if (!operationModel.Parameters.Any(p => string.Equals(p.Name, "id", StringComparison.InvariantCultureIgnoreCase) ||
                                               string.Equals(p.Name, $"{lowerDomainName}Id", StringComparison.InvariantCultureIgnoreCase)))
            {
                return(false);
            }

            if (operationModel.TypeReference.Element != null)
            {
                return(false);
            }

            return(new[]
            {
                "delete",
                $"delete{lowerDomainName}"
            }
                   .Contains(lowerOperationName));
        }
        public bool Match(ClassModel domainModel, OperationModel operationModel)
        {
            var entityName         = domainModel.Name.ToLower();
            var lowerOperationName = operationModel.Name.ToLower();

            if (operationModel.Parameters.Count() != 1)
            {
                return(false);
            }

            if (!operationModel.Parameters.Any(p => string.Equals(p.Name, "id", StringComparison.InvariantCultureIgnoreCase) ||
                                               string.Equals(p.Name, $"{entityName}Id", StringComparison.InvariantCultureIgnoreCase)))
            {
                return(false);
            }

            if (operationModel?.TypeReference?.IsCollection ?? false)
            {
                return(false);
            }


            return(new[]
            {
                "get",
                $"get{entityName}",
                "find",
                "findbyid",
                $"find{entityName}",
                $"find{entityName}byid",
                entityName
            }
                   .Contains(lowerOperationName));
        }
        public string GetImplementation(ClassModel domainModel, OperationModel operationModel)
        {
            var dto = _decorator.FindDTOModel(operationModel.TypeReference.Element.Id);

            return($@"var element ={ (operationModel.IsAsync() ? " await" : "") } {domainModel.Name.ToPrivateMember()}Repository.FindById{ (operationModel.IsAsync() ? "Async" : "") }({operationModel.Parameters.First().Name.ToCamelCase()});
            return element.MapTo{_decorator.Template.GetTypeName(DtoModelTemplate.TemplateId, dto)}(_mapper);");
        }
Example #4
0
        public bool Match(ClassModel domainModel, OperationModel operationModel)
        {
            if (operationModel.Parameters.Count() != 1)
            {
                return(false);
            }

            if (operationModel.TypeReference.Element != null && !_decorator.Template.GetTypeInfo(operationModel.TypeReference).IsPrimitive)
            {
                return(false);
            }

            var lowerDomainName    = domainModel.Name.ToLower();
            var lowerOperationName = operationModel.Name.ToLower();

            return(new[]
            {
                "post",
                $"post{lowerDomainName}",
                "create",
                $"create{lowerDomainName}",
                $"add{lowerDomainName}",
            }
                   .Contains(lowerOperationName));
        }
        public bool Match(ClassModel domainModel, OperationModel operationModel)
        {
            if (operationModel.Parameters.Any())
            {
                return(false);
            }

            if (!(operationModel?.TypeReference?.IsCollection ?? false))
            {
                return(false);
            }

            var lowerDomainName       = domainModel.Name.ToLower();
            var pluralLowerDomainName = lowerDomainName.Pluralize();
            var lowerOperationName    = operationModel.Name.ToLower();

            return(new[]
            {
                $"get",
                $"get{lowerDomainName}",
                $"get{pluralLowerDomainName}",
                $"get{pluralLowerDomainName}list",
                $"getall",
                $"getall{pluralLowerDomainName}",
                $"find",
                $"find{lowerDomainName}",
                $"find{pluralLowerDomainName}",
                "findall"
            }
                   .Contains(lowerOperationName));
        }
        public string GetImplementation(ClassModel domainModel, OperationModel operationModel)
        {
            var idParam  = operationModel.Parameters.First(p => p.Name.EndsWith("id", StringComparison.OrdinalIgnoreCase));
            var dtoParam = operationModel.Parameters.First(p => !p.Name.EndsWith("id", StringComparison.OrdinalIgnoreCase));

            return($@"var existing{domainModel.Name} ={ (operationModel.IsAsync() ? " await" : "") } {domainModel.Name.ToPrivateMember()}Repository.FindById{ (operationModel.IsAsync() ? "Async" : "") }({idParam.Name});
                {EmitPropertyAssignments(domainModel, "existing"+ domainModel.Name, dtoParam)}");
        }
Example #7
0
        public string GetImplementation(ClassModel domainModel, OperationModel operationModel)
        {
            var entityName = _decorator.Template.GetTypeName(DomainEntityStateTemplate.TemplateId, domainModel, new TemplateDiscoveryOptions()
            {
                ThrowIfNotFound = false
            });
            var impl = $@"var new{domainModel.Name} = new {entityName ?? domainModel.Name}
                {{
{GetPropertyAssignments(domainModel, operationModel.Parameters.First())}
                }};
                
                {domainModel.Name.ToPrivateMember()}Repository.Add(new{domainModel.Name});";

            if (operationModel.TypeReference.Element != null)
            {
                impl += $@"
                await {domainModel.Name.ToPrivateMember()}Repository.SaveChangesAsync();
                return new{domainModel.Name}.Id;";
            }

            return(impl);
        }
 public string GetImplementation(ClassModel domainModel, OperationModel operationModel)
 {
     return($@"var existing{domainModel.Name} ={ (operationModel.IsAsync() ? " await" : "") } {domainModel.Name.ToPrivateMember()}Repository.FindById{ (operationModel.IsAsync() ? "Async" : "") }({operationModel.Parameters.Single().Name.ToCamelCase()});
         {domainModel.Name.ToPrivateMember()}Repository.Remove(existing{domainModel.Name});");
 }
 public string GetImplementation(ClassModel domainModel, OperationModel operationModel)
 {
     return($@"var {domainModel.Name.ToCamelCase()} = {domainModel.Name.ToCamelCase()}Repository.findById({operationModel.Parameters.Single().Name.ToCamelCase()}).get();
 {domainModel.Name.ToCamelCase()}Repository.delete({domainModel.Name.ToCamelCase()});");
 }