Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Linq;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace DayQuestionDomainModel
  8. {
  9.  
  10. public class QuestionsRepository : Repository<Question>
  11. {
  12. public QuestionsRepository(DayQDataClassesDataContext context)
  13. : base(context)
  14. {
  15. Context = context;
  16. }
  17.  
  18.  
  19. //public override void DeleteItem(Question item)
  20. //{
  21. // // dayQContext.GetTable<Variant>().DeleteAllOnSubmit(item.Variants);
  22. // base.DeleteItem(item);
  23. //}
  24.  
  25.  
  26. public DayQDataClassesDataContext Context { get; private set; }
  27.  
  28. public override Question FindById(int id)
  29. {
  30. return table.SingleOrDefault(q => q.ID == id);
  31. }
  32.  
  33. public Variant FindVariantById(int variantId)
  34. {
  35. return Context.Variants.SingleOrDefault(v => v.ID == variantId);
  36. }
  37.  
  38.  
  39. public IQueryable<Question> FindAllQuestions(Partner partner)
  40. {
  41. IQueryable<Question> questions = table.Where(q => q.Partner == partner);
  42.  
  43. return questions;
  44. }
  45.  
  46.  
  47. //public Question[] FindAllQuestionsByDate(Partner partner, DateTime datetime)
  48. //{
  49. // var results = new List<Question>();
  50.  
  51. // Table<QuestionHistory> archiveQuestions = Context.QuestionHistories;
  52.  
  53.  
  54. // DateTime startDate = new DateTime(datetime.Year, datetime.Month, datetime.Day);
  55. // DateTime endDate = startDate.AddDays(1);
  56.  
  57. // var arcQuestions = archiveQuestions.Where(q => q.EventDate >= startDate)
  58. // .Where(q => q.EventDate <= endDate)
  59. // .Where(q => q.Question.Partner == partner)
  60. // .GroupBy(s => new { s.Question.ID })
  61. // .Select(group => new
  62. // {
  63. // Question = group.Select(x => x.Question).First()
  64. // });
  65.  
  66. // foreach (var question in archiveQuestions)
  67. // {
  68. // results.Add(question.Question);
  69. // }
  70.  
  71. // return results.ToArray();
  72. //}
  73.  
  74.  
  75. //public void AddQuestion2History(Question question, Partner partner)//, DateTime date)
  76. //{
  77. // QuestionHistory history = new QuestionHistory();
  78. // history.EventDate = DateTime.Now;
  79. // history.Question = question;
  80. // history.Partner = partner;
  81.  
  82. // Context.QuestionHistories.InsertOnSubmit(history);
  83. // SaveAll();
  84. //}
  85. //public DateTime[] GetArchiveDateList()
  86. //{
  87. // Table<ArchiveQuestion> archiveQuestions = Context.ArchiveQuestions;
  88.  
  89. // var dates = archiveQuestions.GroupBy(q => new {q.ArchiveDate.DayOfYear, q.ArchiveDate.Year})
  90. // .Select(group => new { ArchiveDate = group.Select(x => x.ArchiveDate).First() });
  91.  
  92. // var dateList = new List<DateTime>();
  93. // foreach (var item in dates)
  94. // {
  95. // dateList.Add(item.ArchiveDate);
  96. // }
  97.  
  98.  
  99. // return dateList.ToArray();
  100. //}
  101.  
  102.  
  103. //public IQueryable<Question> FindAllArchivedQuestions(Partner partner)
  104. //{
  105. // IQueryable<Question> questions = table.Where(q => q.Partner == partner);
  106. // //.Where(q => q.IsArchived);
  107. // //.GroupBy(g => new {g.ID})
  108. // //.Select(group => new {Date = group.Select(x => x.ArchiveDate).First()}
  109.  
  110.  
  111. // return questions;
  112. //}
  113.  
  114.  
  115.  
  116.  
  117. //public Question[] FindAllArchivedQuestionsByDate(Partner partner, DateTime date)
  118. //{
  119.  
  120. // var results = new List<Question>();
  121.  
  122. // Table<ArchiveQuestion> archiveQuestions = Context.ArchiveQuestions;
  123.  
  124.  
  125. // var arcQuestions = archiveQuestions.Where(q => q.ArchiveDate >= date)
  126. // .Where(q => q.ArchiveDate <= date.AddDays(1))
  127. // .Where(q => q.Question.IsArchived)
  128. // .Where(q => q.Question.Partner == partner)
  129. // .GroupBy(s => new { s.Question.ID })
  130. // .Select(group => new
  131. // {
  132. // Question = group.Select(x => x.Question).First()
  133.  
  134. // });
  135.  
  136.  
  137. // foreach (var question in arcQuestions)
  138. // {
  139. // results.Add(question.Question);
  140. // }
  141.  
  142. // return results.ToArray();
  143. //}
  144.  
  145.  
  146. //public void UnArchiveQuestion (Question question)
  147. //{
  148. // question.IsArchived = false;
  149. // SaveAll();
  150. //}
  151.  
  152. //public void SendQuestion2Archive(Question question)
  153. //{
  154.  
  155. // DayQDataClassesDataContext dbContext = DbContextFactory.GetNew();
  156.  
  157. // var qprepo = new QuestionsPacketRepository(dbContext);
  158. // QuestionPacket packet = qprepo.FindByPartnerIDandQuestionID(question.ID, question.PartnerId);
  159. // if (packet != null) qprepo.DeleteItem(packet);
  160.  
  161. // question.IsArchived = true;
  162.  
  163. // var archiveQuestion = new ArchiveQuestion
  164. // {
  165. // Question = question,
  166. // ArchiveDate = DateTime.Now
  167. // };
  168.  
  169.  
  170.  
  171.  
  172.  
  173. // Context.ArchiveQuestions.InsertOnSubmit(archiveQuestion);
  174.  
  175. // SaveAll();
  176. //}
  177.  
  178. public void Replace2Current(Question question)
  179. {
  180. throw new NotImplementedException();
  181. }
  182. }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement