本文整理汇总了C#中UserRepository.GetBy方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.GetBy方法的具体用法?C# UserRepository.GetBy怎么用?C# UserRepository.GetBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.GetBy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var dbContext = new ApplicationDbContext();
using (var uow = new UnitOfWork(dbContext))
{
// Creating user
// var user1 = new User { Login = "Anna", Password = "123" };
// var userRepo = new UserRepository(dbContext);
//userRepo.Create(user1);
//uow.Commit();
var userRepo = new UserRepository(dbContext);
var user1 = new User { Login = "Anna1", Password = "123" };
var user2 = new User { Login = "Anna2", Password = "123" };
// userRepo.Create(user1);
//userRepo.Create(user2);
// uow.Commit();
var users = userRepo.GetAll();
Console.WriteLine("All users count: " + users.Count());
var anna = userRepo.GetBy(user1.Login);
userRepo.Delete(anna);
uow.Commit();
users = userRepo.GetAll();
Console.WriteLine("All filtered users count: " + users.Count());
Console.ReadLine();
// Creating user article
var article1 = new Article { Title = "Article1", Body = "Article1 BodyText" };
var anna2 = userRepo.GetBy(user2.Login);
userRepo.Delete(anna2);
// anna2.Articles.Add(article1);
uow.Commit();
/*var comment1 = new Comment { Body = "Article1 is my first arctile. (Anna)" };
var articleRepo = new ArticleRepository(dbContext);
anna2.Comments.Add(comment1);
article1.Comments.Add(comment1);
uow.Commit();*/
}
}
示例2: IsAdmin
public static Boolean IsAdmin(this IPrincipal principal)
{
UserRepository userRepository = new UserRepository();
User user = userRepository.GetBy(x => x.Email == principal.Identity.Name);
return user != null && user.Role == Role.Admin;
}
示例3: Register
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
UserRepository userRepository = new UserRepository();
User user = userRepository.GetBy(x => x.Email == model.Email);
if (user != null)
{
ModelState.AddModelError(String.Empty, @"Користувач з вказаним Email вже існує.");
}
else
{
userRepository.RegisterUser(model.Email, model.Password);
return Content("register");
}
}
return PartialView(model);
}
示例4: OrderTour
public ActionResult OrderTour(int id, int placeNumber)
{
UserRepository userRepository = new UserRepository();
OrderRepository orderRepository = new OrderRepository();
TourRepository tourRepository = new TourRepository();
Tour tour = tourRepository.GetById(id);
if (tour != null)
{
Order order = new Order();
order.Date = DateTime.Now;
order.PlaceCount = placeNumber;
order.Tour = tour;
order.User = userRepository.GetBy(x => x.Email == User.Identity.Name);
orderRepository.AddOrder(order);
}
return Redirect("/Tour/Orders");
}
示例5: HistoryOrders
public ActionResult HistoryOrders()
{
String email = User.Identity.Name;
UserRepository userRepository = new UserRepository();
User user = userRepository.GetBy(x => x.Email == email);
if (user == null)
{
return View(new List<Order>());
}
OrderRepository orderRepository = new OrderRepository();
List<Order> orders = orderRepository.FilterBy(x => x.User.Id == user.Id).ToList();
return View(orders);
}