Exemplo n.º 1
0
        public List <ClassSpell> getclassSpells(string classParam)
        {
            List <DndCharacterclass> classdb;
            CharacterClassQuery      ccq = new CharacterClassQuery();
            SpellQuery        sq         = new SpellQuery();
            List <ClassSpell> result     = new List <ClassSpell>();

            var charaters = getDBClass(classParam);

            foreach (var dd in charaters)
            {
                var classId = dd.Id;
                var scl     = ccq.Query_GetCharacterClassSpellLevel(classId);

                foreach (var classlevel in scl)
                {
                    var        spell = sq.Query_dndSpellByID(classlevel.SpellId).First();
                    ClassSpell cs    = new ClassSpell
                    {
                        ClassId   = dd.Id,
                        ClassName = dd.Name,
                        Level     = classlevel.Level,
                        SpellId   = classlevel.SpellId,
                        SpellName = spell.Name
                    };
                    result.Add(cs);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the primary and sub school for a given spell.
        /// </summary>
        /// <param name="spell">Can be the ID, the slug, or the name of the spell</param>
        /// <returns></returns>
        public List <SpellSchoolSubSchool> getSchools(string spell)
        {
            Console.WriteLine(string.Format("log - SpellQuery - getSchools - PARAMS {0}", spell));
            SpellQuery sq = new SpellQuery();
            List <SpellSchoolSubSchool> result      = new List <SpellSchoolSubSchool>();
            List <DndSpell>             spellResult = null;

            try
            {
                spellResult = getDBSpell(spell);

                if (spellResult != null)
                {
                    Console.WriteLine(string.Format("log - getSchools - getSchools - results {0}", spellResult.Count()));

                    foreach (var s in spellResult)
                    {
                        var primary = sq.Query_dndSpellSchoolByID(s.SchoolId);

                        result.Add(new SpellSchoolSubSchool
                        {
                            SpellId    = s.Id,
                            Spellname  = s.Name,
                            isPrimary  = true,
                            SchoolId   = s.SchoolId,
                            SchoolName = primary[0].Name,
                        });

                        if (s.SubSchoolId != null)
                        {
                            var secondary = sq.Query_dndSpellSchoolByID((long)s.SubSchoolId);
                            result.Add(new SpellSchoolSubSchool
                            {
                                SpellId    = s.Id,
                                Spellname  = s.Name,
                                isPrimary  = false,
                                SchoolId   = s.SubSchoolId,
                                SchoolName = secondary[0].Name,
                            });
                        }
                    }
                }
                ;
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }
Exemplo n.º 3
0
        public List <SpellCL> getClass(string spell)
        {
            Console.WriteLine(string.Format("log - SpellQuery - getClass - PARAMS {0}", spell));
            SpellQuery sq = new SpellQuery();
            List <dnd_dal.DndSpell> spellResult = new List <dnd_dal.DndSpell>();
            List <SpellCL>          data        = new List <SpellCL>();

            try
            {
                spellResult = getDBSpell(spell);

                if (spellResult.Count > 0)
                {
                    Console.WriteLine(string.Format("log - SpellQuery - getClass - results {0}", spellResult.Count()));
                    foreach (var s in spellResult)
                    {
                        var spellID           = s.Id;
                        var scl               = sq.Query_dndSpellClassLevelBySpellId(spellID);
                        var CharacterClassIds = scl.Select(x => x.CharacterClassId).ToList();
                        var final             = sq.Query_dndCharacterClassByIds(CharacterClassIds);

                        foreach (var item in scl)
                        {
                            // create spellCL with the data from the last two gets.
                            data.Add(new SpellCL
                            {
                                SpellId   = s.Id,
                                SpellName = spellResult.First().Name,
                                ClassId   = item.CharacterClassId,
                                ClassName = final.Where(x => x.Id == item.CharacterClassId).First().Name,
                                Level     = item.Level
                            });
                        }
                    }


                    if (data.Count == 0)
                    {
                        return(null);
                    }
                    return(data);
                }
                ;
            }
            catch (Exception)
            {
                throw;
            }

            return(null);
        }
Exemplo n.º 4
0
 public List <SpellDTO> GetSpellBy(SpellQuery query)
 {
     try
     {
         Expression <Func <Spell, bool> > predicate;
         QueryStringService queryHelper = new QueryStringService(query);
         queryHelper.CompoundQuery(out predicate);
         var spellContainer = _spells.FindBy(predicate).ToList();
         return(Mapper.Map <List <SpellDTO> >(spellContainer));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
 public IHttpActionResult Get([FromUri] SpellQuery query)
 {
     try
     {
         query.isNull();
         if (!query.isValid())
         {
             return(BadRequest("Query is not valid. :("));
         }
         return(Ok(_service.GetSpellBy(query)));
     }
     catch (Exception EX_NAME)
     {
         Console.WriteLine(EX_NAME);
         throw;
     }
 }
Exemplo n.º 6
0
        public List <DndSpell> getDBSpell(string spell)
        {
            List <DndSpell> spelldb;
            SpellQuery      sq = new SpellQuery();

            // get the spell #refactor
            if (long.TryParse(spell, out long longId))
            {
                spelldb = sq.Query_dndSpellByID(longId);
            }
            else
            {
                if (HttpUtility.UrlDecode(spell).IndexOf(' ') > 0)
                {
                    spelldb = sq.Query_dndSpellByName(spell);
                }
                else
                {
                    spelldb = sq.Query_dndSpellBySlug(spell);
                }
            }
            return(spelldb);
        }
Exemplo n.º 7
0
        /// <summary>
        ///   Pull a list of "SpellClassLewvels items from the database, which lists all spells by class level.
        /// </summary>
        /// <param name="context">Database Concept</param>
        /// <param name="CasterClass">string value of the character class</param>
        /// <param name="CasterLevel">string value of the character level</param>
        /// <returns>A list of SpellClassLevels </returns>
        public List <SpellCL> getSpellsByClassAndLevel(string CasterClass, string CasterLevel)
        {
            long       level;
            SpellQuery sq = new SpellQuery();

            Console.WriteLine(string.Format("log - SpellQuery - SpellsByClassAndLevel - ByClassAndLevel PARAMS {0} {1}", CasterClass, CasterLevel));

            if (long.TryParse(CasterLevel, out level))
            {
                //Get Class and Level data from the database.
                var            query = sq.Query_SpellsByClassAndLevel(CasterClass, level).ToList();
                List <SpellCL> data  = new List <SpellCL>();

                //Format the data from the query into a DTO and pass.
                foreach (var item in query.ToList())
                {
                    SpellCL i = new SpellCL();
                    i.ClassId   = item.ClassId;
                    i.ClassName = item.ClassName;
                    i.Level     = item.LevelForClass;
                    i.SpellId   = item.SpellId;
                    i.SpellName = item.SpellName;
                    data.Add(i);
                }

                if (query != null)
                {
                    Console.WriteLine(string.Format("log - SpellQuery - SpellsByClassAndLevel - ByClassAndLevel - ByClassAndLevel results {0}", query.Count()));
                    return(data);
                }
                ;
            }

            Console.WriteLine(string.Format("log - SpellQuery - SpellsByClassAndLevel - ByClassAndLevel - Not Spells Found", CasterClass, CasterLevel));
            return(null);
        }
Exemplo n.º 8
0
 public QueryStringService(SpellQuery sq)
 {
     _spellQuery = sq;
 }