static void Main(string[] args) { var dbContext = new ApplicationDbContext(); using (var uow = new UnitOfWork(dbContext)) { // Creating user // var user1 = new User { Login = "******", Password = "******" }; // var userRepo = new UserRepository(dbContext); //userRepo.Create(user1); //uow.Commit(); var userRepo = new UserRepository(dbContext); var user1 = new User { Login = "******", Password = "******" }; var user2 = new User { Login = "******", Password = "******" }; // 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();*/ } }
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; }
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); }
public void OnAuthorization(AuthorizationContext filterContext) { var authHeader = filterContext.HttpContext.Request.Headers["Auth"]; if (!string.IsNullOrEmpty(authHeader)) { var selectedToken = TokenRepository.GetBy(t => t.Key == authHeader); if (selectedToken != null) { if (DateTime.UtcNow <= selectedToken.ExpiresOn) { var selectedUser = UserRepository.GetBy(u => u.Id == selectedToken.AllocatedToUserId, "Person"); if (selectedUser != null) { var userRoles = RoleMemberRepository.GetAllBy(m => m.UserId == selectedUser.Id) .Select(r => r.RoleId) .ToList(); var permissions = RolePermissionRepository.GetAllBy(r => userRoles.Contains(r.RoleId), "Permission") .Select(p => p.Permission.PermissionCode) .ToList(); var userInfo = UserInfo.GetInstance(selectedUser, permissions); var newUser = new Principal(userInfo.Name, selectedUser.Code) { Name = userInfo.Name, Id = userInfo.Id, Permissions = permissions }; filterContext.HttpContext.User = newUser; } } } } }
public User GetBy(string row, string value) { return(userDal.GetBy(row, value).ToLocal()); }
public override bool IsValid(object value) { var userRepository = new UserRepository(); return(userRepository.GetBy((string)value) == null); }
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"); }
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); }
public UserModel(Guid userId) { FromEntity(repository.GetBy(userId)); }