コード例 #1
0
 public bool questionInSurvey(int id)
 {
     using (var context = new SuerveyDbContext())
     {
         return(context.Questions.SingleOrDefault(q => q.Id == id).Surveys.Count > 0);
     }
 }
コード例 #2
0
 public Survey Get(int id)
 {
     using (var context = new SuerveyDbContext())
     {
         return(context.Surveys.SingleOrDefault(s => s.Id == id && s.IsArchived == false));
     }
 }
コード例 #3
0
        public bool RemoveOptionToQuestion(int optionid, int questionid)
        {
            using (var context = new SuerveyDbContext())
            {
                var    currentquestion = context.Questions.SingleOrDefault(x => x.Id == questionid);
                Option currentoption   = null;
                var    findoption      = context.Options.SingleOrDefault(x => x.Id == optionid);

                if (findoption.Questions.Any(x => x.Id == questionid))
                {
                    currentoption = findoption;
                }

                if (currentoption == null || currentquestion == null)
                {
                    return(false);
                }

                currentoption.Questions.Add(currentquestion);
                currentquestion.Options.Add(currentoption);
                context.SaveChanges();

                return(true);
            }
        }
コード例 #4
0
 public ICollection <QuestionType> GetAll()
 {
     using (var context = new SuerveyDbContext())
     {
         return(context.QuetionTypes.ToList());
     }
 }
コード例 #5
0
 public ICollection <Question> GetQuestionBySurvey(int surveyid)
 {
     using (var context = new SuerveyDbContext())
     {
         return(context.Surveys.SingleOrDefault(x => x.Id == surveyid && x.IsArchived == false).Questions.ToList());
     }
 }
コード例 #6
0
        public bool RemoveQuestionToSurvey(int surveyid, int questionid)
        {
            using (var context = new SuerveyDbContext())
            {
                var      currentsurvey   = context.Surveys.SingleOrDefault(x => x.Id == surveyid);
                Question currentquestion = null;
                var      findquestion    = context.Questions.SingleOrDefault(x => x.Id == questionid);

                if (findquestion.Surveys.Any(x => x.Id == surveyid))
                {
                    currentquestion = findquestion;
                }

                if (currentsurvey == null || currentquestion == null)
                {
                    return(false);
                }

                currentsurvey.Questions.Remove(currentquestion);
                currentquestion.Surveys.Remove(currentsurvey);
                context.SaveChanges();

                return(true);
            }
        }
コード例 #7
0
 public bool optionIsAssigned(int id)
 {
     using (var context = new SuerveyDbContext())
     {
         return(context.Options.SingleOrDefault(o => o.Id == id).Questions.Count > 0);
     }
 }
コード例 #8
0
 public bool optionExists(string text)
 {
     using (var context = new SuerveyDbContext())
     {
         return(context.Options.Any(o => o.Text.ToLower() == text.ToLower()));
     }
 }
コード例 #9
0
 public Option Get(int id)
 {
     using (var context = new SuerveyDbContext())
     {
         return(context.Options.SingleOrDefault(s => s.Id == id));
     }
 }
コード例 #10
0
 public ICollection <Option> GetOptionByQuestion(int questionid)
 {
     using (var context = new SuerveyDbContext())
     {
         return(context.Questions.SingleOrDefault(x => x.Id == questionid).Options.ToList());
     }
 }
コード例 #11
0
 public QuestionType Get(int id)
 {
     using (var context = new SuerveyDbContext())
     {
         var result = context.QuetionTypes.SingleOrDefault(qt => qt.Id == id);
         return(result);
     }
 }
コード例 #12
0
 public Question Get(int id)
 {
     using (var context = new SuerveyDbContext())
     {
         var question = (context.Questions.SingleOrDefault(s => s.Id == id && s.IsActive == true));
         return(question);
     }
 }
コード例 #13
0
        public int Add(Option option)
        {
            using (var context = new SuerveyDbContext())
            {
                option.CreatedDate = DateTime.Now;

                context.Options.Add(option);
                context.SaveChanges();

                return(option.Id);
            }
        }
コード例 #14
0
        public int Add(Survey survey)
        {
            using (var context = new SuerveyDbContext())
            {
                survey.CreatedDate = DateTime.Now;
                survey.IsArchived  = false;

                context.Surveys.Add(survey);
                context.SaveChanges();

                return(survey.Id);
            }
        }
コード例 #15
0
        public bool Delete(Option option)
        {
            using (var context = new SuerveyDbContext())
            {
                Option currentoption = context.Options.SingleOrDefault(o => o.Id == option.Id);

                if (currentoption == null)
                {
                    return(false);
                }

                context.Options.Remove(currentoption);
                context.SaveChanges();

                return(true);
            }
        }
コード例 #16
0
        public bool Update(Option option)
        {
            using (var context = new SuerveyDbContext())
            {
                Option oldoption = context.Options.SingleOrDefault(o => o.Id == option.Id);

                if (oldoption == null)
                {
                    return(false);
                }

                oldoption.Text         = option.Text;
                oldoption.ModifiedDate = DateTime.Now;
                context.SaveChanges();

                return(true);
            }
        }
コード例 #17
0
        public bool Delete(Survey survey)
        {
            using (var context = new SuerveyDbContext())
            {
                Survey currentsurvey = context.Surveys.SingleOrDefault(q => q.Id == survey.Id);

                if ((currentsurvey == null) || (currentsurvey.IsArchived = true))
                {
                    return(false);
                }

                currentsurvey.IsArchived   = false;
                currentsurvey.ModifiedDate = (DateTime.Now);
                context.SaveChanges();

                return(true);
            }
        }
コード例 #18
0
        public bool Delete(Question question)
        {
            using (var context = new SuerveyDbContext())
            {
                Question currentquestion = context.Questions.SingleOrDefault(q => q.Id == question.Id);

                if ((currentquestion == null) || (currentquestion.IsActive = false))
                {
                    return(false);
                }

                currentquestion.IsActive     = false;
                currentquestion.ModifiedDate = DateTime.Now;
                context.SaveChanges();

                return(true);
            }
        }
コード例 #19
0
        public bool AddQuestionToSurvey(int surveyid, int questionid)
        {
            using (var context = new SuerveyDbContext())
            {
                var currentsurvey   = context.Surveys.SingleOrDefault(x => x.Id == surveyid);
                var currentquestion = context.Questions.SingleOrDefault(x => x.Id == questionid);

                if (currentsurvey == null || currentquestion == null)
                {
                    return(false);
                }

                currentsurvey.Questions.Add(currentquestion);
                currentquestion.Surveys.Add(currentsurvey);
                context.SaveChanges();

                return(true);
            }
        }
コード例 #20
0
        public bool Update(Survey survey)
        {
            using (var context = new SuerveyDbContext())
            {
                Survey oldsurvey = context.Surveys.SingleOrDefault(s => s.Id == survey.Id);

                if (oldsurvey == null)
                {
                    return(false);
                }

                oldsurvey.Title        = survey.Title;
                oldsurvey.Description  = survey.Description;
                oldsurvey.ModifiedDate = DateTime.Now;
                context.SaveChanges();

                return(true);
            }
        }
コード例 #21
0
        public bool Update(Question question)
        {
            using (var context = new SuerveyDbContext())
            {
                Question oldquestion = context.Questions.SingleOrDefault(q => q.Id == question.Id);

                if (oldquestion == null)
                {
                    return(false);
                }

                oldquestion.Text           = question.Text;
                oldquestion.QuestionTypeId = question.QuestionTypeId;

                switch (question.QuestionTypeId)
                {
                case 1: oldquestion.IsActive = true;
                    break;

                case 2: if (oldquestion.Options.Count() == 2)
                    {
                        oldquestion.IsActive = true;
                    }
                    break;

                case 3: if (oldquestion.Options.Count() == 3)
                    {
                        oldquestion.IsActive = true;
                    }
                    break;

                default:
                    oldquestion.IsActive = false;
                    break;
                }

                oldquestion.ModifiedDate = DateTime.Now;
                context.SaveChanges();

                return(true);
            }
        }
コード例 #22
0
        public int Add(Question question)
        {
            using (var context = new SuerveyDbContext())
            {
                question.CreatedDate = DateTime.Now;
                if (question.QuestionTypeId == 1)
                {
                    question.IsActive = true;
                }
                else
                {
                    question.IsActive = false;
                }


                context.Questions.Add(question);
                context.SaveChanges();

                return(question.Id);
            }
        }
コード例 #23
0
        protected override void Seed(SuerveyDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.

            var optYes = new Option {
                Id = 1, Text = "Yes", CreatedDate = DateTime.Now, ModifiedDate = null
            };
            var optNo = new Option {
                Id = 2, Text = "No", CreatedDate = DateTime.Now, ModifiedDate = null
            };
            var opt1 = new Option {
                Id = 3, Text = "Create, Read, Update, Delete", CreatedDate = DateTime.Now, ModifiedDate = null
            };
            var opt2 = new Option {
                Id = 4, Text = "POST, Read, GET, Delete", CreatedDate = DateTime.Now, ModifiedDate = null
            };
            var opt3 = new Option {
                Id = 5, Text = "SOAP, REST, WSDL, JSON", CreatedDate = DateTime.Now, ModifiedDate = null
            };
            var opt4 = new Option {
                Id = 6, Text = "POST, PUT, GET, UPDATE, DELETE", CreatedDate = DateTime.Now, ModifiedDate = null
            };

            context.Options.AddOrUpdate(optYes, optNo, opt1, opt2, opt3, opt4);

            context.QuetionTypes.AddOrUpdate(
                new QuestionType
            {
                Id           = 1,
                Description  = "Open",
                CreatedDate  = DateTime.Now,
                ModifiedDate = null
            },
                new QuestionType
            {
                Id           = 2,
                Description  = "Dichotomous",
                CreatedDate  = DateTime.Now,
                ModifiedDate = null
            },
                new QuestionType
            {
                Id           = 3,
                Description  = "Multiple",
                CreatedDate  = DateTime.Now,
                ModifiedDate = null
            }
                );

            var question1 = new Question
            {
                Id             = 1,
                Text           = "What is a Web Service?",
                QuestionTypeId = 1,
                IsActive       = true,
                CreatedDate    = DateTime.Now,
                ModifiedDate   = null
            };
            var question2 = new Question
            {
                Id             = 2,
                Text           = "Is SOAP a design patten for Software Development?",
                QuestionTypeId = 2,
                IsActive       = true,
                CreatedDate    = DateTime.Now,
                ModifiedDate   = null
            };

            question2.Options.Add(optYes);
            question2.Options.Add(optNo);

            var question3 = new Question
            {
                Id             = 3,
                Text           = "What are the main Http Methods used by RESTful APIs?",
                QuestionTypeId = 3,
                IsActive       = true,
                CreatedDate    = DateTime.Now,
                ModifiedDate   = null
            };

            question3.Options.Add(opt1);
            question3.Options.Add(opt2);
            question3.Options.Add(opt3);
            question3.Options.Add(opt4);

            context.Questions.AddOrUpdate(question1, question2, question3);

            Survey survey = new Survey
            {
                Id           = 1,
                Title        = ".NET Academy 2018 - Web Service Module",
                Description  = "Evaluate the acquired knowledge during the web service module.",
                IsArchived   = false,
                CreatedDate  = DateTime.Now,
                ModifiedDate = null
            };

            survey.Questions.Add(question1);
            survey.Questions.Add(question2);
            survey.Questions.Add(question3);

            context.Surveys.AddOrUpdate(survey);
        }