示例#1
0
        public ActionResult Search(ViewModels.SearchCriteria criteria)
        {
            string bookingCriteria = string.Empty;

            if (!string.IsNullOrWhiteSpace(criteria.GuestName))
            {
                bookingCriteria = criteria.GuestName.ToLower().Trim();
            }

            IQueryable <Models.Leg> results = db.Legs;

            if (bookingCriteria != string.Empty)
            {
                //Code to try and get the information from the datebase, when you input an Guest Name
                //That will retrive the legs of a booking from a Guest with that Name
                results = (from guest in results
                           from legs in guest.Guests
                           where legs.Name.ToLower().
                           Contains(bookingCriteria)
                           select guest).Distinct();
            }
            results = results.Include(b => b.Guests).
                      OrderBy(b => b.LegId);

            return(PartialView("SearchResults", results.ToList()));
        }
        public IEnumerable <object> Get([FromUri] ViewModels.SearchCriteria criteria)
        {
            switch (criteria.Type.ToLower())
            {
            case "user":
                return(SearchUser(criteria));
            }

            return(null);
        }
        private IEnumerable <ApplicationUserViewModel> SearchUser(ViewModels.SearchCriteria criteria)
        {
            var id         = User.Identity.GetUserId();
            var repository = new UserRepository(ApplicationDbContext);
            var users      = repository.SearchByName(criteria.Key)
                             .Where(model => model.Id != id)
                             .ToList();
            var me = repository.FindById(id);

            return(ApplicationUserToViewModel(me, users));
        }
示例#4
0
        public IEnumerable <Models.Book> GetBySearch([FromUri] ViewModels.SearchCriteria criteria)
        {
            string authorCriteria = string.Empty;
            string titleCriteria  = string.Empty;

            if (!string.IsNullOrWhiteSpace(criteria.Author))
            {
                authorCriteria = criteria.Author.ToLower().Trim();
            }
            if (!string.IsNullOrWhiteSpace(criteria.Title))
            {
                titleCriteria = criteria.Title.ToLower().Trim();
            }

            IQueryable <Models.Book> results = libraryDB.Books;

            if (criteria.FormatId != 0)
            {
                results = results.Where(b => b.Format.FormatId == criteria.FormatId);
            }
            if (criteria.SubjectId != 0)
            {
                results = results.Where(b => b.Subject.SubjectId == criteria.SubjectId);
            }
            if (titleCriteria != string.Empty)
            {
                results = results.Where(b => b.Title.ToLower().Contains(titleCriteria));
            }
            if (authorCriteria != string.Empty)
            {
                results = (from book in results
                           from author in book.Authors
                           where author.Name.ToLower().Contains(authorCriteria)
                           select book).Distinct();
            }

            results = results.Include(b => b.Authors).Include(b => b.Format).Include(b => b.Subject).OrderBy(b => b.Title);

            return(results.ToList());
        }