示例#1
0
        public ActionResult Index(HomePageViewModel homePageViewModel)
        {
            using (var session = this.dataContext.OpenSession())
            {
                session.Store(homePageViewModel.NewUser);

                session.SaveChanges();
            }

            return this.RedirectToAction("Index");
        }
示例#2
0
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        public ActionResult Index()
        {
            var vm = new HomePageViewModel
            {
                Users = this.GetAllUsers(),
                NewUser = new UserModel(),
                SearchResults = Enumerable.Empty<UserModel>()
            };

            return this.View(vm);
        }
示例#3
0
        public ActionResult Search(string searchTerm)
        {
            IEnumerable<UserModel> users;

            int age;

            var isAgeSearch = int.TryParse(searchTerm, out age);

            using (var session = this.dataContext.OpenSession())
            {
                users = from u in session.Query<UserModel>()
                        where u.Name.StartsWith(searchTerm)
                        || u.Name.EndsWith(searchTerm)
                        || u.Tags.Any(x => x == searchTerm)
                        || u.Age == age
                        select u;

            }

            var vm = new HomePageViewModel
                {
                    Users = this.GetAllUsers(),
                    SearchResults = users
                };

            return this.View("Index", vm);
        }