当前位置: 首页>>代码示例>>C#>>正文


C# UserRepository.GetBy方法代码示例

本文整理汇总了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();*/

            }
        }
开发者ID:annmasalskaya,项目名称:SyncFramework,代码行数:51,代码来源:SfTest.cs

示例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;
        }
开发者ID:julia-homa,项目名称:Travel_business,代码行数:7,代码来源:IdentityExtensions.cs

示例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);
        }
开发者ID:julia-homa,项目名称:Travel_business,代码行数:20,代码来源:AccountController.cs

示例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");
        }
开发者ID:julia-homa,项目名称:Travel_business,代码行数:21,代码来源:TourController.cs

示例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);
        }
开发者ID:julia-homa,项目名称:Travel_business,代码行数:14,代码来源:TourController.cs


注:本文中的UserRepository.GetBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。