Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.Linq;
- using System.Linq;
- using System.Text;
- namespace DayQuestionDomainModel
- {
- public class QuestionsRepository : Repository<Question>
- {
- public QuestionsRepository(DayQDataClassesDataContext context)
- : base(context)
- {
- Context = context;
- }
- //public override void DeleteItem(Question item)
- //{
- // // dayQContext.GetTable<Variant>().DeleteAllOnSubmit(item.Variants);
- // base.DeleteItem(item);
- //}
- public DayQDataClassesDataContext Context { get; private set; }
- public override Question FindById(int id)
- {
- return table.SingleOrDefault(q => q.ID == id);
- }
- public Variant FindVariantById(int variantId)
- {
- return Context.Variants.SingleOrDefault(v => v.ID == variantId);
- }
- public IQueryable<Question> FindAllQuestions(Partner partner)
- {
- IQueryable<Question> questions = table.Where(q => q.Partner == partner);
- return questions;
- }
- //public Question[] FindAllQuestionsByDate(Partner partner, DateTime datetime)
- //{
- // var results = new List<Question>();
- // Table<QuestionHistory> archiveQuestions = Context.QuestionHistories;
- // DateTime startDate = new DateTime(datetime.Year, datetime.Month, datetime.Day);
- // DateTime endDate = startDate.AddDays(1);
- // var arcQuestions = archiveQuestions.Where(q => q.EventDate >= startDate)
- // .Where(q => q.EventDate <= endDate)
- // .Where(q => q.Question.Partner == partner)
- // .GroupBy(s => new { s.Question.ID })
- // .Select(group => new
- // {
- // Question = group.Select(x => x.Question).First()
- // });
- // foreach (var question in archiveQuestions)
- // {
- // results.Add(question.Question);
- // }
- // return results.ToArray();
- //}
- //public void AddQuestion2History(Question question, Partner partner)//, DateTime date)
- //{
- // QuestionHistory history = new QuestionHistory();
- // history.EventDate = DateTime.Now;
- // history.Question = question;
- // history.Partner = partner;
- // Context.QuestionHistories.InsertOnSubmit(history);
- // SaveAll();
- //}
- //public DateTime[] GetArchiveDateList()
- //{
- // Table<ArchiveQuestion> archiveQuestions = Context.ArchiveQuestions;
- // var dates = archiveQuestions.GroupBy(q => new {q.ArchiveDate.DayOfYear, q.ArchiveDate.Year})
- // .Select(group => new { ArchiveDate = group.Select(x => x.ArchiveDate).First() });
- // var dateList = new List<DateTime>();
- // foreach (var item in dates)
- // {
- // dateList.Add(item.ArchiveDate);
- // }
- // return dateList.ToArray();
- //}
- //public IQueryable<Question> FindAllArchivedQuestions(Partner partner)
- //{
- // IQueryable<Question> questions = table.Where(q => q.Partner == partner);
- // //.Where(q => q.IsArchived);
- // //.GroupBy(g => new {g.ID})
- // //.Select(group => new {Date = group.Select(x => x.ArchiveDate).First()}
- // return questions;
- //}
- //public Question[] FindAllArchivedQuestionsByDate(Partner partner, DateTime date)
- //{
- // var results = new List<Question>();
- // Table<ArchiveQuestion> archiveQuestions = Context.ArchiveQuestions;
- // var arcQuestions = archiveQuestions.Where(q => q.ArchiveDate >= date)
- // .Where(q => q.ArchiveDate <= date.AddDays(1))
- // .Where(q => q.Question.IsArchived)
- // .Where(q => q.Question.Partner == partner)
- // .GroupBy(s => new { s.Question.ID })
- // .Select(group => new
- // {
- // Question = group.Select(x => x.Question).First()
- // });
- // foreach (var question in arcQuestions)
- // {
- // results.Add(question.Question);
- // }
- // return results.ToArray();
- //}
- //public void UnArchiveQuestion (Question question)
- //{
- // question.IsArchived = false;
- // SaveAll();
- //}
- //public void SendQuestion2Archive(Question question)
- //{
- // DayQDataClassesDataContext dbContext = DbContextFactory.GetNew();
- // var qprepo = new QuestionsPacketRepository(dbContext);
- // QuestionPacket packet = qprepo.FindByPartnerIDandQuestionID(question.ID, question.PartnerId);
- // if (packet != null) qprepo.DeleteItem(packet);
- // question.IsArchived = true;
- // var archiveQuestion = new ArchiveQuestion
- // {
- // Question = question,
- // ArchiveDate = DateTime.Now
- // };
- // Context.ArchiveQuestions.InsertOnSubmit(archiveQuestion);
- // SaveAll();
- //}
- public void Replace2Current(Question question)
- {
- throw new NotImplementedException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement