Exemplo n.º 1
0
 public void SaveQuestions(IEnumerable <Question> questions, int parentId)
 {
     using (var db = new TournsDataContext(TournsDataContext.DbConnectionString))
     {
         var qs = questions.ToList();
         foreach (var question in qs)
         {
             var q = Mapper.Map <Question, Model.Question>(question);
             q.TournId = parentId;
             db.QuestionItems.InsertOnSubmit(q);
             db.SubmitChanges();
             if (question.TextImages != null)
             {
                 foreach (var image in question.TextImages)
                 {
                     var img = new Image {
                         Data = image.Data, QuestionId = q.Id, Type = ImageType.Question
                     };
                     db.ImageItems.InsertOnSubmit(img);
                 }
             }
             if (question.CommentImages != null)
             {
                 foreach (var image in question.CommentImages)
                 {
                     var img = new Image {
                         Data = image.Data, QuestionId = q.Id, Type = ImageType.Comment
                     };
                     db.ImageItems.InsertOnSubmit(img);
                 }
             }
             if (question.AnswerImages != null)
             {
                 foreach (var image in question.AnswerImages)
                 {
                     var img = new Image {
                         Data = image.Data, QuestionId = q.Id, Type = ImageType.Answer
                     };
                     db.ImageItems.InsertOnSubmit(img);
                 }
             }
             db.SubmitChanges();
         }
         var t = db.TournItems.FirstOrDefault(el => el.Id == parentId);
         t.HasChildTourns = false;
         t.Loaded         = DateTime.Now;
         db.SubmitChanges();
     }
     //throw new NotImplementedException();
 }
Exemplo n.º 2
0
 public void SaveTourns(IEnumerable <Tourn> tourns, int?parentId)
 {
     using (var db = new TournsDataContext(TournsDataContext.DbConnectionString))
     {
         if (parentId.HasValue)
         {
             var parent = db.TournItems.First(el => el.Id == parentId);
             parent.HasChildTourns = true;
         }
         foreach (var tourn in tourns)
         {
             var existTourn = db.TournItems.FirstOrDefault(el => el.SourceId == tourn.SourceId);
             if (existTourn == null)
             {
                 var t = Mapper.Map <Tourn, Model.Tourn>(tourn);
                 db.TournItems.InsertOnSubmit(t);
             }
             else
             {
                 UpdateItem(existTourn, tourn, new List <string> {
                     "Id", "ParentId", "LastOpened", "LastQuestion", "Loaded", "HasChildTourns"
                 });
             }
         }
         db.SubmitChanges();
     }
 }
Exemplo n.º 3
0
 public void SetLastQuestion(int tournId, int questionNum)
 {
     using (var db = new TournsDataContext(TournsDataContext.DbConnectionString))
     {
         var tourn = db.TournItems.FirstOrDefault(el => el.Id == tournId);
         tourn.LastQuestion = questionNum;
         db.SubmitChanges();
     }
 }
Exemplo n.º 4
0
        public IEnumerable <Question> GetQuestions(int tournId)
        {
            using (var db = new TournsDataContext(TournsDataContext.DbConnectionString))
            {
                var questions =
                    db.QuestionItems.Where(el => el.TournId == tournId)
                    .ToList();

                var res = new List <Question>();

                foreach (var question in questions)
                {
                    var q = Mapper.Map <Model.Question, Question>(question);
                    q.TextImages =
                        db.ImageItems.Where(el => el.QuestionId == question.Id && el.Type == ImageType.Question)
                        .Select(el => new LogicLayer.Model.Image()
                    {
                        Data = el.Data, Id = el.Id
                    })
                        .ToList();
                    q.CommentImages =
                        db.ImageItems.Where(el => el.QuestionId == question.Id && el.Type == ImageType.Comment)
                        .Select(el => new LogicLayer.Model.Image()
                    {
                        Data = el.Data, Id = el.Id
                    })
                        .ToList();
                    q.AnswerImages =
                        db.ImageItems.Where(el => el.QuestionId == question.Id && el.Type == ImageType.Answer)
                        .Select(el => new LogicLayer.Model.Image()
                    {
                        Data = el.Data, Id = el.Id
                    })
                        .ToList();
                    res.Add(q);
                }

                var tourn = db.TournItems.FirstOrDefault(el => el.Id == tournId);
                tourn.LastOpened = DateTime.Now;
                db.SubmitChanges();

                return(res);
            }
        }