public IEnumerable <string> GetImageWithDescription(string filter) { var parts = Regex.Replace(filter.ToUpper(), "[ ,.\\+]+", " ").Split(' ').Where(s => s.Length >= 3).Distinct().ToList(); using (var context = new EmoticonContext()) { return(parts .SelectMany(s => context.Emoticons.Where(a => a.Description.Contains(s))) .GroupBy(s => s.Id) .OrderByDescending(s => s.Count()) .Take(EmoticonsPerPage) .Select(s => s.First().ImageId) .Select(s => new Uri(HttpContext.Current.Request.Url, "/" + s).AbsoluteUri) .ToList()); } }
public void AddImageDescription(string imageId, string description) { if (imageId == null || description == null) { throw new NullReferenceException(); } using (var context = new EmoticonContext()) { var e = context.Emoticons.FirstOrDefault(s => s.ImageId == imageId) ?? new EmoticonContext.Emoticon { ImageId = imageId, Description = "" }; e.Description = Regex .Replace((e.Description + " " + description).ToUpper(), "[ ,.\\+]+", " ") .Split(' ').Where(s => s.Length >= 3).Distinct().Aggregate((a, s) => a + " " + s); if (e.Id == 0) { context.Emoticons.Add(e); } context.SaveChanges(); } }