Ejemplo n.º 1
0
        public void GetAll(MyMeta.ITable table)
        {
            string tableName = table.Name;

            _output.tabLevel++;
            _output.tabLevel++;
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// GetAll and map the fields to the entity");
            _output.autoTabLn("/// and add to generic queryable collection.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <returns></returns>");

            _output.autoTabLn("public List<" + _util.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(tableName)) + "> GetAll()");
            _output.autoTabLn("{");

            _output.tabLevel++;

            _output.autoTabLn("using (var context = DataContextFactory.CreateContext())");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("return context." + StringFormatter.CleanUpClassName(StringFormatter.MakePlural(tableName)) + ".Select(o => " + StringFormatter.CleanUpClassName(tableName) + "Mapper.ToBusinessObject(o)).ToList();");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.tabLevel--;
        }
Ejemplo n.º 2
0
        public void Interface(MyMeta.ITable table)
        {
            string   tableName = table.Name;
            string   args      = "";
            GenTable genTable  = new GenTable(table, _context);
            string   str       = "";

            str += _util.BuildModelClassWithNameSpace(tableName) + " GetById(";

            for (int i = 0; i < genTable.GetPrimaryKeyNames.Length; i++)
            {
                // type + " " + key name
                args += genTable.GetPrimaryKeyTypes[i] + " ";
                args += StringFormatter.CamelCasing(genTable.GetPrimaryKeyNames[i]) + ", ";
            }
            // trim the trailing ", "

            args = args.Substring(0, (args.Length - 2));

            str += args;
            str += ");";
            _output.tabLevel++;
            _output.tabLevel++;
            _output.autoTabLn(str);
            _output.tabLevel--;
            _output.tabLevel--;

            str  = "";
            str += "List<" + _util.BuildModelClassWithNameSpace(tableName) + "> GetAll(string sortExpression, int startRowIndex, int maximumRows);";
            _output.tabLevel++;
            _output.tabLevel++;
            _output.autoTabLn(str);
            _output.tabLevel--;
            _output.tabLevel--;
        }
Ejemplo n.º 3
0
        public void GetAllWithSortingAndPaging(MyMeta.ITable table)
        {
            string tableName = table.Name;
            string model     = _script.Settings.BusinessObjects.BusinessObjectsNamespace + "." + StringFormatter.CleanUpClassName(tableName);
            string entity    = _script.Settings.DataOptions.DataObjectsNamespace + "." + _script.Settings.DataOptions.ORMFramework.Selected + "." + StringFormatter.CleanUpClassName(tableName);

            _output.tabLevel++;
            _output.tabLevel++;

            _output.autoTabLn("public List<" + model + "> GetAll(string sortExpression, int startRowIndex, int maximumRows)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("using (var context = DataContextFactory.CreateContext())");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("IQueryable<" + entity + "> query = context." + StringFormatter.CleanUpClassName(StringFormatter.MakePlural(tableName)) + ";");
            _output.autoTabLn("query = GetListSort(query, sortExpression);");
            _output.autoTabLn("query = query.Skip(startRowIndex).Take(maximumRows);");
            _output.autoTabLn("return query.Select(o => " + StringFormatter.CleanUpClassName(tableName) + "Mapper.ToBusinessObject(o)).ToList();");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.tabLevel--;
        }
Ejemplo n.º 4
0
        public void GetById(MyMeta.ITable table)
        {
            string args      = string.Empty;
            string keys      = string.Empty;
            string tableName = table.Name;

            GenTable genTable = new GenTable(table, _context);

            _output.tabLevel++;
            _output.tabLevel++;
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// GetById and map the fields to the Model.");
            _output.autoTabLn("/// </summary>");
            for (int i = 0; i < genTable.GetPrimaryKeyNames.Length; i++)
            {
                _output.autoTabLn("/// <param name=\"" + StringFormatter.CamelCasing(genTable.GetPrimaryKeyNames[i]) + "\"></param>");
            }

            _output.autoTabLn("/// <returns></returns>");
            _output.autoTab("public " + _util.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(tableName)) + " GetById(");
            for (int i = 0; i < genTable.GetPrimaryKeyNames.Length; i++)
            {
                // type + " " + key name
                args += genTable.GetPrimaryKeyTypes[i] + " ";
                args += StringFormatter.CamelCasing(genTable.GetPrimaryKeyNames[i]) + ", ";
                keys += StringFormatter.CamelCasing(genTable.GetPrimaryKeyNames[i]) + ", ";
            }
            // trim the trailing ", "
            args = args.Substring(0, (args.Length - 2));
            keys = keys.Substring(0, (keys.Length - 2));
            _output.write(args);
            _output.writeln(")");
            _output.autoTabLn("{");

            _output.tabLevel++;
            _output.autoTabLn("using (var context = DataContextFactory.CreateContext())");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("return " + StringFormatter.CleanUpClassName(tableName) + "Mapper.ToBusinessObject(context." + StringFormatter.MakePlural(StringFormatter.CleanUpClassName(tableName)));
            string[] keysSplit = keys.Split(',');
            foreach (string key in keysSplit)
            {
                _output.tabLevel++;
                _output.autoTabLn(".Where(o => o." + _util.CleanUpProperty(key) + " == " + key + ")");
            }
            _output.autoTabLn(".SingleOrDefault());");
            _output.tabLevel--;
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.tabLevel--;
        }
Ejemplo n.º 5
0
 public void Update(MyMeta.ITable table)
 {
 }
Ejemplo n.º 6
0
 public void GetAll(MyMeta.ITable table)
 {
 }
Ejemplo n.º 7
0
 public void Insert(MyMeta.ITable table)
 {
 }
Ejemplo n.º 8
0
    public bool IsContainColumn(ITable table, string columnName)
    {
        if (string.IsNullOrEmpty(columnName) || table == null)
        {
            return false;
        }

        columnName = columnName.ToLower();
        foreach (IColumn column in table.Columns)
        {
            if (column.Name.ToLower().Equals(columnName))
            {
                return true;
            }
        }
        return false;
    }
Ejemplo n.º 9
0
    public string GetPrimaryColumnName(ITable table)
    {
        if (table == null)
        {
            return string.Empty;
        }

        string primryColName = "";
        foreach (IColumn column in table.Columns)
        {
            if (column.IsInPrimaryKey)
            {
                if(column.Name.ToLower().Equals("id"))
                {
                    return column.Name;
                }

                if(String.IsNullOrEmpty(primryColName))
                {
                    primryColName = column.Name;
                }
            }
        }
        return primryColName;
    }
Ejemplo n.º 10
0
 public void GetAllWithSortingAndPaging(MyMeta.ITable table)
 {
 }
Ejemplo n.º 11
0
 public void BuildModelClass(MyMeta.ITable table, bool useWebService)
 {
 }
Ejemplo n.º 12
0
    public IList<string> GetFieldsDisplayAtListView(ITable table)
    {
        IList<string> returnList = new List<string>();
        foreach (IColumn col in table.Columns)
        {
            string colName = col.Name.ToLower();
            if (FieldsDisplayAtListView.Contains(colName)
                || colName.Contains("title")
                || colName.Contains("name")
                )
            {
                returnList.Add(colName);
            }
        }

        if (returnList.Contains("id"))
        {
            returnList.Remove("id");
            returnList.Insert(0, "id");
        }

        if (returnList.Contains("hits"))
        {
            returnList.Remove("hits");
            returnList.Insert(0, "hits");
        }

        if (returnList.Contains("created"))
        {
            returnList.Remove("created");
            returnList.Insert(0, "created");
        }

        if (returnList.Contains("created_by"))
        {
            returnList.Remove("created_by");
            returnList.Insert(0, "created_by");
        }

        if (returnList.Contains("language"))
        {
            returnList.Remove("language");
            returnList.Insert(0, "language");
        }

        if (returnList.Contains("access"))
        {
            returnList.Remove("access");
            returnList.Insert(0, "access");
        }

        if (returnList.Contains("alias"))
        {
            returnList.Remove("alias");
            returnList.Insert(0, "alias");
        }

        if (returnList.Contains("name"))
        {
            returnList.Remove("name");
            returnList.Insert(0, "name");
        }

        if (returnList.Contains("title"))
        {
            returnList.Remove("title");
            returnList.Insert(0, "title");
        }

        if (returnList.Contains("state"))
        {
            returnList.Remove("state");
            returnList.Insert(0, "state");
        }

        if (returnList.Contains("ordering"))
        {
            returnList.Remove("ordering");
            returnList.Insert(0, "ordering");
        }

        return returnList;
    }
Ejemplo n.º 13
0
    public IList<string> GetFieldsDisplayAtModalListView(ITable table)
    {
        IList<string> returnList = new List<string>();
        foreach (IColumn col in table.Columns)
        {
            string colName = col.Name.ToLower();
            if (FieldsDisplayAtModalListView.Contains(colName))
            {
                returnList.Add(colName);
            }
        }

        if (returnList.Contains("alias"))
        {
            returnList.Remove("alias");
            returnList.Insert(0, "alias");
        }

        if (returnList.Contains("name"))
        {
            returnList.Remove("name");
            returnList.Insert(0, "name");
        }

        if (returnList.Contains("title"))
        {
            returnList.Remove("title");
            returnList.Insert(0, "title");
        }

        return returnList;
    }
Ejemplo n.º 14
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="table"></param>
    /// <returns>return value like: '(a.title LIKE '.$search.' OR a.alias LIKE '.$search.')'</returns>
    public string BuilQuerySearch(ITable table)
    {
        List<string> searchFields = new List<string>();
        foreach (IColumn col in table.Columns)
        {
            if (ColumnDataTypeIsText(col) || ColumnDataTypeIsMediumText(col) || ColumnDataTypeIsVarchar(col))
            {
                string colName = col.Name.ToLower();
                foreach (string str in SearchField)
                {
                    if (colName.Contains(str))
                    {
                        searchFields.Add(colName);
                        break;
                    }
                }
            }
        }

        if (searchFields.Count == 0)
        {
            return string.Empty;
        }

        string returnValue = string.Empty;
        foreach (string sarchField in searchFields)
        {
            returnValue += string.Format(" OR a.{0} LIKE '.$search.' ", sarchField);
        }

        returnValue = returnValue.Substring(3);
        returnValue = "'(" + returnValue + ")'";
        return returnValue;
    }
Ejemplo n.º 15
0
    public IColumn GetColumnByColumnName(ITable table, string name)
    {
        if (string.IsNullOrEmpty(name))
        {
            return null;
        }

        if (table == null)
        {
            return null;
        }

        foreach (IColumn cl in table.Columns)
        {
            if (cl.Name.ToLower().Equals(name.ToLower()))
            {
                return cl;
            }
        }

        return null;
    }
Ejemplo n.º 16
0
    public bool IsContainVarcharColumn(ITable table)
    {
        foreach (IColumn col in table.Columns)
        {
            if(ColumnDataTypeIsVarchar(col))
            {
                return true;
            }
        }

        return false;
    }
Ejemplo n.º 17
0
    public bool IsContainPublishOptionField(ITable table)
    {
        foreach (IColumn col in table.Columns)
        {
            if(PublishOptionFields.Contains(col.Name.ToLower()))
            {
                return true;
            }
        }

        return false;
    }
Ejemplo n.º 18
0
    public bool IsContainImageColumn(ITable table)
    {
        if (table == null)
        {
            return false;
        }

        string columnName = "image";
        foreach (IColumn column in table.Columns)
        {
            if (column.Name.ToLower().Contains(columnName)
                || column.Name.ToLower().Contains("url")
                || column.Name.ToLower().Contains("path")
                || column.Name.ToLower().Contains("file")
                || column.Name.ToLower().Contains("picture")
            )
            {
                return true;
            }
        }
        return false;
    }
Ejemplo n.º 19
0
 public void Delete(MyMeta.ITable table)
 {
 }
Ejemplo n.º 20
0
    public string GetTitleFieldName(ITable table)
    {
        foreach(string title in DefaultTitleFields)
        {
            if(IsContainColumn(table,title))
            {
                return title;
            }
        }

        return GetFirstColumn(table).Name;
    }
Ejemplo n.º 21
0
 public void GetById(MyMeta.ITable table)
 {
 }
Ejemplo n.º 22
0
 public void Mapper(MyMeta.ITable table)
 {
 }
Ejemplo n.º 23
0
 public string GetTableNameWithMeaning(ITable table)
 {
     string tableName = GetTableName(table);
     return Regex.Replace(tableName, "[_-]+", " ");
 }
Ejemplo n.º 24
0
 public string GetTableNameForMultipleLanguage(ITable table)
 {
     string tableName = GetTableName(table);
     return Regex.Replace(tableName, "[_-]+", "_");
 }
Ejemplo n.º 25
0
    public IColumn GetFirstColumn(ITable table)
    {
        if (table == null)
        {
            return null;
        }

        string defualtFirst = "title";

        foreach (IColumn column in table.Columns)
        {
            if (column.Name.ToLower().Equals(defualtFirst))
            {
                return column;
            }
        }

        defualtFirst = "id";

        foreach (IColumn column in table.Columns)
        {
            if (column.Name.ToLower().Equals(defualtFirst))
            {
                return column;
            }
        }

        return table.Columns[0];
    }
Ejemplo n.º 26
0
 public string GetViewNameFromTable(ITable obj)
 {
     return obj.Name.Replace(PrefixTable, "");
 }
Ejemplo n.º 27
0
    public string GetGroupColumnNameFromTable(ITable table)
    {
        if (table == null)
        {
            return string.Empty;
        }

        foreach (string groupName in GroupColumnList)
        {
            foreach (IColumn col in table.Columns)
            {
                if (col.Name.ToLower().Equals(groupName.ToLower()))
                {
                    return groupName;
                }
            }
        }

        foreach (IColumn col in table.Columns)
        {
            string returnColumnName = col.Name.ToLower();
            if (returnColumnName.EndsWith("id"))
            {
                return returnColumnName;
            }
        }

        return string.Empty;
    }
Ejemplo n.º 28
0
    public IList<IColumn> GetListColumnOrder(ITable table)
    {
        //Status	 Title		 Access	 Association	 Author	 Language	 Date	 Hits	 ID
        IList<IColumn> list = new List<IColumn>();
        if(table == null)
        {
            return list;
        }

        foreach(IColumn cl in table.Columns)
        {
            if(cl.Name.ToLower().Equals("title")
                || cl.Name.ToLower().Equals("name")
                   || cl.Name.ToLower().Equals("alias")
                   || cl.Name.ToLower().Equals("id")
                )
            {
                continue;
            }
            else
            {
                list.Add(cl);
            }
        }

        if (IsContainColumn(table, "id"))
        {
            IColumn aliasCl = GetColumnByColumnName(table, "id");
            if (aliasCl != null)
            {
                list.Insert(0, aliasCl);
            }
        }

        if (IsContainColumn(table, "alias"))
        {
            IColumn aliasCl = GetColumnByColumnName(table, "alias");
            if (aliasCl != null)
            {
                list.Insert(0, aliasCl);
            }
        }

        if (IsContainColumn(table, "name"))
        {
            IColumn aliasCl = GetColumnByColumnName(table, "name");
            if (aliasCl != null)
            {
                list.Insert(0, aliasCl);
            }
        }

        if (IsContainColumn(table, "title"))
        {
            IColumn aliasCl = GetColumnByColumnName(table, "title");
            if (aliasCl != null)
            {
                list.Insert(0, aliasCl);
            }
        }

        return list;
    }
Ejemplo n.º 29
0
        public void Insert(MyMeta.ITable table)
        {
            string tableName = table.Name;

            _output.tabLevel++;
            _output.tabLevel++;
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Insert new " + StringFormatter.CleanUpClassName(tableName) + ".");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <param name=\"" + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(tableName)) + "\"></param>");
            _output.autoTabLn("/// <returns></returns>");
            _output.autoTabLn("public void Insert(" + _util.BuildModelClassWithNameSpace(StringFormatter.CleanUpClassName(tableName)) + " model)");
            _output.autoTabLn("{");

            _output.tabLevel++;
            _output.autoTabLn("var entity = " + StringFormatter.CleanUpClassName(tableName) + "Mapper.ToEntity(model);");
            _output.autoTabLn("");
            _output.autoTabLn("using (var context = DataContextFactory.CreateContext())");
            _output.autoTabLn("{");

            _output.tabLevel++;
            _output.autoTabLn("try");
            _output.autoTabLn("{");

            _output.tabLevel++;
            _output.autoTabLn("context." + StringFormatter.CleanUpClassName(StringFormatter.MakePlural(tableName)) + ".InsertOnSubmit(entity);");
            _output.autoTabLn("context.SubmitChanges();");

            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("catch (ChangeConflictException)");
            _output.autoTabLn("{");

            _output.tabLevel++;
            _output.autoTabLn("foreach (ObjectChangeConflict conflict in context.ChangeConflicts)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("conflict.Resolve(RefreshMode.KeepCurrentValues);");

            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("try");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("context.SubmitChanges();");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("catch (ChangeConflictException)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("throw new Exception(\"A concurrency error occurred!\");");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("catch (Exception)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("throw new Exception(\"There was an error inserting the record!\");");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");

            _output.tabLevel--;
            _output.tabLevel--;
        }
Ejemplo n.º 30
0
 public string GetTableName(ITable table)
 {
     string tableName = table.Name.Replace(PrefixTable, "");
     return tableName;
 }