// Gets item from db by Id public static CalendarDomainItem GetCalendarItem(int id) { CalendarDomainItem item = null; DataProvider.ExecuteCmd(GetConnection, "dbo.CalendarData_SelectById" , inputParamMapper : delegate(SqlParameterCollection commentsCollection) { commentsCollection.AddWithValue("@Id", id); }, map : delegate(IDataReader reader, short set) { item = MapCalendar(reader); }); return(item); }
// Mapping the item. Using DRY methodology. public static CalendarDomainItem MapCalendar(IDataReader reader) { CalendarDomainItem item = new CalendarDomainItem(); int startingindex = 0; item.Id = reader.GetInt32(startingindex++); item.Title = reader.GetString(startingindex++); item.Location = reader.GetString(startingindex++); item.Description = reader.GetString(startingindex++); item.StartTime = reader.GetDateTime(startingindex++); item.EndTime = reader.GetDateTime(startingindex++); item.Date = reader.GetDateTime(startingindex++); return(item); }
// Gets List of Items in db public static List <CalendarDomainItem> GetCalendarItemList() { List <CalendarDomainItem> list = null; DataProvider.ExecuteCmd(GetConnection, "dbo.CalendarData_SelectAll", inputParamMapper : null, map : delegate(IDataReader reader, short set) { CalendarDomainItem item = MapCalendar(reader); if (list == null) { list = new List <CalendarDomainItem>(); } list.Add(item); } ); return(list); }
// Gets List of Items in db public static List <CalendarDomainItem> GetCalendarItemListByDate(DateTime Date) { List <CalendarDomainItem> list = null; DataProvider.ExecuteCmd(GetConnection, "dbo.CalendarData_SelectByDate", inputParamMapper : delegate(SqlParameterCollection commentsCollection) { commentsCollection.AddWithValue("@Date", Date); }, map : delegate(IDataReader reader, short set) { CalendarDomainItem item = MapCalendar(reader); if (list == null) { list = new List <CalendarDomainItem>(); } list.Add(item); } ); return(list); }