Esempio n. 1
0
        private void ExecuteSaveCurrentQuestion()
        {
            using (var sql = new SampleTravelersContext())
            {
                var p = new Question();
                if (sql.Questions.Any(x => x.Name == Name))
                {
                    p = sql.Questions.Where(x => x.Name == this.Name).First();
                }
                else
                {
                    sql.Questions.Add(p);
                }
                foreach (var item in PrerequisiteQuestions)
                {
                    var i = sql.Questions.Where(x => x.Id == item.Id).First();
                    p.AddPrerequisite(i);
                }
                foreach (var item in CorequisiteQuestions)
                {
                    p.Corequisites.Add(sql.Questions.Where(x => x.Id == item.Id).First());
                }
                foreach (var item in PostrequisiteQuestions)
                {
                    var i = sql.Questions.Where(x => x.Id == item.Id).First();
                    p.AddPostrequisite(i);
                }

                p.Name             = this.Name;
                p.Request          = this.Request;
                p.RequiresResponse = this.IsRequired;
                p.Template         = this.IsTemplate;
                p.Type             = (int)this.CurrentResponseType;
                p.Team             = (int)this.CurrentTeam;
                p.HelpText         = this.HelpText;
                //p.HelpImage = this.HelpImage;

                var saved = true;
                try
                {
                    sql.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    saved = false;
                    System.Windows.MessageBox.Show(SampleTravelersContext.AlertUserErrors(e));
                }
                finally
                {
                    if (saved)
                    {
                        OnSuccessfulSave(this, null);
                    }
                }
            }
        }