public void CreateCharacterPOST(Guid user_id, CharacterVM vm)
        {
            Guid character_id = Guid.NewGuid();
            CreateModelMapper <PrimaryTabVM, CharacterDM> characterMapper = new CreateModelMapper <PrimaryTabVM, CharacterDM>();
            CreateModelMapper <CombatCM, CharacterDM>     combatMapper    = new CreateModelMapper <CombatCM, CharacterDM>();
            CharacterDM character = characterMapper.mapViewModelToDataModel(vm.PrimaryTab);

            if (_commons.raceExists(vm.PrimaryTab.Race) == true)
            {
                character.Race_id = vm.PrimaryTab.Race;
            }
            ;
            combatMapper.mapViewModelToDataModel(vm.PrimaryTab.Combat, character);


            character.Character_id = character_id;
            Health       health = CharacterMapper.mapCombatCMToNewHealthEntity(vm.PrimaryTab.Combat);
            IsProficient skills = mapIsProficient(vm.PrimaryTab.Skills.isProficient);
            CreateModelMapper <SavesCM, IsProficient> mapSaves = new CreateModelMapper <SavesCM, IsProficient>();

            mapSaves.mapViewModelToDataModel(vm.PrimaryTab.Saves, skills);
            Stats    stats = CharacterMapper.mapStatsCMToNewEntity(vm.PrimaryTab.Stats);
            Currency money = CharacterMapper.mapCurrencyCMToNewEntity(vm.InventoryTab.Money);

            character.Character_id = character_id;
            character.User_id      = user_id;
            health.Character_id    = character_id;
            stats.Character_id     = character_id;
            skills.Character_id    = character_id;
            money.Character_id     = character_id;

            _userAccess.AddCharacter(character);
            _userAccess.AddHealthRecord(health);
            _userAccess.AddStatsRecord(stats);
            _userAccess.AddProficiencyRecord(skills);
            _userAccess.AddCurrencyRecord(money);
            LearnSpells(vm.SpellsTab.KnownSpells, character_id);
            SetInventory(vm.InventoryTab.Items, character_id);
            SetNotes(vm.NotesTab.Notes, character_id);
            SetClasses(vm.PrimaryTab.Classes.SelectedClasses, character_id);
            _userAccess.SaveChanges();
        }
        private void LearnSpells(IEnumerable <KnownSpellRowCM> knownSpells, Guid character_id)
        {
            CreateModelMapper <KnownSpellRowCM, Spell_Character> mapper = new CreateModelMapper <KnownSpellRowCM, Spell_Character>();
            List <Guid> alreadyLearned = new List <Guid>();

            foreach (KnownSpellRowCM cm in knownSpells)
            {
                if (_commons.spellExists(cm.Spell_id) && alreadyLearned.Contains(cm.Spell_id) == false)
                {
                    Spell_Character record = mapper.mapViewModelToDataModel(cm);
                    record.Character_id = character_id;
                    _userAccess.CharacterLearnsSpell(record);
                    alreadyLearned.Add(cm.Spell_id);
                }
                else
                {
                    continue;
                }
            }
        }
        private void SetInventory(IEnumerable <HeldItemRowCM> heldItems, Guid Character_id)
        {
            CreateModelMapper <HeldItemRowCM, Character_Item> mapper = new CreateModelMapper <HeldItemRowCM, Character_Item>();
            List <Guid> obtainedItems = new List <Guid>();

            foreach (HeldItemRowCM heldItem in heldItems)
            {
                Guid item_id = heldItem.Item_id;
                if (_commons.itemExists(item_id) && obtainedItems.Contains(item_id) == false)
                {
                    Character_Item record = mapper.mapViewModelToDataModel(heldItem);
                    record.Character_id = Character_id;
                    _userAccess.CharacterObtainsItem(record);
                    obtainedItems.Add(item_id);
                }
                else
                {
                    continue;
                }
            }
        }
        private void SetClasses(IEnumerable <ClassRowCM> selectedClasses, Guid Character_id)
        {
            CreateModelMapper <ClassRowCM, Character_Class_Subclass> mapper = new CreateModelMapper <ClassRowCM, Character_Class_Subclass>();
            List <Guid> alreadyLearnedClasses = new List <Guid>();

            foreach (ClassRowCM cm in selectedClasses)
            {
                //Check if the classes the player selected exist, if the selected sublcass exists, if the player hasn't already selected this class,
                //and if the selected subclass belongs to the selected class.
                if (_commons.playableClassExists(cm.SelectedClass_id) && _commons.subclassExists(cm.SelectedSubclass_id) &&
                    _commons.subclassIsOfClass(cm.SelectedSubclass_id, cm.SelectedClass_id) &&
                    alreadyLearnedClasses.Contains(cm.SelectedClass_id) == false)
                {
                    Character_Class_Subclass record = mapper.mapViewModelToDataModel(cm);
                    record.Character_id = Character_id;
                    alreadyLearnedClasses.Add(record.Class_id);
                    _userAccess.CharacterLearnsClass(record);
                }
                else
                {
                    continue;
                }
            }
        }
        private IsProficient mapIsProficient(IsProficientCM cm)
        {
            CreateModelMapper <IsProficientCM, IsProficient> skillMapper = new CreateModelMapper <IsProficientCM, IsProficient>();

            return(skillMapper.mapViewModelToDataModel(cm));
        }
        public static Note mapNoteCMToNewEntity(NoteCM cm)
        {
            ICreateModelMapper <NoteCM, Note> mapper = new CreateModelMapper <NoteCM, Note>();

            return(mapper.mapViewModelToDataModel(cm));
        }
        public static Currency mapCurrencyCMToNewEntity(MoneyCM cm)
        {
            ICreateModelMapper <MoneyCM, Currency> mapper = new CreateModelMapper <MoneyCM, Currency>();

            return(mapper.mapViewModelToDataModel(cm));
        }
        public static Stats mapStatsCMToNewEntity(StatsCM cm)
        {
            ICreateModelMapper <StatsCM, Stats> mapper = new CreateModelMapper <StatsCM, Stats>();

            return(mapper.mapViewModelToDataModel(cm));
        }
        public static Health mapCombatCMToNewHealthEntity(CombatCM cm)
        {
            ICreateModelMapper <CombatCM, Health> mapper = new CreateModelMapper <CombatCM, Health>();

            return(mapper.mapViewModelToDataModel(cm));
        }
Exemplo n.º 10
0
        //Create
        public static CharacterDM mapCharacterVMToNewEntity(CharacterVM vm)
        {
            ICreateModelMapper <CharacterVM, CharacterDM> mapper = new CreateModelMapper <CharacterVM, CharacterDM>();

            return(mapper.mapViewModelToDataModel(vm));
        }