public ICollection<UnitWrapper> GetRecommendedUnits(UserWrapper user, int RecommendationCount) { int _numberOfDisplayedUnits = RecommendationCount <0 ? _maxNumberOfDisplayedUnits : RecommendationCount; UnitAccess access = new UnitAccess(); ICollection<UnitWrapper> candidates; if (user == null) { candidates = access.GetUnits().ToList(); } else { candidates = access.GetUnitsByDicipline(user.Dicipline.ToList()).ToList(); if (candidates.Count() < _numberOfDisplayedUnits) { int num = _numberOfDisplayedUnits - candidates.Count(); foreach (var unitWrapper in access.GetUnits().OrderByDescending(d=>d.AverageRating).Take(num)) { candidates.Add(unitWrapper); } } } return candidates.OrderByDescending(d => d.AverageRating).ToList().GetRange(0, candidates.Count() >= _numberOfDisplayedUnits ? _numberOfDisplayedUnits : candidates.Count()); }
public Dictionary<String, List<UnitWrapper>> GetUnitsPerDiscipline() { UnitAccess unitAccess=new UnitAccess(); var result = unitAccess.GetUnits(); Dictionary<string,List<UnitWrapper>> dic=new Dictionary<string, List<UnitWrapper>>(); foreach (UnitWrapper u in unitAccess.GetUnits()) { if(!dic.ContainsKey(u.Dicipline.Name)) dic.Add(u.Dicipline.Name,new List<UnitWrapper>()); dic[u.Dicipline.Name].Add(u); } //return result.Select(unit => new UnitWrapper {UnitObject = unit}).ToList(); return dic; }
public Dictionary<string, List<UnitWrapper>> GetUnitsPerDiscipline(String filterText) { UnitAccess unitAccess = new UnitAccess(); var result = unitAccess.GetUnits().Where(w=>w.Name.ToLower().Contains(filterText.ToLower()) || w.UnitCode.ToLower().Contains(filterText.ToLower())||w.Description.ToLower().Contains(filterText.ToLower())||w.Dicipline.Name.ToLower().Contains(filterText.ToLower())); Dictionary<string, List<UnitWrapper>> dic = new Dictionary<string, List<UnitWrapper>>(); foreach (UnitWrapper u in result) { if (!dic.ContainsKey(u.Dicipline.Name)) dic.Add(u.Dicipline.Name, new List<UnitWrapper>()); dic[u.Dicipline.Name].Add(u); } return dic; }