/// <summary> /// Insert a new Skill and SkillAbilityTypes /// </summary> Skill insertSkill() { SkillAbilityTypesCreator skillAbilityTypesCreator = new SkillAbilityTypesCreator(); using (Dota2Entities ctx = new Dota2Entities()) { try { ctx.Skill.Add(this.skill); foreach (var abilityType in abilityTypeList) { skillAbilityTypesCreator.insert(this.skill.ID, abilityType.ID); } ctx.SaveChanges(); } catch (Exception e) { //TODO Adicionar ao log throw e; } } return this.skill; }
/// <summary> /// Insert a new Skill and SkillAbilityTypes /// </summary> 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; }