コード例 #1
0
        public ActionResult Register([Bind(Include = "Username,Password")] RegisterViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var user = new User(model.Username, model.Password);

            _persistenceContext.Add(user);
            _persistenceContext.SaveChanges();

            return RedirectToAction("Index", "Home");
        }
コード例 #2
0
        static TestData()
        {
            var users = new List<User>();
            var user1 = new User("user1", "my super secret password") { ID = 1 };
            var user2 = new User("user2", "my super secret password") { ID = 2 };

            users.Add(user1);
            users.Add(user2);

            Users = users.AsQueryable();

            var beers = new List<Beer>();

            beers.AddRange(new Beer[]
            {
                new Beer
                {
                    ID = 1,
                    Name = "beer 1",
                    Quantity = 10,
                    Owner = user1
                },
                new Beer
                {
                    ID = 2,
                    Name = "beer 2",
                    Quantity = 10,
                    Owner = user1
                },
                new Beer
                {
                    ID = 3,
                    Name = "beer 3",
                    Quantity = 10,
                    Owner = user1
                },
                new Beer
                {
                    ID = 4,
                    Name = "beer 4",
                    Quantity = 10,
                    Owner = user2
                },
                new Beer
                {
                    ID = 5,
                    Name = "beer 5",
                    Quantity = 10,
                    Owner = user2
                },
                new Beer
                {
                    ID = 6,
                    Name = "beer 10",
                    Quantity = 10,
                    Owner = user1
                }
            });

            Beers = beers.AsQueryable();
        }
コード例 #3
0
ファイル: BeerQueries.cs プロジェクト: yanpearson/BeerCellier
 public static IQueryable<Beer> Search(this IQueryable<Beer> query, User user, string term)
 {
     return query.ForUser(user)
         .Where(b => b.Name.StartsWith(term));
 }
コード例 #4
0
ファイル: BeerQueries.cs プロジェクト: yanpearson/BeerCellier
 public static IQueryable<Beer> ForUser(this IQueryable<Beer> query, User user)
 {
     return query.Where(b => b.Owner.ID == user.ID);
 }
コード例 #5
0
 public FakeSessionContext(User currentLoggedUser)
 {
     _currentLoggedUser = currentLoggedUser;
 }