/DataAccess/ORM/AutoGen/SessionsManager.cs

https://bitbucket.org/suwatch/svcodecampweb · C# · 204 lines · 174 code · 17 blank · 13 comment · 96 complexity · 5262c58ef44fd92aed42764a2a7e52da MD5 · raw file

  1. // This is the Manager class used for data operations. It is meant to have another Partial
  2. // class associated with it.
  3. // C 3PLogic, Inc.
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.ComponentModel;
  8. using CodeCampSV;
  9. namespace CodeCampSV
  10. {
  11. // Here are the 2 methods that needs to be auto genearted.
  12. // First is a one to one maping to the database columns.
  13. // Since we auto generate the results class too, we can guarantee the columns are all there
  14. [DataObject(true)]
  15. public partial class SessionsManager : ManagerBase<SessionsManager, SessionsResult, Sessions, CodeCampDataContext>
  16. {
  17. protected override void ApplyToDataModel(Sessions record, SessionsResult result)
  18. {
  19. record.CodeCampYearId = result.CodeCampYearId;
  20. record.SessionLevel_id = result.SessionLevel_id;
  21. record.SponsorId = result.SponsorId;
  22. record.Username = result.Username;
  23. record.Title = result.Title;
  24. record.Description = result.Description;
  25. record.Approved = result.Approved;
  26. record.Createdate = result.Createdate;
  27. record.Updatedate = result.Updatedate;
  28. record.AdminComments = result.AdminComments;
  29. record.DoNotShowPrimarySpeaker = result.DoNotShowPrimarySpeaker;
  30. record.InterentAccessRequired = result.InterentAccessRequired;
  31. record.LectureRoomsId = result.LectureRoomsId;
  32. record.SessionTimesId = result.SessionTimesId;
  33. record.TweetLine = result.TweetLine;
  34. record.TweetLineTweetedDate = result.TweetLineTweetedDate;
  35. record.TweetLineTweeted = result.TweetLineTweeted;
  36. record.SessionsMaterialUrl = result.SessionsMaterialUrl;
  37. record.SessionsMaterialQueueToSend = result.SessionsMaterialQueueToSend;
  38. record.SessionMaterialUrlDateSent = result.SessionMaterialUrlDateSent;
  39. record.SessionMaterialUrlMessage = result.SessionMaterialUrlMessage;
  40. record.TwitterHashTags = result.TwitterHashTags;
  41. record.TweetLinePreCamp = result.TweetLinePreCamp;
  42. record.TweetLineTweetedDatePreCamp = result.TweetLineTweetedDatePreCamp;
  43. record.TweetLineTweetedPreCamp = result.TweetLineTweetedPreCamp;
  44. record.ShortUrl = result.ShortUrl;
  45. record.BoxFolderIdString = result.BoxFolderIdString;
  46. record.BoxFolderEmailInAddress = result.BoxFolderEmailInAddress;
  47. record.BoxFolderPublicUrl = result.BoxFolderPublicUrl;
  48. record.OptInTechJobKeyWords = result.OptInTechJobKeyWords;
  49. //
  50. // Used by Default in Update and Insert Methods.
  51. }
  52. protected override Sessions GetEntityById(CodeCampDataContext meta, int id)
  53. {
  54. return (from r in meta.Sessions where r.Id == id select r).FirstOrDefault();
  55. }
  56. public IQueryable<SessionsResult> GetBaseResultIQueryable(IQueryable<Sessions> baseQuery)
  57. {
  58. IQueryable<SessionsResult> results = (from myData in baseQuery orderby myData.Id select new SessionsResult { Id= myData.Id,
  59. CodeCampYearId = myData.CodeCampYearId,
  60. SessionLevel_id = myData.SessionLevel_id,
  61. SponsorId = myData.SponsorId,
  62. Username = myData.Username,
  63. Title = myData.Title,
  64. Description = myData.Description,
  65. Approved = myData.Approved,
  66. Createdate = myData.Createdate == null ? null : (DateTime?) new DateTime(myData.Createdate.Value.Ticks,DateTimeKind.Utc),
  67. Updatedate = myData.Updatedate == null ? null : (DateTime?) new DateTime(myData.Updatedate.Value.Ticks,DateTimeKind.Utc),
  68. AdminComments = myData.AdminComments,
  69. DoNotShowPrimarySpeaker = myData.DoNotShowPrimarySpeaker,
  70. InterentAccessRequired = myData.InterentAccessRequired,
  71. LectureRoomsId = myData.LectureRoomsId,
  72. SessionTimesId = myData.SessionTimesId,
  73. TweetLine = myData.TweetLine,
  74. TweetLineTweetedDate = myData.TweetLineTweetedDate == null ? null : (DateTime?) new DateTime(myData.TweetLineTweetedDate.Value.Ticks,DateTimeKind.Utc),
  75. TweetLineTweeted = myData.TweetLineTweeted,
  76. SessionsMaterialUrl = myData.SessionsMaterialUrl,
  77. SessionsMaterialQueueToSend = myData.SessionsMaterialQueueToSend,
  78. SessionMaterialUrlDateSent = myData.SessionMaterialUrlDateSent == null ? null : (DateTime?) new DateTime(myData.SessionMaterialUrlDateSent.Value.Ticks,DateTimeKind.Utc),
  79. SessionMaterialUrlMessage = myData.SessionMaterialUrlMessage,
  80. TwitterHashTags = myData.TwitterHashTags,
  81. TweetLinePreCamp = myData.TweetLinePreCamp,
  82. TweetLineTweetedDatePreCamp = myData.TweetLineTweetedDatePreCamp == null ? null : (DateTime?) new DateTime(myData.TweetLineTweetedDatePreCamp.Value.Ticks,DateTimeKind.Utc),
  83. TweetLineTweetedPreCamp = myData.TweetLineTweetedPreCamp,
  84. ShortUrl = myData.ShortUrl,
  85. BoxFolderIdString = myData.BoxFolderIdString,
  86. BoxFolderEmailInAddress = myData.BoxFolderEmailInAddress,
  87. BoxFolderPublicUrl = myData.BoxFolderPublicUrl,
  88. OptInTechJobKeyWords = myData.OptInTechJobKeyWords
  89. });
  90. return results;
  91. }
  92. public List<SessionsResult> GetJustBaseTableColumns(SessionsQuery query)
  93. {
  94. foreach (var info in typeof (SessionsQuery).GetProperties())
  95. {
  96. object value = info.GetValue(query, null);
  97. if (value != null)
  98. {
  99. object[] attributes = info.GetCustomAttributes(typeof (AutoGenColumnAttribute), true);
  100. if (attributes.Length == 0)
  101. {
  102. string errorMessage = String.Format("Attribute Illegal Here, Use Normal Get(..), not GetJustBaseTableColumns(..) Table: Sessions QueryColumnProblem: {0}",info.Name);
  103. throw new ApplicationException(errorMessage);
  104. }
  105. }
  106. }
  107. var meta = new CodeCampDataContext();
  108. IQueryable<Sessions> baseQuery = from myData in meta.Sessions select myData;
  109. baseQuery = BaseQueryAutoGen(baseQuery,query);
  110. IQueryable<SessionsResult> results = (from myData in baseQuery orderby myData.Id select new SessionsResult { Id= myData.Id,
  111. CodeCampYearId = myData.CodeCampYearId,
  112. SessionLevel_id = myData.SessionLevel_id,
  113. SponsorId = myData.SponsorId,
  114. Username = myData.Username,
  115. Title = myData.Title,
  116. Description = myData.Description,
  117. Approved = myData.Approved,
  118. Createdate = myData.Createdate == null ? null : (DateTime?) new DateTime(myData.Createdate.Value.Ticks,DateTimeKind.Utc),
  119. Updatedate = myData.Updatedate == null ? null : (DateTime?) new DateTime(myData.Updatedate.Value.Ticks,DateTimeKind.Utc),
  120. AdminComments = myData.AdminComments,
  121. DoNotShowPrimarySpeaker = myData.DoNotShowPrimarySpeaker,
  122. InterentAccessRequired = myData.InterentAccessRequired,
  123. LectureRoomsId = myData.LectureRoomsId,
  124. SessionTimesId = myData.SessionTimesId,
  125. TweetLine = myData.TweetLine,
  126. TweetLineTweetedDate = myData.TweetLineTweetedDate == null ? null : (DateTime?) new DateTime(myData.TweetLineTweetedDate.Value.Ticks,DateTimeKind.Utc),
  127. TweetLineTweeted = myData.TweetLineTweeted,
  128. SessionsMaterialUrl = myData.SessionsMaterialUrl,
  129. SessionsMaterialQueueToSend = myData.SessionsMaterialQueueToSend,
  130. SessionMaterialUrlDateSent = myData.SessionMaterialUrlDateSent == null ? null : (DateTime?) new DateTime(myData.SessionMaterialUrlDateSent.Value.Ticks,DateTimeKind.Utc),
  131. SessionMaterialUrlMessage = myData.SessionMaterialUrlMessage,
  132. TwitterHashTags = myData.TwitterHashTags,
  133. TweetLinePreCamp = myData.TweetLinePreCamp,
  134. TweetLineTweetedDatePreCamp = myData.TweetLineTweetedDatePreCamp == null ? null : (DateTime?) new DateTime(myData.TweetLineTweetedDatePreCamp.Value.Ticks,DateTimeKind.Utc),
  135. TweetLineTweetedPreCamp = myData.TweetLineTweetedPreCamp,
  136. ShortUrl = myData.ShortUrl,
  137. BoxFolderIdString = myData.BoxFolderIdString,
  138. BoxFolderEmailInAddress = myData.BoxFolderEmailInAddress,
  139. BoxFolderPublicUrl = myData.BoxFolderPublicUrl,
  140. OptInTechJobKeyWords = myData.OptInTechJobKeyWords
  141. });
  142. List<SessionsResult> resultList = GetFinalResults(results, query);
  143. //
  144. return resultList;
  145. }
  146. // This is called from partial class which can be modified and not regenerated
  147. // This class is expected to be regenerated as new columns are added
  148. private static IQueryable<Sessions> BaseQueryAutoGen(IQueryable<Sessions> baseQuery, SessionsQuery query)
  149. {
  150. // This assumes all tables have an Id column
  151. if (query.Id != null) baseQuery = baseQuery.Where(a => a.Id == query.Id);
  152. if (query.Ids != null) baseQuery = baseQuery.Where(a => query.Ids.Contains(a.Id));
  153. // Generate Queries for Each type of data
  154. if (query.CodeCampYearId != null) baseQuery = baseQuery.Where(a => a.CodeCampYearId == query.CodeCampYearId);
  155. if (query.SessionLevel_id != null) baseQuery = baseQuery.Where(a => a.SessionLevel_id == query.SessionLevel_id);
  156. if (query.SponsorId != null) baseQuery = baseQuery.Where(a => a.SponsorId == query.SponsorId);
  157. if (query.Username != null) baseQuery = baseQuery.Where(a => a.Username.ToLower().Equals(query.Username.ToLower()));
  158. if (query.Title != null) baseQuery = baseQuery.Where(a => a.Title.ToLower().Equals(query.Title.ToLower()));
  159. if (query.Description != null) baseQuery = baseQuery.Where(a => a.Description.ToLower().Equals(query.Description.ToLower()));
  160. if (query.Approved != null) baseQuery = baseQuery.Where(a => a.Approved == query.Approved);
  161. if (query.Createdate != null) baseQuery = baseQuery.Where(a => a.Createdate.Value.CompareTo(query.Createdate.Value) == 0);
  162. if (query.Updatedate != null) baseQuery = baseQuery.Where(a => a.Updatedate.Value.CompareTo(query.Updatedate.Value) == 0);
  163. if (query.AdminComments != null) baseQuery = baseQuery.Where(a => a.AdminComments.ToLower().Equals(query.AdminComments.ToLower()));
  164. if (query.DoNotShowPrimarySpeaker != null) baseQuery = baseQuery.Where(a => a.DoNotShowPrimarySpeaker == query.DoNotShowPrimarySpeaker);
  165. if (query.InterentAccessRequired != null) baseQuery = baseQuery.Where(a => a.InterentAccessRequired == query.InterentAccessRequired);
  166. if (query.LectureRoomsId != null) baseQuery = baseQuery.Where(a => a.LectureRoomsId == query.LectureRoomsId);
  167. if (query.SessionTimesId != null) baseQuery = baseQuery.Where(a => a.SessionTimesId == query.SessionTimesId);
  168. if (query.TweetLine != null) baseQuery = baseQuery.Where(a => a.TweetLine.ToLower().Equals(query.TweetLine.ToLower()));
  169. if (query.TweetLineTweetedDate != null) baseQuery = baseQuery.Where(a => a.TweetLineTweetedDate.Value.CompareTo(query.TweetLineTweetedDate.Value) == 0);
  170. if (query.TweetLineTweeted != null) baseQuery = baseQuery.Where(a => a.TweetLineTweeted == query.TweetLineTweeted);
  171. if (query.SessionsMaterialUrl != null) baseQuery = baseQuery.Where(a => a.SessionsMaterialUrl.ToLower().Equals(query.SessionsMaterialUrl.ToLower()));
  172. if (query.SessionsMaterialQueueToSend != null) baseQuery = baseQuery.Where(a => a.SessionsMaterialQueueToSend == query.SessionsMaterialQueueToSend);
  173. if (query.SessionMaterialUrlDateSent != null) baseQuery = baseQuery.Where(a => a.SessionMaterialUrlDateSent.Value.CompareTo(query.SessionMaterialUrlDateSent.Value) == 0);
  174. if (query.SessionMaterialUrlMessage != null) baseQuery = baseQuery.Where(a => a.SessionMaterialUrlMessage.ToLower().Equals(query.SessionMaterialUrlMessage.ToLower()));
  175. if (query.TwitterHashTags != null) baseQuery = baseQuery.Where(a => a.TwitterHashTags.ToLower().Equals(query.TwitterHashTags.ToLower()));
  176. if (query.TweetLinePreCamp != null) baseQuery = baseQuery.Where(a => a.TweetLinePreCamp.ToLower().Equals(query.TweetLinePreCamp.ToLower()));
  177. if (query.TweetLineTweetedDatePreCamp != null) baseQuery = baseQuery.Where(a => a.TweetLineTweetedDatePreCamp.Value.CompareTo(query.TweetLineTweetedDatePreCamp.Value) == 0);
  178. if (query.TweetLineTweetedPreCamp != null) baseQuery = baseQuery.Where(a => a.TweetLineTweetedPreCamp == query.TweetLineTweetedPreCamp);
  179. if (query.ShortUrl != null) baseQuery = baseQuery.Where(a => a.ShortUrl.ToLower().Equals(query.ShortUrl.ToLower()));
  180. if (query.BoxFolderIdString != null) baseQuery = baseQuery.Where(a => a.BoxFolderIdString.ToLower().Equals(query.BoxFolderIdString.ToLower()));
  181. if (query.BoxFolderEmailInAddress != null) baseQuery = baseQuery.Where(a => a.BoxFolderEmailInAddress.ToLower().Equals(query.BoxFolderEmailInAddress.ToLower()));
  182. if (query.BoxFolderPublicUrl != null) baseQuery = baseQuery.Where(a => a.BoxFolderPublicUrl.ToLower().Equals(query.BoxFolderPublicUrl.ToLower()));
  183. if (query.OptInTechJobKeyWords != null) baseQuery = baseQuery.Where(a => a.OptInTechJobKeyWords.ToLower().Equals(query.OptInTechJobKeyWords.ToLower()));
  184. return baseQuery;
  185. }
  186. }
  187. }