/// <summary> /// select file library aggregator data /// </summary> /// <param name="page"></param> /// <param name="identifier"></param> /// <param name="lang"></param> /// <param name="createIfNotExist"></param> /// <returns></returns> public FileLibraryAggregatorData fetchAggregatorData(CmsPage page, int identifier, CmsLanguage lang, bool createIfNotExist) { if (page.ID < 0 || identifier < 0) { return(new FileLibraryAggregatorData()); } StringBuilder sql = new StringBuilder("SELECT NumFilesOverview,NumFilesPerPage FROM "); sql.Append(AGGREGATOR_TABLE); sql.Append(" WHERE PageId=" + page.ID.ToString()); sql.Append(" AND LangCode='" + lang.shortCode + "'"); sql.Append(" AND Identifier=" + identifier.ToString()); sql.Append(" AND Deleted is null;"); FileLibraryAggregatorData entity = new FileLibraryAggregatorData(); DataSet ds = this.RunSelectQuery(sql.ToString()); if (this.hasSingleRow(ds)) { DataRow dr = ds.Tables[0].Rows[0]; rowToData(dr, entity); } else { if (createIfNotExist) { if (insertFileLibraryAggregator(page, identifier, lang, entity) == false) { throw new Exception("fetchFileLibraryAggregator() database error: Error creating new placeholder"); } } else { throw new Exception("fetchFileLibraryAggregator() database error: placeholder does not exist"); } } return(entity); }
/// <summary> /// Put datarow raw values to entity object /// </summary> /// <param name="dr"></param> /// <param name="entity"></param> protected void rowToData(DataRow dr, FileLibraryAggregatorData entity) { entity.NumFilesForOverview = Convert.ToInt32(dr["NumFilesOverview"]); entity.NumFilesPerPage = Convert.ToInt32(dr["NumFilesPerPage"]); }
/// <summary> /// Insert file library aggregator data /// </summary> /// <param name="page"></param> /// <param name="identifier"></param> /// <param name="lang"></param> /// <param name="entity"></param> /// <returns></returns> public bool insertFileLibraryAggregator(CmsPage page, int identifier, CmsLanguage lang, FileLibraryAggregatorData entity) { StringBuilder sql = new StringBuilder("INSERT INTO "); sql.Append(AGGREGATOR_TABLE); sql.Append(" (PageId,Identifier,LangCode,NumFilesOverview,NumFilesPerPage) VALUES ("); sql.Append(page.ID.ToString() + ","); sql.Append(identifier.ToString() + ",'"); sql.Append(dbEncode(lang.shortCode) + "',"); sql.Append(entity.NumFilesForOverview.ToString() + ","); sql.Append(entity.NumFilesPerPage.ToString() + ");"); int affected = this.RunUpdateQuery(sql.ToString()); if (affected > 0) { return(page.setLastUpdatedDateTimeToNow()); } else { return(false); } }
/// <summary> /// Update file library aggregator data /// </summary> /// <param name="page"></param> /// <param name="identifier"></param> /// <param name="lang"></param> /// <param name="entity"></param> /// <returns></returns> public bool updateAggregatorData(CmsPage page, int identifier, CmsLanguage lang, FileLibraryAggregatorData entity) { StringBuilder sql = new StringBuilder("UPDATE "); sql.Append(AGGREGATOR_TABLE); sql.Append(" SET NumFilesOverview=" + entity.NumFilesForOverview.ToString() + ","); sql.Append(" NumFilesPerPage=" + entity.NumFilesPerPage.ToString()); sql.Append(" WHERE PageId=" + page.ID.ToString()); sql.Append(" AND LangCode='" + lang.shortCode + "'"); sql.Append(" AND Identifier=" + identifier.ToString()); int affected = this.RunUpdateQuery(sql.ToString()); return(affected > 0); }