private string GenerateRemoveByPrimaryKey(MethodImplementationInfo method)
        {
            var filter = method.FilterInfo;

            var sb = new StringBuilder();

            // Remove by entity (use primary key(s))
            var parameterName = RepositoryInfo.ClassName.FirstSymbolToLower();
            var methodParameter = RepositoryInfo.ClassFullName + " " + parameterName;

            // Synchronous method
            sb.AppendLine("public void RemoveBy" + filter.Key + "(" + methodParameter + ")");
            sb.AppendLine("{");
            sb.AppendLine(parameterName + ".IsDeleted = true;");
            sb.AppendLine("UpdateBy" + filter.Key + "(" + parameterName + ");");
            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async Task RemoveBy" + filter.Key + "Async(" + methodParameter + ")");
            sb.AppendLine("{");
            sb.AppendLine(parameterName + ".IsDeleted = true;");
            sb.AppendLine("await UpdateBy" + filter.Key + "Async(" + parameterName + ");");
            sb.AppendLine("}");

            // Remove by primary key(s)
            var parameterNames = string.Join(",", filter.Parameters.Select(p => p.TypeName + " " + p.Name.FirstSymbolToLower()));
            var parameters = string.Join(",", filter.Parameters.Select(p => p.Name.FirstSymbolToLower()));
            //var parameter2Name = parameter2.Name.FirstSymbolToLower();
            //var methodParameter2 = parameter2.TypeName + " " + parameter2Name;

            // Synchronous method
            sb.AppendLine("public void RemoveBy" + filter.Key + "(" + parameterNames + ")");
            sb.AppendLine("{");
            sb.AppendLine("var result = " + CacheRepositoryField + ".GetBy" + filter.Key + "(" + parameters + ");");
            sb.AppendLine("result.IsDeleted = true;");
            sb.AppendLine("UpdateBy" + filter.Key + "(result);");
            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async Task RemoveBy" + filter.Key + "Async(" + parameterNames + ")");
            sb.AppendLine("{");
            sb.AppendLine("var result = await " + CacheRepositoryField + ".GetBy" + filter.Key + "Async(" + parameters + ");");
            sb.AppendLine("result.IsDeleted = true;");
            sb.AppendLine("await UpdateBy" + filter.Key + "Async(result);");
            sb.AppendLine("}");

            return method.RequiresImplementation ? sb.ToString() : sb.ToString().SurroundWithComments();
        }
        private string GenerateUpdate(MethodImplementationInfo method)
        {
            var filter = method.FilterInfo;
            var parameterName = RepositoryInfo.ClassName.FirstSymbolToLower();
            var methodParameter = RepositoryInfo.ClassFullName + " " + parameterName;

            var sb = new StringBuilder();

            // Synchronous method
            sb.AppendLine("public void UpdateBy" + filter.Key + "(" + methodParameter + ")");
            sb.AppendLine("{");
            sb.AppendLine(parameterName + ".Modified = " + DateTimeServiceField + ".CurrentDateTimeOffset;");
            sb.AppendLine(parameterName + ".ModifiedBy = " + DataAccessControllerField + ".EmployeeId.Value;");
            sb.AppendLine(parameterName + "." + RepositoryInfo.VersionKeyName + " = Guid.NewGuid();");
            sb.AppendLine(VersionRepositoryField + ".Insert(" + parameterName + ");");
            sb.AppendLine(CacheRepositoryField + ".UpdateBy" + filter.Key + "(" + parameterName + ");");

            var updateMethodNames = GetUpdateMethodNames();
            var updateMethods = updateMethodNames.Select(name => name + "(" + parameterName + ");").ToList();

            foreach (var m in updateMethods)
            {
                sb.AppendLine(m);
            }

            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async Task UpdateBy" + filter.Key + "Async(" + methodParameter + ")");
            sb.AppendLine("{");
            sb.AppendLine(parameterName + ".Modified = " + DateTimeServiceField + ".CurrentDateTimeOffset;");
            sb.AppendLine(parameterName + ".ModifiedBy = " + DataAccessControllerField + ".EmployeeId.Value;");
            sb.AppendLine(parameterName + "." + RepositoryInfo.VersionKeyName + " = Guid.NewGuid();");
            sb.AppendLine("await " + VersionRepositoryField + ".InsertAsync(" + parameterName + ");");
            sb.AppendLine("await " + CacheRepositoryField + ".UpdateBy" + filter.Key + "Async(" + parameterName + ");");

            // if async
            // var updateMethodsAsync = RepositoryInfo.Many2ManyInfo.Select(info => "Update" + info.ManyToManyRepositoryInfo.ClassName + "Async(" + parameterName + ");");

            foreach (var m in updateMethods)
            {
                sb.AppendLine(m);
            }

            sb.AppendLine("}");

            return method.RequiresImplementation ? sb.ToString() : sb.ToString().SurroundWithComments();
        }
        private string GenerateInsert(MethodImplementationInfo method)
        {
            var parameterName = RepositoryInfo.ClassName.FirstSymbolToLower();

            var versionKeyProperty = parameterName + "." + RepositoryInfo.VersionKeyName;
            var methodParameter = RepositoryInfo.ClassFullName + " " + parameterName;

            var updateMethodNames = GetUpdateMethodNames();
            var updateMethods = updateMethodNames.Select(name => name + "(" + parameterName + ");").ToList();

            var returnType = "Guid";
            var returnTypeAsync = "Task<" + returnType + ">";
            var returnFunc = "return " + versionKeyProperty + ";";

            var sb = new StringBuilder();

            // synchronous method
            sb.AppendLine("public " + returnType + " Insert(" + methodParameter + ")");
            sb.AppendLine("{");
            sb.AppendLine(parameterName + ".Modified = " + DateTimeServiceField + ".CurrentDateTimeOffset;");
            sb.AppendLine(parameterName + ".ModifiedBy = " + DataAccessControllerField + ".EmployeeId.Value;");
            sb.AppendLine(versionKeyProperty + " = Guid.NewGuid();");

            foreach (var key in RepositoryInfo.PrimaryKeys)
            {
                var primaryKeyProperty = parameterName + "." + key.Name;

                if (key.TypeName.IsInt()) // int skipped on insert
                {
                    sb.AppendLine(primaryKeyProperty + " = 0;");
                }
                else if (key.TypeName.IsGuid()) // throw ArgumentException if primary key if guid and empty,
                {
                    sb.AppendLine("if(" + primaryKeyProperty + " == null || " + primaryKeyProperty + "== Guid.Empty )");
                    sb.AppendLine("{");
                    sb.AppendLine("throw new ArgumentException(" + RepositoryInfo.PrimaryKeyName.SurroundWithQuotes() + ");");
                    sb.AppendLine("}");
                }
            }

            sb.AppendLine(VersionRepositoryField + ".Insert(" + parameterName + ");");
            sb.AppendLine(CacheRepositoryField + ".Insert(" + parameterName + ");");

            foreach (var m in updateMethods)
            {
                sb.AppendLine(m);
            }

            sb.AppendLine(returnFunc);

            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async " + returnTypeAsync + " InsertAsync(" + methodParameter + ")");
            sb.AppendLine("{");
            sb.AppendLine(parameterName + ".Modified = " + DateTimeServiceField + ".CurrentDateTimeOffset;");
            sb.AppendLine(parameterName + ".ModifiedBy = " + DataAccessControllerField + ".EmployeeId.Value;");
            sb.AppendLine(versionKeyProperty + " = Guid.NewGuid();");

            foreach (var key in RepositoryInfo.PrimaryKeys)
            {
                var primaryKeyProperty = parameterName + "." + key.Name;

                if (key.TypeName.IsInt()) // int skipped on insert
                {
                    sb.AppendLine(primaryKeyProperty + " = 0;");
                }
                else if (key.TypeName.IsGuid()) // throw ArgumentException if primary key if guid and empty,
                {
                    sb.AppendLine("if(" + primaryKeyProperty + " == null || " + primaryKeyProperty + "== Guid.Empty )");
                    sb.AppendLine("{");
                    sb.AppendLine("throw new ArgumentException(" + RepositoryInfo.PrimaryKeyName.SurroundWithQuotes() + ");");
                    sb.AppendLine("}");
                }
            }

            sb.AppendLine("await " + VersionRepositoryField + ".InsertAsync(" + parameterName + ");");
            sb.AppendLine("await " + CacheRepositoryField + ".InsertAsync(" + parameterName + ");");

            foreach (var m in updateMethods)
            {
                sb.AppendLine(m);
            }

            sb.AppendLine(returnFunc);

            sb.AppendLine("}");

            return method.RequiresImplementation ? sb.ToString() : sb.ToString().SurroundWithComments();
        }
        private string GenerateRemoveByFilterKey(MethodImplementationInfo method)
        {
            var filter = method.FilterInfo;

            var sb = new StringBuilder();

            // Remove by entity (use filter key)
            var parameterName = RepositoryInfo.ClassName.FirstSymbolToLower();
            var methodParameter = RepositoryInfo.ClassFullName + " " + parameterName;

            // Synchronous method
            sb.AppendLine("public void RemoveBy" + filter.Key + "(" + methodParameter + ")");
            sb.AppendLine("{");
            sb.AppendLine(parameterName + ".IsDeleted = true;");
            sb.AppendLine(CacheRepositoryField + ".UpdateBy" + filter.Key + "(" + parameterName + ");");
            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async Task RemoveBy" + filter.Key + "Async(" + methodParameter + ")");
            sb.AppendLine("{");
            sb.AppendLine(parameterName + ".IsDeleted = true;");
            sb.AppendLine("await " + CacheRepositoryField + ".UpdateBy" + filter.Key + "Async(" + parameterName + ");");
            sb.AppendLine("}");

            // Remove by filter key
            var parameter2 = filter.Parameters.First();
            var parameter2Name = parameter2.Name.FirstSymbolToLower();
            var methodParameter2 = parameter2.TypeName + " " + parameter2Name;

            // Synchronous method
            sb.AppendLine("public void RemoveBy" + filter.Key + "(" + methodParameter2 + ")");
            sb.AppendLine("{");
            sb.AppendLine("var result = " + CacheRepositoryField + ".GetBy" + filter.Key + "(" + parameter2Name + ");");
            sb.AppendLine("foreach (var item in result)");
            sb.AppendLine("{");
            sb.AppendLine("item.IsDeleted = true;");
            sb.AppendLine("UpdateBy" + filter.Key + "(item);");
            sb.AppendLine("}");
            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async Task RemoveBy" + filter.Key + "Async(" + methodParameter2 + ")");
            sb.AppendLine("{");
            sb.AppendLine("var result = await " + CacheRepositoryField + ".GetBy" + filter.Key + "Async(" + parameter2Name + ");");
            sb.AppendLine("foreach (var item in result)");
            sb.AppendLine("{");
            sb.AppendLine("item.IsDeleted = true;");
            sb.AppendLine("await UpdateBy" + filter.Key + "Async(item);");
            sb.AppendLine("}");
            sb.AppendLine("}");

            return method.RequiresImplementation ? sb.ToString() : sb.ToString().SurroundWithComments();
        }
        private string GenerateGetByKey(MethodImplementationInfo method)
        {
            var filter = method.FilterInfo;
            var sb = new StringBuilder();

            var parameters = filter.Parameters.Select(k => k.TypeName + " " + k.Name.FirstSymbolToLower()).ToList();
            var parameterNames = filter.Parameters.Select(k => k.Name.FirstSymbolToLower()).ToList();

            var firstOverloadParameters = filter.Parameters.Select(k => k.TypeName + " " + k.Name.FirstSymbolToLower()).ToList();
            var firstOverloadParameterNames = filter.Parameters.Select(k => k.Name.FirstSymbolToLower()).ToList();

            var filterBySliceDate = filter.FilterType != FilterType.VersionKey && RepositoryInfo.IsModifiedExist;
            var filterByIsDeleted = RepositoryInfo.IsModifiedExist;

            if (filterBySliceDate)
            {
                var specialParameterModified = RepositoryInfo.SpecialOptionsModified.Parameters.First();
                var specialMethodParameterModified = specialParameterModified.TypeName + " " + specialParameterModified.Name.FirstSymbolToLower();
                var specialMethodParameterModifiedName = specialParameterModified.Name.FirstSymbolToLower();

                parameters.Add(specialMethodParameterModified);
                parameterNames.Add(specialMethodParameterModifiedName);
            }

            // last parameter - because have default value
            if (filterByIsDeleted)
            {
                var specialParameterIsDeleted = RepositoryInfo.SpecialOptionsIsDeleted.Parameters.First();
                var specialMethodParameterIsDeleted = specialParameterIsDeleted.TypeName + "? " + specialParameterIsDeleted.Name.FirstSymbolToLower() + " = " + specialParameterIsDeleted.DefaultValue;
                var specialMethodParameterIsDeletedName = specialParameterIsDeleted.Name.FirstSymbolToLower();

                parameters.Add(specialMethodParameterIsDeleted);
                parameterNames.Add(specialMethodParameterIsDeletedName);
                firstOverloadParameters.Add(specialMethodParameterIsDeleted);
                firstOverloadParameterNames.Add(specialMethodParameterIsDeletedName);
            }

            var methodParameters = string.Join(", ", parameters);
            var methodParameterNames = string.Join(", ", parameterNames);

            var firstOverloadMethodParameters = string.Join(", ", firstOverloadParameters);
            var firstOverloadMethodParameterNames = string.Join(", ", firstOverloadParameterNames);

            var returnType = method.ReturnType.IsEnumerable() ? "IEnumerable<" + RepositoryInfo.ClassFullName + ">" : RepositoryInfo.ClassFullName;
            var returnFunc = method.ReturnType.IsEnumerable() ? "return result.ToList();" : "return result;";

            var overloads = new[]
            {
                new {repository = VersionRepositoryField, parameters = methodParameters, parameterNames = methodParameterNames, needImplement = true},
                new {repository = CacheRepositoryField, parameters = firstOverloadMethodParameters, parameterNames = firstOverloadMethodParameterNames, needImplement = filter.FilterType != FilterType.VersionKey}
            };

            var methods = overloads.Where(m => m.needImplement).ToList();

            foreach (var overload in methods)
            {
                // Synchronous method
                sb.AppendLine("public " + returnType + " GetBy" + filter.Key + "(" + overload.parameters + ")");
                sb.AppendLine("{");
                sb.AppendLine("var result = " + overload.repository + ".GetBy" + filter.Key + "(" + overload.parameterNames + ");");
                sb.AppendLine(returnFunc);
                sb.AppendLine("}");
                sb.AppendLine();

                //Asynchronous method
                sb.AppendLine("public async Task<" + returnType + "> GetBy" + filter.Key + "Async(" + overload.parameters + ")");
                sb.AppendLine("{");
                sb.AppendLine("var result = await " + overload.repository + ".GetBy" + filter.Key + "Async(" + overload.parameterNames + ");");
                sb.AppendLine(returnFunc);
                sb.AppendLine("}");
                sb.AppendLine();
            }

            return sb.ToString();
        }
 private string GenerateGetByVersionKey(MethodImplementationInfo method)
 {
     var code = GenerateGetByKey(method);
     return method.RequiresImplementation ? code : code.SurroundWithComments();
 }
        private string GenerateUpdate(MethodImplementationInfo method)
        {
            var filter = method.FilterInfo;

            var sb = new StringBuilder();

            // Update by entity (use filter key)
            var parameterName = RepositoryInfo.ClassName.FirstSymbolToLower();
            var methodParameter = RepositoryInfo.ClassFullName + " " + parameterName;

            var whereQueryName = _whereQueryBy + filter.Key;
            var whereQueryByJoinPk = _whereQueryBy + _join + _pk;

            // Synchronous method
            sb.AppendLine("public void UpdateBy" + filter.Key + "(" + methodParameter + ")");
            sb.AppendLine("{");
            if (RepositoryInfo.JoinRepositoryInfo == null)
            {
                sb.AppendLine("var sql = " + _updateQueryBy + " + " + whereQueryName + "; ");
            }
            else
            {
                sb.AppendLine("var sql = " + _updateQueryBy + " + " + whereQueryName +  " + " + _updateQuery + _join + " + " + whereQueryByJoinPk + "; ");
            }
            sb.AppendLine("DataAccessService.PersistObject(" + parameterName + ", sql);");
            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async Task UpdateBy" + filter.Key + "Async(" + methodParameter + ")");
            sb.AppendLine("{");
            if (RepositoryInfo.JoinRepositoryInfo == null)
            {
                sb.AppendLine("var sql = " + _updateQueryBy + " + " + whereQueryName + "; ");
            }
            else
            {
                sb.AppendLine("var sql = " + _updateQueryBy + " + " + whereQueryName + " + " + _updateQuery + _join + " + " + whereQueryByJoinPk + "; ");
            }
            sb.AppendLine("await DataAccessService.PersistObjectAsync(" + parameterName + ", sql);");
            sb.AppendLine("}");
            sb.AppendLine("");

            return method.RequiresImplementation ? sb.ToString() : sb.ToString().SurroundWithComments();
        }
        private string GenerateGetAll(MethodImplementationInfo method)
        {
            var specialParameterIsDeleted = RepositoryInfo.SpecialOptionsIsDeleted.Parameters.First();
            var specialMethodParameterIsDeleted = specialParameterIsDeleted.TypeName + "? " + specialParameterIsDeleted.Name.FirstSymbolToLower() + " = " + specialParameterIsDeleted.DefaultValue;
            var specialMethodParameterIsDeletedName = specialParameterIsDeleted.Name.FirstSymbolToLower();

            var addIsDeletedFilter = RepositoryInfo.IsVersioning && RepositoryInfo.IsDeletedExist;
            var returnType = "IEnumerable<" + RepositoryInfo.ClassFullName + ">";

            var parameters = addIsDeletedFilter ? specialMethodParameterIsDeleted : "";
            var parameterNames = addIsDeletedFilter ? specialMethodParameterIsDeletedName : "";

            var sb = new StringBuilder();

            // Synchronous method
            sb.AppendLine("public " + returnType + " GetAll(" + parameters + ")");
            sb.AppendLine("{");
            sb.AppendLine("return " + CacheRepositoryField + ".GetAll(" + parameterNames + ");");
            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async Task<" + returnType + "> GetAllAsync(" + parameters + ")");
            sb.AppendLine("{");
            sb.AppendLine("return await " + CacheRepositoryField + ".GetAllAsync(" + parameterNames + ");");
            sb.AppendLine("}");

            return method.RequiresImplementation ? sb.ToString() : sb.ToString().SurroundWithComments();
        }
        private string GenerateRemove(MethodImplementationInfo method)
        {
            var filter = method.FilterInfo;

            var sb = new StringBuilder();

            // Remove by entity (use filter key)
            var parameterName = RepositoryInfo.ClassName.FirstSymbolToLower();
            var methodParameter = RepositoryInfo.ClassFullName + " " + parameterName;

            var whereQueryName = _whereQueryBy + filter.Key;

            // Synchronous method
            sb.AppendLine("public void RemoveBy" + filter.Key + "(" + methodParameter + ")");
            sb.AppendLine("{");
            if (RepositoryInfo.JoinRepositoryInfo == null)
            {
                sb.AppendLine("var sql = " + _deleteQueryBy + " + " + whereQueryName + "; ");
            }
            else
            {
                sb.AppendLine("var sql = " + _selectIntoTemp + " + " + whereQueryName + " + " + _deleteQueryBy + "; ");
            }
            sb.AppendLine("DataAccessService.PersistObject("+ parameterName + ", sql);");
            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async Task RemoveBy" + filter.Key + "Async(" + methodParameter + ")");
            sb.AppendLine("{");
            if (RepositoryInfo.JoinRepositoryInfo == null)
            {
                sb.AppendLine("var sql = " + _deleteQueryBy + " + " + whereQueryName + "; ");
            }
            else
            {
                sb.AppendLine("var sql = " + _selectIntoTemp + " + " + whereQueryName + " + " + _deleteQueryBy + "; ");
            }
            sb.AppendLine("await DataAccessService.PersistObjectAsync(" + parameterName + ", sql);");
            sb.AppendLine("}");
            sb.AppendLine("");

            // Remove by filter key
            var methodParameters = string.Join(", ", filter.Parameters.Select(k => k.TypeName + " " + k.Name.FirstSymbolToLower()));
            var sqlParameters = string.Join(", ", filter.Parameters.Select(k => k.Name.FirstSymbolToLower()));

            // Synchronous method
            sb.AppendLine("public void RemoveBy" + filter.Key + "(" + methodParameters + ")");
            sb.AppendLine("{");
            sb.AppendLine("object parameters = new {" + sqlParameters + "};");
            if (RepositoryInfo.JoinRepositoryInfo == null)
            {
                sb.AppendLine("var sql = " + _deleteQueryBy + " + " + whereQueryName + "; ");
            }
            else
            {
                sb.AppendLine("var sql = " + _selectIntoTemp + " + " + whereQueryName + " + " + _deleteQueryBy + "; ");
            }
            sb.AppendLine("DataAccessService.PersistObject<" + RepositoryInfo.ClassFullName + ">(sql, parameters);");
            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async Task RemoveBy" + filter.Key + "Async(" + methodParameters + ")");
            sb.AppendLine("{");
            sb.AppendLine("object parameters = new {" + sqlParameters + "};");
            if (RepositoryInfo.JoinRepositoryInfo == null)
            {
                sb.AppendLine("var sql = " + _deleteQueryBy + " + " + whereQueryName + "; ");
            }
            else
            {
                sb.AppendLine("var sql = " + _selectIntoTemp + " + " + whereQueryName + " + " + _deleteQueryBy + "; ");
            }
            sb.AppendLine("await DataAccessService.PersistObjectAsync<" + RepositoryInfo.ClassFullName + ">(sql, parameters);");
            sb.AppendLine("}");
            sb.AppendLine("");

            return method.RequiresImplementation ? sb.ToString() : sb.ToString().SurroundWithComments();
        }
        private string GenerateInsert(MethodImplementationInfo method)
        {
            var sb = new StringBuilder();

            var parameterName = RepositoryInfo.ClassName.FirstSymbolToLower();
            var methodParameter = RepositoryInfo.ClassFullName + " " + parameterName;

            var queryName = _insertQuery;

            // If should not return identifier
            if (RepositoryInfo.PrimaryKeys.Count != 1)
            {
                // Synchronous method
                sb.AppendLine("public void Insert(" + methodParameter + ")");
                sb.AppendLine("{");
                sb.AppendLine("DataAccessService.InsertObject(" + parameterName + "," + queryName + ");");
                sb.AppendLine("}");

                // Asynchronous method
                sb.AppendLine("public async Task InsertAsync(" + methodParameter + ")");
                sb.AppendLine("{");
                sb.AppendLine("await DataAccessService.InsertObjectAsync(" + parameterName + "," + queryName + ");");
                sb.AppendLine("}");
            }
            else
            {
                var returnType = RepositoryInfo.PrimaryKeys.First().TypeName;

                // Synchronous method
                sb.AppendLine("public " + returnType + " Insert(" + methodParameter + ")");
                sb.AppendLine("{");
                sb.AppendLine("var res = DataAccessService.InsertObject(" + parameterName + "," + queryName + ");");
                sb.AppendLine("return (" + returnType + ")res;");
                sb.AppendLine("}");

                // Asynchronous method
                sb.AppendLine("public async Task<" + returnType + "> InsertAsync(" + methodParameter + ")");
                sb.AppendLine("{");
                sb.AppendLine("var res = await DataAccessService.InsertObjectAsync(" + parameterName + "," + queryName + ");");
                sb.AppendLine("return (" + returnType + ")res;");
                sb.AppendLine("}");
            }

            return method.RequiresImplementation ? sb.ToString() : sb.ToString().SurroundWithComments();
        }
        private string GenerateGetByKey(MethodImplementationInfo method)
        {
            var returnType = method.ReturnType.IsEnumerable() ? "IEnumerable<" + RepositoryInfo.ClassFullName + ">" : RepositoryInfo.ClassFullName;
            var returnFunc = method.ReturnType.IsEnumerable() ? "return result.ToList();" : "return result.FirstOrDefault();";
            var filter = method.FilterInfo;
            var filterByIsDeleted = RepositoryInfo.IsDeletedExist;
            var sqlWhere = _whereQueryBy + filter.Key;
            var selectQuery = _selectByQuery;

            var parameters = filter.Parameters.Select(k => k.TypeName + " " + k.Name.FirstSymbolToLower()).ToList();
            var parameterNames = filter.Parameters.Select(k => k.Name.FirstSymbolToLower()).ToList();

            // last parameter - because have default value
            if (filterByIsDeleted)
            {
                var specialParameterIsDeleted = RepositoryInfo.SpecialOptionsIsDeleted.Parameters.First();
                var specialMethodParameterIsDeleted = specialParameterIsDeleted.TypeName + "? " + specialParameterIsDeleted.Name.FirstSymbolToLower() + " = " + specialParameterIsDeleted.DefaultValue;
                var specialMethodParameterIsDeletedName = specialParameterIsDeleted.Name.FirstSymbolToLower();

                parameters.Add(specialMethodParameterIsDeleted);
                parameterNames.Add(specialMethodParameterIsDeletedName);
            }

            var methodParameters = string.Join(", ", parameters);
            var methodParameterNames = string.Join(", ", parameterNames);

            var sb = new StringBuilder();

            // Synchronous method
            sb.AppendLine("public " + returnType + " GetBy" + filter.Key + "(" + methodParameters + ")");
            sb.AppendLine("{");

            sb.AppendLine("object parameters = new {" + methodParameterNames + "};");
            sb.AppendLine("var sql = " + selectQuery + " + " + sqlWhere + ";");
            if (filterByIsDeleted)
            {
                var parameter = RepositoryInfo.SpecialOptionsIsDeleted.Parameters.First().Name.FirstSymbolToLower();
                sb.AppendLine("if (" + parameter + ".HasValue)");
                sb.AppendLine("{");
                sb.AppendLine("sql = sql + " + _andWithIsDeletedFilter + ";");
                sb.AppendLine("}");
            }
            sb.AppendLine("var result = DataAccessService.Get<" + RepositoryInfo.ClassFullName + ">(sql, parameters);");
            sb.AppendLine(returnFunc);
            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async Task<" + returnType + "> GetBy" + filter.Key + "Async" + "(" + methodParameters + ")");
            sb.AppendLine("{");

            sb.AppendLine("object parameters = new {" + methodParameterNames + "};");
            sb.AppendLine("var sql = " + selectQuery + " + " + sqlWhere + ";");
            if (filterByIsDeleted)
            {
                var parameter = RepositoryInfo.SpecialOptionsIsDeleted.Parameters.First().Name.FirstSymbolToLower();
                sb.AppendLine("if (" + parameter + ".HasValue)");
                sb.AppendLine("{");
                sb.AppendLine("sql = sql + " + _andWithIsDeletedFilter + ";");
                sb.AppendLine("}");
            }
            sb.AppendLine("var result = (await DataAccessService.GetAsync<" + RepositoryInfo.ClassFullName + ">(sql, parameters));");
            sb.AppendLine(returnFunc);
            sb.AppendLine("}");
            sb.AppendLine("");

            return sb.ToString();
        }
        private string GenerateGetAll(MethodImplementationInfo method)
        {
            var specialParameterIsDeleted = RepositoryInfo.SpecialOptionsIsDeleted.Parameters.First();
            var specialMethodParameterIsDeleted = specialParameterIsDeleted.TypeName + "? " + specialParameterIsDeleted.Name.FirstSymbolToLower() + " = " + specialParameterIsDeleted.DefaultValue;
            var specialMethodParameterIsDeletedName = specialParameterIsDeleted.Name.FirstSymbolToLower();

            var addIsDeletedFilter = RepositoryInfo.IsDeletedExist;
            var returnType = "IEnumerable<" + RepositoryInfo.ClassFullName + ">";

            var parameters = addIsDeletedFilter ? specialMethodParameterIsDeleted : "";
            var parameterNames = addIsDeletedFilter ? specialMethodParameterIsDeletedName : "";

            var sb = new StringBuilder();

            // Synchronous method
            sb.AppendLine("public " + returnType + " GetAll(" + parameters + ")");
            sb.AppendLine("{");
            sb.AppendLine("var sql = " + _selectAllQuery + ";");

            if (addIsDeletedFilter)
            {
                var parameter = RepositoryInfo.SpecialOptionsIsDeleted.Parameters.First().Name.FirstSymbolToLower();
                sb.AppendLine("object parameters = new {" + parameterNames + "};");
                sb.AppendLine("if (" + parameter + ".HasValue)");
                sb.AppendLine("{");
                sb.AppendLine("sql = sql + " + _andWithIsDeletedFilter + ";");
                sb.AppendLine("}");
            }
            else
            {
                sb.AppendLine("object parameters = null;");
            }

            sb.AppendLine("var result = DataAccessService.Get<" + RepositoryInfo.ClassFullName + ">(sql, parameters).ToList();");
            sb.AppendLine("return result.ToList();");
            sb.AppendLine("}");

            // Asynchronous method
            sb.AppendLine("public async Task<" + returnType + "> GetAllAsync(" + parameters + ")");
            sb.AppendLine("{");
            sb.AppendLine("var sql = " + _selectAllQuery + ";");

            if(addIsDeletedFilter)
            {
                var parameter = RepositoryInfo.SpecialOptionsIsDeleted.Parameters.First().Name.FirstSymbolToLower();
                sb.AppendLine("object parameters = new {" + parameterNames + "};");
                sb.AppendLine("if (" + parameter + ".HasValue)");
                sb.AppendLine("{");
                sb.AppendLine("sql = sql + " + _andWithIsDeletedFilter + ";");
                sb.AppendLine("}");
            }
            else
            {
                sb.AppendLine("object parameters = null;");
            }

            sb.AppendLine("var result = (await DataAccessService.GetAsync<" + RepositoryInfo.ClassFullName + ">(sql, parameters));");
            sb.AppendLine("return result.ToList();");
            sb.AppendLine("}");

            return method.RequiresImplementation ? sb.ToString() : sb.ToString().SurroundWithComments();
        }
 private static bool NameIsTrue(MethodImplementationInfo methodInfo, string name)
 {
     return methodInfo.Method.GetName() + (methodInfo.FilterInfo != null ? methodInfo.FilterInfo.Key ?? "" : "") == name || methodInfo.Method.GetName() + (methodInfo.FilterInfo != null ? methodInfo.FilterInfo.Key ?? "" : "") + "Async" == name;
 }