Пример #1
0
        public async Task <IActionResult> Create([Bind("Name,Level,StrenghtBase,DexterityBase,ConstitutionBase,IntelligenceBase,WisdomBase,CharismaBase, characterClassId, characterRaceId")] Character character)
        {
            if (ModelState.IsValid)
            {
                _context.Add(character);

                await _context.SaveChangesAsync();

                Character _character = await _charService.LoadCharacter(character.Id);

                ChoiceViewModel choiceViewModel = new ChoiceViewModel();

                choiceViewModel.Choices = await GetChoices(character);

                choiceViewModel.Character = _character;

                if (choiceViewModel.Choices.Count == 0)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else if (choiceViewModel.Choices.Count != 0)
                {
                    return(View("Choices", choiceViewModel));
                }
            }



            return(View(character));
        }
Пример #2
0
 public static Choice Map(ChoiceViewModel viewModel) => new Choice
 {
     ChoiceId     = viewModel.ChoiceId,
     QuestionId   = viewModel.QuestionId,
     Correct      = viewModel.Correct,
     ChoiceString = viewModel.ChoiceString
 };
Пример #3
0
 public void AddNewItem()
 {
   var newItem = new ChoiceViewModel();
   Selections.Add(newItem);
   newItem.PropertyChanged += () => 
    {
      //This is where we update the model from the ViewModel
      Model.Selections = from x in Selections
        select x.Value;
    }
  }
Пример #4
0
        public void UpdateRaceChoices()
        {
            List <ChoiceViewModel> choices = new List <ChoiceViewModel>
            {
                new RaceChoice(this)
            };
            List <String> parentraces = new List <string>();

            foreach (Feature f in Context.Player.GetFeatures().Where(f => f is SubRaceFeature))
            {
                parentraces.AddRange(((SubRaceFeature)f).Races);
            }
            if (parentraces.Count > 0)
            {
                choices.Add(new SubRaceChoice(this, parentraces));
            }
            foreach (Feature f in Context.Player.GetRaceFeatures())
            {
                ChoiceViewModel c = ChoiceViewModel <Feature> .GetChoice(this, f);

                if (c != null)
                {
                    choices.Add(c);
                }
            }
            if (Context.Player.Race != null)
            {
                foreach (Description d in Context.Player.Race.Descriptions)
                {
                    if (d is TableDescription td && td.Amount > 0)
                    {
                        choices.Add(new DescriptionChoice(this, td, Navigation));
                    }
                }
            }
            if (Context.Player.SubRace != null)
            {
                foreach (Description d in Context.Player.SubRace.Descriptions)
                {
                    if (d is TableDescription td && td.Amount > 0)
                    {
                        choices.Add(new DescriptionChoice(this, td, Navigation));
                    }
                }
            }
            RaceChoices.ReplaceRange(choices);
        }
Пример #5
0
        public void UpdateClassChoices()
        {
            int level = Context.Player.GetLevel();
            List <ChoiceViewModel> choices = new List <ChoiceViewModel>();
            int nextlevel = 1;

            foreach (ClassInfo ci in Context.Player.GetClassInfos(level))
            {
                if (ci == null || ci.Class == null || ci.Level > level)
                {
                    break;
                }
                nextlevel = ci.Level + 1;
                choices.Add(new ClassChoice(this, ci.Level));
                choices.Add(new ClassHPChoice(this, ci.Level, ci.Class.HitDieCount * Math.Max(1, ci.Class.HitDie)));
            }
            if (nextlevel <= level)
            {
                choices.Add(new ClassChoice(this, nextlevel));
            }
            choices.AddRange(from Feature f in Context.Player.GetFeatures(level) where f is SubClassFeature select new SubClassChoice(this, (SubClassFeature)f));

            foreach (Feature f in Context.Player.GetClassFeatures(level))
            {
                ChoiceViewModel c = ChoiceViewModel <Feature> .GetChoice(this, f);

                if (c != null)
                {
                    choices.Add(c);
                }
            }
            foreach (PlayerClass pc in Context.Player.Classes)
            {
                foreach (TableDescription d in pc.CollectTables(Context))
                {
                    if (d.Amount > 0)
                    {
                        choices.Add(new DescriptionChoice(this, d, Navigation));
                    }
                }
            }
            ClassChoices.ReplaceRange(choices);
        }
Пример #6
0
        public void UpdateInventoryChoices()
        {
            List <ChoiceViewModel> choices = new List <ChoiceViewModel>();

            foreach (Feature f in Context.Player.GetPossessionFeatures())
            {
                ChoiceViewModel c = ChoiceViewModel <Feature> .GetChoice(this, f);

                if (c != null)
                {
                    choices.Add(c);
                }
            }
            foreach (Feature f in Context.Player.GetBoons())
            {
                ChoiceViewModel c = ChoiceViewModel <Feature> .GetChoice(this, f);

                if (c != null)
                {
                    choices.Add(c);
                }
            }
            InventoryChoices.ReplaceRange(choices);
        }
Пример #7
0
        public void UpdateRaceChoices()
        {
            List <ChoiceViewModel> choices = new List <ChoiceViewModel>
            {
                new BackgroundChoice(this)
            };

            foreach (Feature f in Context.Player.GetOnlyBackgroundFeatures())
            {
                ChoiceViewModel c = ChoiceViewModel <Feature> .GetChoice(this, f);

                if (c != null)
                {
                    choices.Add(c);
                }
            }
            Background back = Context.Player.Background;
            List <TableDescription> tables = Context.Player.CollectTables();

            List <TableEntry> traits = new List <TableEntry>();

            if (back != null)
            {
                traits.AddRange(back.PersonalityTrait.ToArray <TableEntry>());
            }
            foreach (TableDescription td in tables)
            {
                if (td.BackgroundOption.HasFlag(BackgroundOption.Trait))
                {
                    traits.AddRange(td.Entries.ToArray <TableEntry>());
                }
            }
            choices.Add(new PersonalityTraitChoice(this, traits));

            List <TableEntry> ideals = new List <TableEntry>();

            if (back != null)
            {
                ideals.AddRange(back.Ideal.ToArray <TableEntry>());
            }
            foreach (TableDescription td in tables)
            {
                if (td.BackgroundOption.HasFlag(BackgroundOption.Ideal))
                {
                    ideals.AddRange(td.Entries.ToArray <TableEntry>());
                }
            }
            choices.Add(new IdealChoice(this, ideals));

            List <TableEntry> bonds = new List <TableEntry>();

            if (back != null)
            {
                bonds.AddRange(back.Bond.ToArray <TableEntry>());
            }
            foreach (TableDescription td in tables)
            {
                if (td.BackgroundOption.HasFlag(BackgroundOption.Bond))
                {
                    bonds.AddRange(td.Entries.ToArray <TableEntry>());
                }
            }
            choices.Add(new BondChoice(this, bonds));

            List <TableEntry> flaws = new List <TableEntry>();

            if (back != null)
            {
                flaws.AddRange(back.Flaw.ToArray <TableEntry>());
            }
            foreach (TableDescription td in tables)
            {
                if (td.BackgroundOption.HasFlag(BackgroundOption.Flaw))
                {
                    flaws.AddRange(td.Entries.ToArray <TableEntry>());
                }
            }
            choices.Add(new FlawChoice(this, flaws));

            foreach (TableDescription td in tables)
            {
                if (td.Amount > 0)
                {
                    choices.Add(new DescriptionChoice(this, td, Navigation));
                }
            }
            BackgroundChoices.ReplaceRange(choices);
        }
Пример #8
0
        protected void lnkAddMoreOptions_Click(object sender, EventArgs e)
        {
            var options = ViewState["Options" + hidPageKey.Value] as
                          List <ChoiceViewModel>;

            if (options != null)
            {
                var min = -3;
                var pos = 0;
                try
                {
                    min = options.Min(x => x.Id);
                    if (min >= 0)
                    {
                        min = -1;
                    }
                }

                catch { }
                try
                {
                    pos = options.Max(x => x.Position);
                }
                catch { }

                var count = Convert.ToInt32(hidCountOfOptions.Value);
                //count;
                //var uc = (ChoiceOptionsCreate)Page.LoadControl
                //    ("~/Views/ActivityResource/Choice/ChoiceOptionsCreate.ascx");
                //uc.SetValues("Option" + count, "Limit" + count, ddlLimitTheNumberOfResponses.SelectedIndex == 1);
                //uc.SetValues(ChoiceId, min - 1, "Option" + count, "Limit" + count, "", 0, ddlLimitTheNumberOfResponses.SelectedIndex == 1);



                //uc.SetValues("Option","Limit",true);

                //uc.RemoveClicked += uc_RemoveClicked;
                hidCountOfOptions.Value = (count + 1).ToString();

                //Option = "",Limit = 0,Id = -2,Position=2
                //    ,OptionName = "Option2", LimitName = "Limit2"
                //    ,Visible=true
                var o = new ChoiceViewModel()
                {
                    //ChoiceActivityId = ChoiceId
                    //,
                    Limit = 0
                    ,
                    Option = ""
                    ,
                    Id = min - 1
                    ,
                    LimitName = "Limit" + (count + 1)
                    ,
                    OptionName = "Option" + (count + 1)
                    ,
                    Position = pos + 1
                    ,
                    Visible = true
                };
                options.Add(o);

                var uc = (ChoiceOptionsCreate)Page.LoadControl
                             ("~/Views/ActivityResource/Choice/ChoiceOptionsCreate.ascx");
                //uc.SetValues("Option" + i, "Limit" + i, ddlLimitTheNumberOfResponses.SelectedIndex == 1);
                uc.SetValues(ChoiceId, o.Id, o.OptionName, o.LimitName, o.Option, o.Limit ?? 0
                             , ddlLimitTheNumberOfResponses.SelectedIndex == 1);
                uc.ID                     = "optionuc" + o.Id;
                uc.Position               = o.Position;
                uc.Visible                = o.Visible;
                uc.RemoveClicked         += uc_RemoveClicked;
                uc.RemoveButtonVisibility = true;
                uc.PageKey                = hidPageKey.Value;
                pnlOptions.Controls.Add(uc);

                //uc.SetValues(o.ChoiceActivityId, o.optionId, o.OptionName + (count + 1)
                //    , "Limit" + (count + 1), "", 0
                //    , ddlLimitTheNumberOfResponses.SelectedIndex == 1);
            }
        }
Пример #9
0
        //creates an universal choice view model for all available options. This model is then returned to the view.
        public ChoiceViewModel CreateChoiceViewModelFromDB(Choice choice)
        {
            ChoiceViewModel returnChoiceViewModel = new ChoiceViewModel();

            returnChoiceViewModel.AllowedNumberOfChoices = choice.AllowedOptions;

            List <Option> availableOptions = _context.Options.Where(o => o.FK_Choice == choice.Id).ToList();

            //Seperates the choice by type to the proper tables can be referenced.
            ChoiceType _choiceType;

            Enum.TryParse(choice.Descriminator, out _choiceType);
            returnChoiceViewModel.Descriminator = _choiceType;

            //retreives info from the right table. Cases refer to eachother with goto to prevent duplicate code.
            switch (_choiceType)
            {
            case ChoiceType.RacialLanguage:
                goto case ChoiceType.RacialProficiency;

            case ChoiceType.RacialProficiency:
                returnChoiceViewModel.Description = _context.RaceFeatureChoices.Where(c => c.FK_Choice == choice.Id).Select(c => c.RaceFeature).FirstOrDefault().Description;

                returnChoiceViewModel.Name = _context.RaceFeatureChoices.Where(c => c.FK_Choice == choice.Id).Select(c => c.RaceFeature).FirstOrDefault().Name;
                break;

            case ChoiceType.AbilityScoreImprovement:
                goto case ChoiceType.ClassFeature;

            case ChoiceType.ClassSkillChoice:
                goto case ChoiceType.ClassFeature;

            case ChoiceType.ClassFeature:
                returnChoiceViewModel.Description = _context.FeatureChoices.Where(c => c.FK_Choice == choice.Id).Select(c => c.Feature).FirstOrDefault().Description;

                returnChoiceViewModel.Name = _context.FeatureChoices.Where(c => c.FK_Choice == choice.Id).Select(c => c.Feature).FirstOrDefault().Name;
                break;

            case ChoiceType.SubClass:
                returnChoiceViewModel.Description = _context.FeatureChoices.Where(c => c.FK_Choice == choice.Id).Select(c => c.Feature).FirstOrDefault().Description;

                returnChoiceViewModel.Name = _context.FeatureChoices.Where(c => c.FK_Choice == choice.Id).Select(c => c.Feature).FirstOrDefault().Name;

                Feature feature = _context.FeatureChoices.Where(c => c.FK_Choice == choice.Id).Select(c => c.Feature).FirstOrDefault();

                Class _class = _context.ClassFeatures.Where(cf => cf.FK_Feature == feature.Id).Select(cf => cf.Class).FirstOrDefault();

                returnChoiceViewModel.OptionNames = _context.SubClasses.Where(sc => sc.FK_Class == _class.Id).Select(c => c.Name).ToList();

                returnChoiceViewModel.OptionNames = _context.SubClasses.Where(sc => sc.FK_Class == _class.Id).Select(c => c.Name).ToList();

                returnChoiceViewModel.OptionDescriptions = _context.SubClasses.Where(sc => sc.FK_Class == _class.Id).Select(c => c.Description).ToList();

                foreach (var option in returnChoiceViewModel.OptionNames)
                {
                    returnChoiceViewModel.FreeOptions.Add(false);
                }

                returnChoiceViewModel.OptionIds = _context.SubClasses.Where(sc => sc.FK_Class == _class.Id).Select(c => c.Id).ToList();

                return(returnChoiceViewModel);

            default:
                //insert logging here.
                break;
            }


            returnChoiceViewModel.OptionNames        = availableOptions.Select(i => i.Name).ToList();
            returnChoiceViewModel.OptionDescriptions = availableOptions.Select(i => i.Description).ToList();

            for (int i = 0; i < availableOptions.Count; i++)
            {
                if (availableOptions[i].free)
                {
                    returnChoiceViewModel.FreeOptions.Add(true);
                }
                else
                {
                    returnChoiceViewModel.FreeOptions.Add(false);
                }

                if (availableOptions[i].Name != null)
                {
                    returnChoiceViewModel.OptionNames[i] = availableOptions[i].Name;
                }
                if (availableOptions[i].Description != null)
                {
                    returnChoiceViewModel.OptionDescriptions[i] = availableOptions[i].Description;
                }

                returnChoiceViewModel.OptionIds = _context.Options.Where(c => c.FK_Choice == choice.Id).Select(c => c.Id).ToList();
            }



            return(returnChoiceViewModel);
        }
Пример #10
0
 public Choice()
 {
     InitializeComponent();
     DataContext = new ChoiceViewModel();
 }
Пример #11
0
        public QCAViewModel Map(QCA QCA)
        {
            QCAViewModel QCAViewModel = new QCAViewModel();

            QCAViewModel.QuestionViewModel = _questionMapper.Map(QCA.Question);
            QCAViewModel.AnswersViewModel  = new List <AnswerViewModel>();
            string ChoiceType = QCA.Question.ChoiceType;

            if (ChoiceType == "R")
            {
                if (!QCA.Answers.Any())
                {
                    AnswerViewModel AVM = new AnswerViewModel {
                        AnswerId = Guid.NewGuid(), QuestionId = QCA.Question.QuestionId
                    };
                    QCAViewModel.AnswersViewModel.Add(AVM);
                }
                else
                {
                    foreach (var Answer in QCA.Answers)
                    {
                        QCAViewModel.AnswersViewModel.Add(_answerMapper.Map(Answer));
                    }
                }
                QCAViewModel.AnswersViewModel.First().ChoicesViewModel = new List <ChoiceViewModel>();
                foreach (var Choice in QCA.Choices)
                {
                    QCAViewModel.AnswersViewModel.First().ChoicesViewModel.Add(_choiceMapper.Map(Choice));
                }
                QCAViewModel.AnswersViewModel.ForEach(x => x.IsSelected = true);
                QCAViewModel.AnswersViewModel.ForEach(x => x.ChoiceType = "R");
            }

            if (ChoiceType == "C")
            {
                foreach (var Choice in QCA.Choices)
                {
                    AnswerViewModel AVM = new AnswerViewModel();

                    foreach (var Answer in QCA.Answers)
                    {
                        if (Answer.ChoiceId == Choice.ChoiceId)
                        {
                            AVM.AnswerId      = Answer.AnswerId;
                            AVM.AnswerContent = Answer.AnswerContent;
                            AVM.ChoiceId      = Answer.ChoiceId;
                            AVM.IsSelected    = true;
                        }
                    }

                    if (string.IsNullOrEmpty(AVM.AnswerContent))
                    {
                        AVM.AnswerId      = Guid.NewGuid();
                        AVM.AnswerContent = Choice.ChoiceContent;
                        AVM.ChoiceId      = Choice.ChoiceId;
                        AVM.IsSelected    = false;
                    }

                    //Add QuestionId to AnswerViewModel

                    AVM.QuestionId = Choice.QuestionId;

                    //Add Choice type to AnswerViewModel
                    AVM.ChoiceType = "C";

                    //Add ChoicesViewModel to the AnswerViewModel (Should only be one ChoiceViewModel for each AnswerViewModel with "CheckBox"
                    AVM.ChoicesViewModel = new List <ChoiceViewModel>();
                    ChoiceViewModel CVM = new ChoiceViewModel();
                    CVM.ChoiceId      = Choice.ChoiceId;
                    CVM.ChoiceContent = Choice.ChoiceContent;
                    AVM.ChoicesViewModel.Add(CVM);


                    QCAViewModel.AnswersViewModel.Add(AVM);
                }
            }
            if (ChoiceType == "F")
            {
                if (!QCA.Answers.Any())
                {
                    AnswerViewModel AVM = new AnswerViewModel();
                    AVM.AnswerId   = Guid.NewGuid();
                    AVM.QuestionId = QCA.Question.QuestionId;
                    QCAViewModel.AnswersViewModel.Add(AVM);
                }
                else
                {
                    foreach (var Answer in QCA.Answers)
                    {
                        AnswerViewModel AVM = new AnswerViewModel();
                        AVM.AnswerId      = Answer.AnswerId;
                        AVM.QuestionId    = Answer.QuestionId;
                        AVM.AnswerContent = Answer.AnswerContent;
                        QCAViewModel.AnswersViewModel.Add(AVM);
                    }
                }
                QCAViewModel.AnswersViewModel.ForEach(x => x.IsSelected = true);
                QCAViewModel.AnswersViewModel.ForEach(x => x.ChoiceType = "F");
                QCAViewModel.AnswersViewModel.ForEach(x => x.ChoiceId   = QCA.Choices.First().ChoiceId);
            }

            return(QCAViewModel);
        }