Exemplo n.º 1
0
        public override void Add(SysUserGroup item)
        {
            foreach (SysUserGroup g in this)
            {
                if (item.id == g.id)
                {
                    throw new Exception(O2.Languages.Errors.SYSUSERGROUP_ALREADY_EXISTS.Replace("{G}", item.group));
                }
            }

            if (sysuser_id > 0)
            {
                SysUserSysUserGroup obj = new SysUserSysUserGroup();

                if (query != null)
                {
                    obj.query = query;
                }

                obj.sysuser_id       = sysuser_id;
                obj.sysuser_group_id = item.id;

                obj.Insert();
            }

            innerList.Add(item);
        }
Exemplo n.º 2
0
        public override void InsertAll()
        {
            SysUserSysUserGroup sysusers_sysusers_group = new SysUserSysUserGroup();

            string sysuser_group_ids = String.Empty;

            foreach (SysUserGroup g in this)
            {
                sysuser_group_ids += "," + g.id;
            }

            StringBuilder sql = new StringBuilder();

            sql.Append("DELETE FROM " + sysusers_sysusers_group.get_table());
            sql.Append(" WHERE sysuser_id = @sysuser_id");

            if (!String.IsNullOrEmpty(sysuser_group_ids))
            {
                sql.Append(" AND sysuser_group_id NOT IN (" + sysuser_group_ids.Substring(1) + ")");
            }

            query.AddParameter("@sysuser_id", sysuser_id);
            query.ExecuteNonQuery(sql.ToString());

            query.AddParameter("@sysuser_id", sysuser_id);
            DataTable dt = query.get_DataTable("SELECT * FROM " + sysusers_sysusers_group.get_table() + " WHERE sysuser_id = @sysuser_id");

            foreach (SysUserGroup g in this)
            {
                bool exists_in_db = false;
                foreach (DataRow row in dt.Rows)
                {
                    if (g.id == Convert.ToInt32(row["sysuser_group_id"]))
                    {
                        exists_in_db = true;
                        break;
                    }
                }

                if (!exists_in_db)
                {
                    SysUserSysUserGroup obj = new SysUserSysUserGroup();

                    if (query != null)
                    {
                        obj.query = query;
                    }

                    obj.sysuser_id       = sysuser_id;
                    obj.sysuser_group_id = g.id;

                    obj.Insert();
                }
            }
        }
Exemplo n.º 3
0
        public override void Insert(int index, SysUserGroup item)
        {
            if (sysuser_id > 0)
            {
                SysUserSysUserGroup obj = new SysUserSysUserGroup();

                if (query != null)
                {
                    obj.query = query;
                }

                obj.sysuser_id       = sysuser_id;
                obj.sysuser_group_id = item.id;

                obj.Insert();
            }

            innerList.Insert(index, item);
        }