public Skill GetSkill(int id) { using (var ctx = new TarikSkillsDB()) { return GetSkill(id, ctx); } }
public IEnumerable<Skill> GetSkills() { using (var context = new TarikSkillsDB()) { return context.Skills.Include("Level").ToList(); } }
public IEnumerable<Level> GetLevels() { using (var ctx = new TarikSkillsDB()) { return ctx.Levels.ToList(); } }
public Level GetLevel(int id) { using (var ctx = new TarikSkillsDB()) { return (from c in ctx.Levels where c.id == id select c).FirstOrDefault(); } }
public Skill CreateSkill(Skill skill) { using (var ctx = new TarikSkillsDB()) { ctx.Skills.Add(skill); ctx.SaveChanges(); int newId = skill.id; return GetSkill(newId, ctx); } }
public Skill DeleteSkill(int id) { using (var ctx = new TarikSkillsDB()) { Skill s = GetSkill(id, ctx); if (s == null) return null; ctx.Skills.Remove(s); ctx.SaveChanges(); return s; } }
public Skill UpdateSkill(Skill skill) { using (var ctx = new TarikSkillsDB()) { Skill s = GetSkill(skill.id, ctx); if (s == null) return null; s.level_id = skill.level_id; s.name = skill.name; s.experience = skill.experience; ctx.SaveChanges(); s.Level = GetLevel(s.level_id); return s; } }
private static Skill GetSkill(int id, TarikSkillsDB ctx) { return (from s in ctx.Skills where s.id == id select s).Include("Level").FirstOrDefault(); }