public List <FaqCategories> GetFaqByAllCategories() { string storedProc = "[dbo].[Faq_SelectAllByCategory]"; List <FaqCategories> FaqList = new List <FaqCategories>(); Dictionary <int, FaqCategories> dict = new Dictionary <int, FaqCategories>(); _dataProvider.ExecuteCmd(storedProc, inputParamMapper : delegate(SqlParameterCollection sqlParams) { }, singleRecordMapper : delegate(IDataReader reader, short set) { switch (set) { case 0: FaqCategories sqlCategories = new FaqCategories(); sqlCategories.FaqList = new List <Faq>(); int startingIndex = 0; sqlCategories.Id = reader.GetSafeInt32(startingIndex++); sqlCategories.Name = reader.GetSafeString(startingIndex++); FaqList.Add(sqlCategories); dict.Add(sqlCategories.Id, sqlCategories); break; case 1: startingIndex = 0; Faq faq = new Faq(); faq.Id = reader.GetSafeInt32(startingIndex++); faq.CategoryId = reader.GetSafeInt32(startingIndex++); faq.Question = reader.GetSafeString(startingIndex++); faq.Answer = reader.GetSafeString(startingIndex++); faq.SortOrder = reader.GetSafeInt32(startingIndex++); faq.DateCreated = reader.GetSafeUtcDateTime(startingIndex++); faq.DateModified = reader.GetSafeUtcDateTime(startingIndex++); faq.UserId = reader.GetSafeInt32(startingIndex++); if (dict.ContainsKey(faq.CategoryId)) { dict[faq.CategoryId].FaqList.Add(faq); } break; } }); return(FaqList); }
public Sabio.Models.Domain.FaqCategories GetByCategoryId(int id) { FaqCategories singleItem = new FaqCategories(); string storeProc = "[dbo].[Faq_SelectByCategoryId]"; _dataProvider.ExecuteCmd(storeProc, inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Id", id); }, singleRecordMapper : delegate(IDataReader reader, short set) { switch (set) { case 0: int startingIndex = 0; singleItem.Id = reader.GetSafeInt32(startingIndex++); singleItem.Name = reader.GetSafeString(startingIndex++); break; case 1: Faq faq = GetFaqMap(reader); if (singleItem.FaqList == null) { singleItem.FaqList = new List <Faq>(); } singleItem.FaqList.Add(faq); break; default: singleItem = null; break; } } ); return(singleItem); }