/// <summary> /// Count the number of roles ID defined. If the count is zero, it indicates /// the WebPortalUser does not belong to the roles which are required to access /// the zone. /// </summary> /// <param name="z"></param> /// <param name="roleArray"></param> /// <returns></returns> public int fetchRoleMatchingCountForWrite(CmsPageSecurityZone z, WebPortalUserRole[] roleArray) { StringBuilder sql = new StringBuilder("SELECT Count(WriteAccess) AS MatchingCount FROM "); sql.Append(TABLE_NAME); sql.Append(" WHERE ZoneId=" + z.ZoneId.ToString()); sql.Append(" AND WriteAccess=1"); sql.Append(" AND UserRoleId in ("); foreach (WebPortalUserRole r in roleArray) { sql.Append(r.RoleID + ","); } sql.Remove(sql.Length - 1, 1); sql.Append(");"); DataSet ds = this.RunSelectQuery(sql.ToString()); if (this.hasSingleRow(ds) == false) { return(0); } DataRow dr = ds.Tables[0].Rows[0]; return(Convert.ToInt32(dr["MatchingCount"])); }
}//constructor public CmsPageSecurityZoneUserRole(int newZoneId, int newUserRoleId) { IRepository <CmsPageSecurityZone> repository = new Repository <CmsPageSecurityZone>(); this.zone = repository.Get(newZoneId); UserRoleId = newUserRoleId; }//constructor
/// <summary> /// Select all the aurhority definitions by providing a zone (zone ID) /// </summary> /// <param name="z"></param> /// <returns></returns> public List <CmsPageSecurityZoneUserRole> fetchAllByZone(CmsPageSecurityZone z) { //PageSecurityZoneUserRoleRepository repository = new PageSecurityZoneUserRoleRepository(); List <CmsPageSecurityZoneUserRole> list = repository.fetchAllByZone(z); return(list); }
/// <summary> /// Recursive is T: see what CmsZone a page is. /// Recursive is F: select the exact zone record given a cms page (i.e. boundary page). /// </summary> /// <param name="page"></param> /// <param name="recursive"></param> /// <returns></returns> public CmsPageSecurityZone fetchByPage(CmsPage page, bool recursive) { if (recursive) { return(fetchByPage(page)); } StringBuilder sql = new StringBuilder("SELECT p.ParentPageId, p.PageId, z.ZoneId, z.StartingPageId, z.ZoneName FROM pages p LEFT JOIN "); sql.Append("(SELECT * FROM " + TABLE_NAME + " WHERE Deleted IS NULL) z on p.PageId=z.StartingPageId"); sql.Append(" WHERE p.PageId={0};"); int id = page.ID; CmsPageSecurityZone z = null; string formattedSQL = String.Format(sql.ToString(), new string[] { id.ToString() }); DataSet ds = this.RunSelectQuery(formattedSQL); DataRow dr = ds.Tables[0].Rows[0]; try { z = fromDataRow(dr); } catch { } return(z); }
}//constructor public CmsPageSecurityZoneUserRole(int newZoneId, int newUserRoleId, bool newReadAccess, bool newWriteAccess) { IRepository <CmsPageSecurityZone> repository = new Repository <CmsPageSecurityZone>(); this.zone = repository.Get(newZoneId); UserRoleId = newUserRoleId; ReadAccess = newReadAccess; WriteAccess = newWriteAccess; }//constructor
/// <summary> /// Put raw datarow values to entity object /// </summary> /// <param name="dr"></param> /// <returns></returns> protected CmsPageSecurityZone fromDataRow(DataRow dr) { CmsPageSecurityZone entity = new CmsPageSecurityZone(); entity.ZoneId = Convert.ToInt32(dr["ZoneId"]); entity.StartingPageId = Convert.ToInt32(dr["StartingPageId"]); entity.ZoneName = dr["ZoneName"].ToString(); return(entity); }
/// <summary> /// Delete from `Zone` /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool delete(CmsPageSecurityZone entity) { StringBuilder sql = new StringBuilder("UPDATE "); sql.Append(TABLE_NAME); sql.Append(" SET Deleted=Now()"); sql.Append(" WHERE ZoneId=" + entity.ZoneId.ToString() + ";"); int affected = this.RunUpdateQuery(sql.ToString()); return(affected > 0); }
/// <summary> /// Update `Zone` /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool update(CmsPageSecurityZone entity) { PageSecurityZoneRepository repository = new PageSecurityZoneRepository(); if (repository.SaveOrUpdate(entity).Id > 0) { return(true); } else { return(false); } }
/// <summary> /// Update `Zone` /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool update(CmsPageSecurityZone entity) { StringBuilder sql = new StringBuilder("UPDATE "); sql.Append(TABLE_NAME); sql.Append(" SET StartingPageId=" + entity.StartingPageId.ToString() + ","); sql.Append(" ZoneName='" + dbEncode(entity.ZoneName) + "'"); sql.Append(" WHERE ZoneId=" + entity.ZoneId.ToString() + ";"); int affected = this.RunUpdateQuery(sql.ToString()); return(affected > 0); }
/// <summary> /// Delete records according to zone id /// </summary> /// <param name="z"></param> /// <returns></returns> public bool deleteByZone(CmsPageSecurityZone z) { StringBuilder sql = new StringBuilder("DELETE FROM "); sql.Append(TABLE_NAME); sql.Append(" WHERE ZoneId=" + z.ZoneId.ToString() + ";"); int affected = this.RunUpdateQuery(sql.ToString()); if (affected > 0) { return(true); } else { return(false); } }
/// <summary> /// Find out the zone where the current page is located. If the current page is /// not defined in ZoneManagement, search the parent page. Repeat until a record /// is defined in ZoneManagement. /// </summary> /// <param name="page"></param> /// <returns></returns> public CmsPageSecurityZone fetchByPage(CmsPage page) { StringBuilder sql = new StringBuilder("SELECT p.ParentPageId, p.PageId, z.ZoneId, z.StartingPageId, z.ZoneName FROM pages p LEFT JOIN "); sql.Append("(SELECT * FROM " + TABLE_NAME + " WHERE Deleted IS NULL) z on p.PageId=z.StartingPageId"); sql.Append(" WHERE p.PageId={0};"); int id = page.ID; CmsPageSecurityZone z = null; while (z == null) { string formattedSQL = String.Format(sql.ToString(), new string[] { id.ToString() }); DataSet ds = this.RunSelectQuery(formattedSQL); if (hasSingleRow(ds)) { DataRow dr = ds.Tables[0].Rows[0]; try { z = fromDataRow(dr); return(z); } catch { try { id = Convert.ToInt32(dr["ParentPageId"]); } catch { break; } } // catch } // if hasRows else { throw new Exception("Error: can not execute Zone SQL: " + formattedSQL); } } return(z); }
/// <summary> /// Select all the aurhority definitions by providing a zone (zone ID) /// </summary> /// <param name="z"></param> /// <returns></returns> public List <CmsPageSecurityZoneUserRole> fetchAllByZone(CmsPageSecurityZone z) { StringBuilder sql = new StringBuilder("SELECT ZoneId,UserRoleId,ReadAccess,WriteAccess FROM "); sql.Append(TABLE_NAME); sql.Append(" WHERE ZoneId=" + z.ZoneId.ToString()); sql.Append(" ORDER by ZoneId, UserRoleId;"); DataSet ds = this.RunSelectQuery(sql.ToString()); List <CmsPageSecurityZoneUserRole> list = new List <CmsPageSecurityZoneUserRole>(); if (this.hasRows(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { list.Add(fromDataRow(dr)); } } return(list); }
/// <summary> /// Insert into `zone` /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool insert(CmsPageSecurityZone entity) { StringBuilder sql = new StringBuilder("INSERT INTO "); sql.Append(TABLE_NAME); sql.Append(" (StartingPageId,ZoneName) VALUES ("); sql.Append(entity.StartingPageId.ToString() + ",'"); sql.Append(dbEncode(entity.ZoneName) + "');"); int newId = this.RunInsertQuery(sql.ToString()); if (newId > 0) { entity.ZoneId = newId; return(true); } else { return(false); } }
/// <summary> /// Delete from `Zone` /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool delete(CmsPageSecurityZone entity) { PageSecurityZoneRepository repository = new PageSecurityZoneRepository(); return(repository.delete(entity)); }
/// <summary> /// Count the number of roles ID defined. If the count is zero, it indicates /// the WebPortalUser does not belong to the roles which are required to access /// the zone. /// </summary> /// <param name="z"></param> /// <param name="roleArray"></param> /// <returns></returns> public int fetchRoleMatchingCountForWrite(CmsPageSecurityZone z, WebPortalUserRole[] roleArray) { //PageSecurityZoneUserRoleRepository repository = new PageSecurityZoneUserRoleRepository(); return(repository.fetchRoleMatchingCountForWrite(z, roleArray)); }
/// <summary> /// Delete records according to zone id /// </summary> /// <param name="z"></param> /// <returns></returns> public bool deleteByZone(CmsPageSecurityZone z) { //PageSecurityZoneUserRoleRepository repository = new PageSecurityZoneUserRoleRepository(); return(repository.deleteByZone(z)); }