Exemple #1
0
        public void CreateThematicArea(string thematicArea)
        {
            var newThematicArea = new ThematicArea {
                Name = thematicArea
            };

            if (string.IsNullOrEmpty(thematicArea))
            {
                return;
            }

            using (var context = new AppDbContext())
            {
                //context.Database.Log = Console.WriteLine;
                try
                {
                    if (context.ThematicAreas.SingleOrDefault(t => t.Name.Equals(thematicArea)) == null)
                    {
                        context.ThematicAreas.Add(newThematicArea);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }


                context.SaveChanges();
            }
        }
Exemple #2
0
        public int CreateQuestion(QuestionDTO question, string thematicArea)
        {
            var newQuestion = Mapping.Mapper.Map <Question>(question);


            int id;

            using (var context = new AppDbContext())
            {
                var tA = context.ThematicAreas.SingleOrDefault(c => c.Name.Equals(thematicArea));
                if (tA != null)
                {
                    tA.Questions.Add(newQuestion);
                    newQuestion.ThematicArea = tA;
                    context.Entry(tA).State  = EntityState.Modified;
                    context.SaveChanges();
                }
                else
                {
                    var them = new ThematicArea {
                        Name = thematicArea
                    };

                    them.Questions.Add(newQuestion);
                    context.ThematicAreas.Add(them);

                    newQuestion.ThematicArea = context.ThematicAreas.SingleOrDefault(t => t.Name.Equals(thematicArea));

                    context.Questions.Add(newQuestion);

                    context.SaveChanges();
                }

                id = newQuestion.Id;
            }



            return(id);
        }