Beispiel #1
0
        public IActionResult ViewImageTag(string term)
        {
            using (var db = new FusekiContext())
            {
                var model = new ViewImagesModel();
                model.Term = term;
                term       = term.ToLower();
                var    images    = new List <Image>();
                string matchType = "";
                var    tag       = db.ImageTags.FirstOrDefault(el => el.Name.ToLower() == term);
                if (tag == null)
                {
                    tag       = db.ImageTags.FirstOrDefault(el => el.Name.ToLower().StartsWith(term));
                    matchType = "prefix";
                }
                else if (tag == null)
                {
                    tag       = db.ImageTags.FirstOrDefault(el => el.Name.ToLower().Contains(term));
                    matchType = "substring";
                }
                else if (tag == null)
                {
                    tag       = null;
                    matchType = "none";
                }
                else
                {
                    matchType = "exact";
                }

                if (tag != null)
                {
                    var tagName = tag.Name;
                    var tags    = db.ImageTags.Where(el => el.Name == tagName);
                    images = tags.Select(el => el.Image)
                             .Include(el => el.ImageTags)
                             .ToList();
                }

                model.Images    = images;
                model.MatchType = matchType;
                return(View("ViewImages", model));
            }
        }
Beispiel #2
0
        public IActionResult ViewImages(string term)
        {
            using (var db = new FusekiContext())
            {
                var model = new ViewImagesModel();
                model.Term = term;
                IOrderedQueryable <Image> images;
                if (!string.IsNullOrEmpty(term))
                {
                    images     = db.Images.Where(el => el.Filename.ToLower().Contains(term.ToLower())).OrderByDescending(el => el.Id);
                    model.Term = "Search for: " + term;
                }
                else
                {
                    images = db.Images.OrderByDescending(el => el.Id).Take(20).OrderByDescending(el => el.Id);
                }

                model.Images = images
                               .Where(el => el.Deleted == false)
                               .Include(el => el.ImageTags)
                               .ToList();
                return(View("ViewImages", model));
            }
        }