private void CacheEntityMappings(string entityType) { var entityMap = new StoreEntityMap() { StoreID = this.StoreID, EntityType = entityType }; entityMap.MappedObjects = MappedObjectCollection.GetObjects(this.StoreID, entityType); EntityMaps.Add(entityMap); }
/// <summary> /// Gets the mapped objects /// </summary> /// <param name="storeId"></param> /// <param name="entityType"></param> /// <param name="alphaFilter"></param> /// <param name="searchFilter"></param> /// <param name="pageSize"></param> /// <param name="page"></param> /// <returns></returns> public static MappedObjectCollection GetObjects(int storeId, string entityType, string alphaFilter, string searchFilter, int pageSize, int page) { var mapping = new MappedObjectCollection(); mapping.StoreID = storeId; mapping.EntityType = entityType; var cmd = new SqlCommand("aspdnsf_GetMappedObjects"); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@StoreId", SqlDbType.Int) { Value = storeId }); cmd.Parameters.Add(new SqlParameter("@EntityType", SqlDbType.NVarChar, 30) { Value = entityType }); // nullable parameters var pAlphaFilter = new SqlParameter("@AlphaFilter", SqlDbType.NVarChar, 30) { Value = DBNull.Value }; var pSearchFilter = new SqlParameter("@SearchFilter", SqlDbType.NVarChar, 30) { Value = DBNull.Value }; var pPageSize = new SqlParameter("@PageSize", SqlDbType.Int) { Value = DBNull.Value }; var pPage = new SqlParameter("@Page", SqlDbType.Int) { Value = DBNull.Value }; if (!string.IsNullOrEmpty(alphaFilter)) { pAlphaFilter.Value = alphaFilter; } if (!string.IsNullOrEmpty(searchFilter)) { pSearchFilter.Value = searchFilter; } if (pageSize > 0 && page > 0) { pPageSize.Value = pageSize; pPage.Value = page; } cmd.Parameters.Add(pAlphaFilter); cmd.Parameters.Add(pSearchFilter); cmd.Parameters.Add(pPageSize); cmd.Parameters.Add(pPage); Action <IDataReader> readAction = (rs) => { // first result set is the paging data if (rs.Read()) { var nfo = new PagingInfo(); nfo.TotalCount = rs.FieldInt("TotalCount"); nfo.PageSize = rs.FieldInt("PageSize"); nfo.CurrentPage = rs.FieldInt("CurrentPage"); nfo.TotalPages = rs.FieldInt("TotalPages"); nfo.StartIndex = rs.FieldInt("StartIndex"); nfo.EndIndex = rs.FieldInt("EndIndex"); mapping.PageInfo = nfo; } rs.NextResult(); // next is the actual result set while (rs.Read()) { var map = new MappedObject(); map.ID = rs.FieldInt("ID"); map.StoreID = storeId; map.Type = rs.Field("EntityType"); map.Name = rs.Field("Name"); map.IsMapped = rs.FieldBool("Mapped"); mapping.Add(map); } }; DB.UseDataReader(cmd, readAction); return(mapping); }