/// <summary>
        /// Checks if the description of the skill exists
        /// </summary>
        protected SkillEffectName checkIfSkillNameExists(string name, string heroName, string skillName)
        {
            SkillEffectName skillEffectName = new SkillEffectName();
            using (Dota2Entities ctx = new Dota2Entities())
            {
                //get SkillId
                SkillCreator.SelectByName(skillName)

                if (skill != null)
                {
                    try
                    {
                        if (ctx.SkillEffectName.Any(x =>
                                                    x.Name == name &&
                                                    x.Skill.Hero.Name == heroName))
                        {
                            Console.WriteLine("Skill " + name + " Already exists...");
                            return true;
                        }
                        else
                        {
                            return null;
                        }
                    }
                    catch (Exception e)
                    {
                        //TODO implementar log de erro
                        throw e;
                    }
                }

            }
        }
        public SkillEffectName insertSkillEffectName(string name, string heroName, string skillName, 
            List<string> skillEffectValues, string skillDescription)
        {
            SkillEffectName skillEffectName = new SkillEffectName();

            Skill skill = SkillCreator.SelectByName(skillName);

            skillEffectName.Name = name.Trim();

            

            skillEffectName = checkIfSkillNameExists(name, skill, skillDescription);

            if (skillEffectName == null)
            {
                using (Dota2Entities ctx = new Dota2Entities())
                {
                    try
                    {
                        skillEffectName = ctx.SkillEffectName.Add(skillEffectName);
                        ctx.SaveChanges();
                        Console.WriteLine("Skill " + name + " Created");
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
            return skillEffectName;
        }
        public AttributesCreator(int heroId, Dictionary<string, string> primaryStats)
        {
            attribute = new Attributes();
            attribute.HeroId = heroId;
            attribute.Intelligence = primaryStats["Intelligence"];
            attribute.Agility = primaryStats["Agility"];
            attribute.Strength = primaryStats["Strength"];
            attribute.Damage = primaryStats["Damage"];
            attribute.MoveSpeed = primaryStats["Movespeed"];
            attribute.Armor = primaryStats["Armor"];

            using (Dota2Entities ctx = new Dota2Entities())
            {
                try
                {
                    ctx.Attributes.Add(this.attribute);

                    ctx.SaveChanges();
                    Console.WriteLine("Primary Stats Created ");
                }
                catch (Exception e)
                {
                    //TODO Adicionar ao log
                    throw e;
                }
            }
        }
        public SkillImage InsertSkillImage(int skillId, string imageUrl)
        {
            SkillImage skillImage = new SkillImage();

            try
            {
                using (Dota2Entities ctx = new Dota2Entities())
                {
                    //Check if the image exists
                    if (!ctx.SkillImage.Any(si => si.Url == imageUrl))
                    {
                        skillImage.SkillId = skillId;
                        skillImage.Url = imageUrl;

                        ctx.SkillImage.Add(skillImage);
                        ctx.SaveChanges();
                    }
                    else
                    {
                        skillImage = ctx.SkillImage.Where(si => si.Url == imageUrl).FirstOrDefault();
                        Console.WriteLine("SkillImage Already exists");                        
                    }
                }
            }
            catch (Exception)
            {
                //TODO implementar log
                throw;
            }

            return skillImage;
        }
        /// <summary>
        /// Checks if the description of the skill exists
        /// </summary>
        protected SkillEffectName checkIfSkillNameExists(string name, Skill skill, string skillDescription)
        {
            SkillEffectName skillEffectName = new SkillEffectName();
            using (Dota2Entities ctx = new Dota2Entities())
            {
                try
                {
                    ctx.Configuration.LazyLoadingEnabled = true;

                    if(ctx.SkillEffectName.Any(s => s.Name == name))
                    {
                    skillEffectName = ctx.SkillEffectName.Where(x =>
                                                                x.Name == name).First();


                    skillEffectName = ctx.SkillEffectName.Where(x =>
                                                                x.Name == name &&
                                                                x.Skill.Hero.Name == skill.Hero.Name &&
                                                                skillDescription == skill.Description).First();
                    
                        Console.WriteLine("Skill " + name + " Already exists...");
                        return skillEffectName;
                    }
                    else
                    {
                        return null;   
                    }
                }
                catch (Exception e)
                {
                    //TODO implementar log de erro
                    throw e;
                }                
            }
        }
        public Hero createHero(string heroName, string biography)
        {
            this.hero = new Hero();

            this.hero.Name = heroName;
            this.hero.Biography = biography;

            using (Dota2Entities ctx = new Dota2Entities())
            {
                try
                {
                    ctx.Hero.Add(this.hero);

                    ctx.SaveChanges();
                    Console.WriteLine("*************************** " + heroName + " Created(Hero)" + "***************************");
                }
                catch (Exception e)
                {
                    //TODO Adicionar ao log
                    throw e;
                }
            }

            return this.hero;
        }
        public SkillEffectName InsertSkillEffectName(string name, string heroName, Skill skill, List<string> skillEffectValues)
        {
            SkillEffectName skillEffectName;            

            Skill completeSkill = SkillCreator.SelectByName(skill.Name);            

            bool exists = checkIfSkillNameExists(name, completeSkill, completeSkill.Description, out skillEffectName);

            if (!exists)
            {
                skillEffectName.Name = name.Trim();
                skillEffectName.SkillId = completeSkill.ID;
                skillEffectName.ValueLv1 = int.Parse(skillEffectValues.First());
                skillEffectName.ValueLv2 = int.Parse(skillEffectValues.ElementAt(1));
                skillEffectName.ValueLv3 = int.Parse(skillEffectValues.ElementAt(2));
                skillEffectName.ValueLv4 = int.Parse(skillEffectValues.ElementAt(3));
                skillEffectName.ValueScepter = int.Parse(skillEffectValues.Last());            

                using (Dota2Entities ctx = new Dota2Entities())
                {
                    try
                    {
                        skillEffectName = ctx.SkillEffectName.Add(skillEffectName);
                        ctx.SaveChanges();
                        Console.WriteLine("Skill " + name + " Created");
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
            return skillEffectName;
        }
 /// <summary>
 /// Checks if the description of the skill exists
 /// </summary>
 protected SkillEffectName checkIfSkillNameExists(string name, string heroName, string skillId)
 {
     SkillEffectName skillEffectName = new SkillEffectName();
     using(Dota2Entities ctx = new Dota2Entities())
     {
         //get SkillId
         
         
         //if (skill != null)
         //{
         //    try
         //    {
         //        if (ctx.SkillEffectName.Any(x =>
         //                                    x.Name == name &&
         //                                    x.Skill.Hero.Name == heroName))
         //        {
         //            Console.WriteLine("Skill " + name + " Already exists...");
         //            return true;
         //        }
         //        else
         //        {
         //            return null;
         //        }
         //    }
         //    catch (Exception e)
         //    {
         //        //TODO implementar log de erro
         //        throw e;
         //    }
         //}
         
     }
 }
        public HeroPortrait InsertHeroPortrait(int heroId, string imageUrl)
        {
            HeroPortrait HeroPortrait = new HeroPortrait();

            try
            {
                using (Dota2Entities ctx = new Dota2Entities())
                {
                    //Check if the image exists
                    if (!ctx.HeroPortrait.Any(si => si.Url == imageUrl))
                    {
                        HeroPortrait.HeroId = heroId;
                        HeroPortrait.Url = imageUrl;

                        ctx.HeroPortrait.Add(HeroPortrait);
                        ctx.SaveChanges();
                        Console.WriteLine("Image " + HeroPortrait.Url + " Added");
                    }
                    else
                    {
                        HeroPortrait = ctx.HeroPortrait.Where(si => si.Url == imageUrl).FirstOrDefault();
                        Console.WriteLine("HeroPortrait Already exists");
                    }
                }
            }
            catch (Exception)
            {
                //TODO implementar log
                throw;
            }

            return HeroPortrait;
        }
        public Hero createHero(string name, List<string> primaryStats, string biography)
        {
            this.hero = new Hero();

            this.hero.Name = name;
            this.hero.Biography = biography;

            using (Dota2Entities ctx = new Dota2Entities())
            {
                try
                { 
                    ctx.Hero.Add(this.hero);

                    ctx.SaveChanges();
                }
                catch(Exception e)
                {
                    //TODO Adicionar ao log
                    throw e.Message;
                }


            return this.hero;
        }
        
    }
 /// <summary>
 /// Checks if the description of the skill exists
 /// </summary>
 protected SkillEffectName checkIfSkillNameExists(string name, Skill skill, string skillDescription)
 {
     SkillEffectName skillEffectName = new SkillEffectName();
     using (Dota2Entities ctx = new Dota2Entities())
     {
         try
         {
             skillEffectName = ctx.SkillEffectName.Where(x =>
                                                         x.Name == name &&
                                                         x.Skill.Hero.Name == skill.Hero.Name &&
                                                         skillDescription == skill.Description).First();
             if(skillEffectName.ID != null)
             {
                 Console.WriteLine("Skill " + name + " Already exists...");
                 return skillEffectName;
             }
             else
             {
                 return null;   
             }
         }
         catch (Exception e)
         {
             //TODO implementar log de erro
             throw e;
         }                
     }
 }
        public SkillAbilityTypes insert(int skillId, int abilityTypeId, out bool success)
        {
            skillAbilityType = new SkillAbilityTypes();

            using (Dota2Entities ctx = new Dota2Entities())
            {
                try
                {
                    skillAbilityType.SkillId = skillId;
                    skillAbilityType.AbilityTypeId = abilityTypeId;

                    ctx.SkillAbilityTypes.Add(skillAbilityType);

                    ctx.SaveChanges();
                    success = true;
                }
                catch (Exception e)
                {
                    success = false;
                    throw e;
                }
            }            

            return skillAbilityType;
        }
        /// <summary>
        /// Checks if the description of the skill exists, in negative case call the insertSkillDesc
        /// </summary>
        public SkillEffectName checkIfSkillNameExists(string name)
        {
            SkillEffectName skillEffectName = new SkillEffectName();
            using(Dota2Entities ctx = new Dota2Entities())
            {
                try
                {
                    if (ctx.SkillEffectName.Any(x => x.Name == name))
                    {
                        Console.WriteLine("Skill " + name + " Already exists...");
                    }
                    else
                    {
                        skillEffectName = insertSkillEffectName(name);
                    }
                }
                catch (Exception e)
                {
                    //TODO implementar log de erro
                    throw e;
                }
            }

            return skillEffectName;
        }
        void setAbilityCastType(string abilityCastTypeString)
        {
            using(Dota2Entities ctx = new Dota2Entities())
            {
                var abilityType = (from e in ctx.AbilityType
                                       where e.Name == abilityCastTypeString);

            }
        }
Ejemplo n.º 15
0
        public Hero getHeroByName(string heroName)
        {
            Hero hero = new Hero();
            using (Dota2Entities ctx = new Dota2Entities())
            {
                hero = ctx.Hero.Where(h => h.Name == heroName).FirstOrDefault();
            }

            return hero;
        }
        void setAbilityCastType(string abilityCastTypeString)
        {
            AbilityType abilityType = new AbilityType();
            using(Dota2Entities ctx = new Dota2Entities())
            {
                var abType = (from p in ctx.AbilityType
                             where p.Name == abilityCastTypeString                             
                             select p);
                

            }
        }
        void setAbilityCastType(string abilityCastTypeString)
        {
            AbilityType abilityType = new AbilityType();
            using(Dota2Entities ctx = new Dota2Entities())
            {
                var abilityTp = (from p in ctx.AbilityType
                             where p.Name == abilityCastTypeString                             
                             select p).FirstOrDefault();

                abilityType = abilityTp;
            }
        }
        void setAbilityCastType(string abilityCastTypeString)
        {
            using(Dota2Entities ctx = new Dota2Entities())
            {
                var abilityType = (from p in contextDb.PassBook
                             where p.Locator == passBook.Locator
                             where p.PassagerName == passBook.PassagerName
                             where p.FlightData == passBook.FlightData
                             where p.FlightNumber == passBook.FlightNumber
                             where p.DepartureAirportName == passBook.DepartureAirportName
                             select p).FirstOrDefault();

            }
        }
        public SkillAbilityTypes insert(int skillId, int abilityTypeId, Dota2Entities ctx)
        {
            SkillAbilityTypes skillAbilityType = new SkillAbilityTypes();
            try
            {
                
                skillAbilityType.SkillId = skillId;
                skillAbilityType.AbilityTypeId = abilityTypeId;

                ctx.SkillAbilityTypes.Add(skillAbilityType);
            }
            catch (Exception e)
            {   
                throw e;
            }

            return skillAbilityType;
        }
        void setAbilityCastType(string abilityCastTypeString)
        {
            AbilityType abilityType = new AbilityType();
            using(Dota2Entities ctx = new Dota2Entities())
            {
                var abilityTp = (from p in ctx.AbilityType
                             where p.Name == abilityCastTypeString
                             select p).FirstOrDefault();

                abilityType = abilityTp;
            }

            if (abilityType != null)
                this.skill.AbilityType = abilityType;
            else
            {
                //TODO Incluir este erro no log posteriormente
                throw new Exception("No AbilityType has been returned. AbilityType: " + abilityCastTypeString);
            }            
        }
        public SkillEffectName InsertSkillEffectName(string name, string heroName, Skill skill, List<string> skillEffectValues)
        {
            HeroCreator heroCreator = new HeroCreator();
            SkillEffectName skillEffectName;
            Hero hero = heroCreator.getHeroByName(heroName);

            Skill completeSkill = SkillCreator.SelectSkill(skill.Name, hero.ID);            

            bool exists = checkIfSkillNameExists(name, completeSkill, completeSkill.Description, out skillEffectName);

            if (!exists)
            {
                skillEffectName.Name = name.Trim();
                skillEffectName.SkillId = completeSkill.ID;
                if (skillEffectValues.FirstOrDefault() != null)
                    skillEffectName.ValueLv1 = skillEffectValues.First();
                if (skillEffectValues.ElementAtOrDefault(1) != null)
                    skillEffectName.ValueLv2 = skillEffectValues.ElementAt(1);
                if (skillEffectValues.ElementAtOrDefault(2) != null)
                    skillEffectName.ValueLv3 = skillEffectValues.ElementAt(2);
                if (skillEffectValues.ElementAtOrDefault(3) != null)
                    skillEffectName.ValueLv4 = skillEffectValues. ElementAt(3);
                if (skillEffectValues.LastOrDefault() != null)
                    skillEffectName.ValueScepter = skillEffectValues.Last();            

                using (Dota2Entities ctx = new Dota2Entities())
                {
                    try
                    {
                        skillEffectName = ctx.SkillEffectName.Add(skillEffectName);
                        ctx.SaveChanges();
                        Console.WriteLine("Skill " + name + " Created");
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
            return skillEffectName;
        }
        /// <summary>
        /// Checks if the description of the skill exists
        /// </summary>
        protected bool checkIfSkillNameExists(string name, Skill skill, string skillDescription, out SkillEffectName skillEffectName)
        {
            using (Dota2Entities ctx = new Dota2Entities())
            {
                skillEffectName = new SkillEffectName();

                try
                {
                    skill = ctx.Skill.Include("Hero").Where(x => x.ID == skill.ID).First();

                    var result = from s in ctx.SkillEffectName
                                 where s.Name == name
                                    && s.SkillId == skill.ID
                                    && s.Skill.Hero.Name == skill.Hero.Name
                                    && s.Skill.Description == skill.Description
                                 select s;

                    if (result.Count() == 1)
                    {
                        Console.WriteLine(result.First().ID +  " Skill " + name + " Already exists..." );
                        skillEffectName = result.First();
                        return true;
                    }
                    else if (result.Count() > 1)
                    {
                        //TODO Create log
                        throw new Exception("More than 1 skillEffectname returned. Check this");
                    }
                    else
                    {
                        return false;
                    }
                }
                catch (Exception e)
                {
                    //TODO implementar log de erro
                    throw e;
                }                
            }
        }
        /// <summary>
        /// Checks if the description of the skill exists
        /// </summary>
        protected SkillEffectName checkIfSkillNameExists(string name, Skill skill, string skillDescription)
        {
            SkillEffectName skillEffectName = new SkillEffectName();
            

            using (Dota2Entities ctx = new Dota2Entities())
            {
                try
                {
                    ctx.Configuration.LazyLoadingEnabled = false;

                    var result = from s in ctx.SkillEffectName
                                 where s.SkillId == skill.ID
                                    && s.Skill.Hero.Name == skill.Hero.Name
                                    && s.Skill.Description == skill.Description
                                 select s;
                    
                    if(result.Count() == 0)
                    {
                        Console.WriteLine("Skill " + name + " Already exists...");
                        return result.First();
                    }
                    else if(result.Count() > 1)
                    {
                        //TODO Create log
                        throw new Exception("More than 1 skilleffectname returned. Check this");
                    }
                    else
                    {
                        return null;   
                    }
                }
                catch (Exception e)
                {
                    //TODO implementar log de erro
                    throw e;
                }                
            }
        }
        public SkillEffectName insertSkillEffectName(string name)
        {
            SkillEffectName skillEffectName = new SkillEffectName();

            skillEffectName.Name = name.Trim();

            using(Dota2Entities ctx = new Dota2Entities())
            {
                try
                {
                    skillEffectName = ctx.SkillEffectName.Add(skillEffectName);
                    ctx.SaveChanges();
                    Console.WriteLine("Skill " + name + " Created");
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            return skillEffectName;
        }
Ejemplo n.º 25
0
		void setTargetAffectedType (string targetAffectedTypeString)
		{
			TargetAffectedType targetAffectedType = new TargetAffectedType();
			using (Dota2Entities ctx = new Dota2Entities())
			{
				var targetAffectedTp = (from p in ctx.TargetAffectedType
										where p.Name == targetAffectedTypeString
								 select p).FirstOrDefault();

				targetAffectedType = targetAffectedTp;
			}

			if (targetAffectedType != null)
			{
				this.skill.TargetAffectedTypeId = targetAffectedType.ID;
			}
			else
			{
				//TODO Incluir este erro no log posteriormente
				throw new Exception("No TargetAffectedType has been returned. TargetAffectedType: " + targetAffectedTypeString);
			}
		}
Ejemplo n.º 26
0
		void setDamageType(string damageTypeString)
		{
			DamageType damageType = new DamageType();
			using (Dota2Entities ctx = new Dota2Entities())
			{
				var damageTp = (from p in ctx.DamageType
										where p.Name == damageTypeString
										select p).FirstOrDefault();

				damageType = damageTp;
			}

			if (damageType != null)
			{
				this.skill.DamageTypeId = damageType.ID;
			}
			else
			{
				//TODO Incluir este erro no log posteriormente
				throw new Exception("No DamageType has been returned. DamageType: " + damageTypeString);
			}
		}
Ejemplo n.º 27
0
		/// <summary>
		/// Insert a new Skill and SkillAbilityTypes
		/// </summary>        
		private Skill InsertSkill()
		{
			SkillAbilityTypesCreator skillAbilityTypesCreator = new SkillAbilityTypesCreator();
			bool isSkillAbilityTypeInserted = false;
			using (Dota2Entities ctx = new Dota2Entities())
			{
				try
				{
					ctx.Skill.Add(this.skill);
					ctx.SaveChanges();
					foreach (var abilityType in abilityTypeList)
					{
						skillAbilityTypesCreator.insert(this.skill.ID, abilityType.ID, out isSkillAbilityTypeInserted);
						//If we have a error when inserting SkillAbilityType, then delete the inserted skill
						if(!isSkillAbilityTypeInserted)
						{
							//TODO Create a function to remove all the SkillAbilityTypes that have been created for this skill
							ctx.Skill.Remove(this.skill);
						}
					}
					
					
				}
				catch (Exception e)
				{
					//TODO Adicionar ao log
					throw e;
				}
			}

			return this.skill;
		}
Ejemplo n.º 28
0
        /// <summary>
        /// Workaround 
        /// Get the first skill description because there're skills that have the same name and the same heroName, but they are equals, so get the first description
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="heroId"></param>
        /// <returns></returns>
        public static Skill SelectSkill(string name, int heroId)
        {
            Skill skill = new Skill();
            using (Dota2Entities ctx = new Dota2Entities())
            {
                try
                {
                    skill = ctx.Skill.Where(s => s.Name == name &&
                                                 s.HeroId == heroId).FirstOrDefault();
                }
                catch (Exception e)
                {
                    //TODO adicionar log
                    throw e;
                }
            }

            return skill;
        }
Ejemplo n.º 29
0
        public bool SkillExists(string skillName, string skillDescription, int heroId)
        {
            //Check if the skill exists
            using (Dota2Entities ctx = new Dota2Entities())
            {
                bool skillExists = ctx.Skill.Any(s => s.HeroId == heroId
                                      && s.Name == skillName
                                    && s.Description == skillDescription);

                return skillExists;
            }
                                    
        }
 public SkillAbilityTypesCreator(int skillId, int abilityTypeId, Dota2Entities ctx)
 {
     ctx.SkillAbilityTypes
 }