Exemplo n.º 1
0
		public Conceptual.Skill GetById(Guid skillId) {
			var results =
				from s in _dbContext.Skills
				join st in _dbContext.SkillTaggings on s.SkillId equals st.SkillId
				join t in _dbContext.SkillTags on st.TagId equals t.TagId
				where s.SkillId == skillId
				select new { s.SkillId, s.Code, s.IconClass, s.Name, s.Rating, Tag = t.Code }
			;

			var iter = results.GetEnumerator();
			if (!iter.MoveNext()) {
				throw new InvalidOperationException($"Skill with SkillId {skillId} does not exist");
			}

			var first = iter.Current;
			var skill = new Conceptual.Skill {
				SkillId = first.SkillId,
				Code = first.Code,
				IconClass = first.IconClass,
				Name = first.Name,
				Rating = first.Rating,
				Tags = new List<string> { first.Tag }
			};

			while (iter.MoveNext()) {
				skill.Tags.Add(iter.Current.Tag);
			}

			return skill;
		}
Exemplo n.º 2
0
		public IEnumerable<Conceptual.Skill> GetAll() {
			var results =
				from s in _dbContext.Skills
				join st in _dbContext.SkillTaggings on s.SkillId equals st.SkillId
				join t in _dbContext.SkillTags on st.TagId equals t.TagId
				orderby s.Name
				select new { s.SkillId, s.Code, s.IconClass, s.Name, s.Rating, Tag = t.Code }
			;

			using (var iter = results.GetEnumerator()) {
				if (!iter.MoveNext()) yield break;

				var cur = iter.Current;
				var skill = new Conceptual.Skill {
					SkillId = cur.SkillId,
					Code = cur.Code,
					IconClass = cur.IconClass,
					Name = cur.Name,
					Rating = cur.Rating,
					Tags = new List<string> { cur.Tag }
				};

				while (iter.MoveNext()) {
					cur = iter.Current;
					if (cur.SkillId != skill.SkillId) {
						yield return skill;
						skill = new Conceptual.Skill {
							SkillId = cur.SkillId,
							Code = cur.Code,
							IconClass = cur.IconClass,
							Name = cur.Name,
							Rating = cur.Rating,
							Tags = new List<string>()
						};
					}
					skill.Tags.Add(cur.Tag);
				}
				yield return skill;
			}
		}