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"); }
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(); }
public static IQueryable<Beer> Search(this IQueryable<Beer> query, User user, string term) { return query.ForUser(user) .Where(b => b.Name.StartsWith(term)); }
public static IQueryable<Beer> ForUser(this IQueryable<Beer> query, User user) { return query.Where(b => b.Owner.ID == user.ID); }
public FakeSessionContext(User currentLoggedUser) { _currentLoggedUser = currentLoggedUser; }