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


C# UserRepository.GetAll方法代码示例

本文整理汇总了C#中UserRepository.GetAll方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.GetAll方法的具体用法?C# UserRepository.GetAll怎么用?C# UserRepository.GetAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserRepository的用法示例。


在下文中一共展示了UserRepository.GetAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Remove_Entity_Test

        public static void Remove_Entity_Test()
        {
            IUserRepository repository = new UserRepository(_session);
            ICollection<User> todosAntesDeDelete = repository.GetAll();

            foreach (User User in todosAntesDeDelete)
            {
                repository.Delete(User);
            }

            ICollection<User> todosDepoisDeDelete = repository.GetAll();

            Assert.IsTrue(todosDepoisDeDelete.Count == 0);
        }
开发者ID:icarocamelo,项目名称:iLunchWeb,代码行数:14,代码来源:RepositoryTests.cs

示例3: AddUser

        public void AddUser()
        {
            using (CapriconContext context = new CapriconContext())
            {

                var newUser = new User()
                {
                    FirstName = "james",
                    LastName = "kamau",
                    OtherName = "",
                    Gender = Gender.Female,
                    MobilePhone = "0756 123 456",
                    Email = "[email protected]",
                    Town = "Nairobi",
                    District = "Nairobi",
                    DateOfBirth = DateTime.Now.AddYears(-40),
                };

                var userRep = new UserRepository(context);
                userRep.Add(newUser);

                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //Retrieve validation errors
                    ex.EntityValidationErrors.ToList().ForEach
                    (
                        v =>
                        {
                            v.ValidationErrors.ToList().ForEach
                                (
                                    e =>
                                    {
                                        System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                                    }
                                );
                        }
                    );
                    Assert.Fail("Test failed");
                }

                //retrieve saved object
                var context1 = new CapriconContext();
                var repository = new UserRepository(context1);
                var savedUsers = repository.GetAll().ToList();

               Assert.AreEqual(savedUsers.Count(), 1, "returns 20 records");
               var savedUsersList = savedUsers;
               savedUsersList.ForEach
                   (
                       s =>
                       {
                           Debug.WriteLine(s.UserId +" - "+ s.FirstName +" "+ s.LastName);
                       }
                   );
            };
        }
开发者ID:shyakaster,项目名称:CARPRICONRELOADED,代码行数:60,代码来源:UserTests.cs

示例4: AddUserMessage

        public void AddUserMessage()
        {
            using (var uow = new CapriconContext())
            {
                //retreive an existing user
                var userRepository = new UserRepository(uow);
                var existingUser = userRepository.GetAll().FirstOrDefault();

                Assert.IsNotNull(existingUser);

                //retreive an existing message
                var messageRepository = new MessageRepository(uow);
                var existingMessage = messageRepository.GetAll().FirstOrDefault();

                Assert.IsNotNull(existingMessage);

                //create new user messsage
                var newUserMessage = new UserMessage()
                {
                    User = existingUser,
                    Message = existingMessage
                };

                //add the new user message to the repository
                var userMessageRepository = new UserMessageRepository(uow);
                userMessageRepository.Add(newUserMessage);

                try
                {
                    uow.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //Retrieve validation errors
                    ex.EntityValidationErrors.ToList().ForEach
                    (
                        v =>
                        {
                            v.ValidationErrors.ToList().ForEach
                                (
                                    e =>
                                    {
                                        System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                                    }
                                );
                        }
                    );

                    Assert.Fail("Test failed");
                }

                //retrieve saved object
                var uow1 = new CapriconContext();
                var repository = new UserMessageRepository(uow1);
                var savedUserMessages = repository.GetAll().ToList();

                Assert.AreEqual(savedUserMessages[0].User.FirstName, existingUser.FirstName = "james");
                Assert.AreEqual(savedUserMessages[0].Message.MessageId, existingMessage.MessageId = 1);
            };
        }
开发者ID:shyakaster,项目名称:CARPRICONRELOADED,代码行数:60,代码来源:UserMessageTests.cs

示例5: GetMySql

 public static void GetMySql()
 {
     UserRepository rep = new UserRepository(new MySqlDbContext());
     rep.Insert(new User { ID = new Guid("12736219-9398-4DBD-A392-BF8C5CCC3635"), Mobile = "01819421877", Password = "NewPassword", Username = "SiamDeath" });
     rep.Commit();
     var data = rep.Get(new Guid("C1C8D804-0645-4006-B9C8-192EBD944944"));
     var collection = rep.GetAll().ToList();
 }
开发者ID:LudwigLei,项目名称:MSSQL-MySql-Mongo-Repository-withEF6,代码行数:8,代码来源:Program.cs

示例6: Index

        public ActionResult Index()
        {
            var test = WebSecurity.CurrentUserName;
            var db = new GazDbContext();
            var repo = new UserRepository(db);
            var users = repo.GetAll();

            return View(users);
        }
开发者ID:RonenZ,项目名称:GazProject,代码行数:9,代码来源:HomeController.cs

示例7: ListAdmins

        public ActionResult ListAdmins()
        {
            AdminListAdminsVM model = new AdminListAdminsVM();
            UserRepository<Administrator> adminRepo = new UserRepository<Administrator>();

            model.Administrators = adminRepo.GetAll();

            return View(model);
        }
开发者ID:hristo-enchev,项目名称:UniversitySystem,代码行数:9,代码来源:AdministratorController.cs

示例8: GetSql

        public static void GetSql()
        {
            UserRepository rep = new UserRepository(new WebApiDBContext());
            rep.Insert(new User { ID = new Guid("19D40AEC-37B7-4114-A5BF-E4E3B3CFC97A"), Mobile = "01819421877", Password = "NewPassword", Username = "SiamDeath" });
            rep.Commit();

            var data = rep.Get(new Guid("C1C8D804-0645-4006-B9C8-192EBD944944"));
            var collection = rep.GetAll().ToList();

        }
开发者ID:LudwigLei,项目名称:MSSQL-MySql-Mongo-Repository-withEF6,代码行数:10,代码来源:Program.cs

示例9: GetUsers

        public JsonResult GetUsers(DataTablesRequest model)
        {
            string dataPath = ConfigurationManager.AppSettings["UsersPath"];
            var repo = new UserRepository(dataPath);
            var data = repo.GetAll().AsQueryable();
            var dataTableParser = new DataTablesParser<User>(model, data);
            var formattedList = dataTableParser.Process();

            return Json(formattedList, JsonRequestBehavior.AllowGet);
        }
开发者ID:itlackey,项目名称:DataTablesDotNet,代码行数:10,代码来源:HomeController.cs

示例10: WhenGetAllFromEmptyDatabase_ThenReturnsEmptyCollection

        public void WhenGetAllFromEmptyDatabase_ThenReturnsEmptyCollection()
        {
            this.InitializeFixture();

            var repository = new UserRepository(new DatabaseFactory());
            IEnumerable<User> actual = repository.GetAll();

            Assert.NotNull(actual);
            var actualList = new List<User>(actual);
            Assert.Equal(0, actualList.Count);
        }
开发者ID:rajbyexample,项目名称:Firebrick-CMS,代码行数:11,代码来源:UserRepositoryFixture.cs

示例11: Get

        public IEnumerable<User> Get()
        {
            string userName = Thread.CurrentPrincipal.Identity.Name;

            var userDataContext = new UserDataContext();
            var userRepository = new UserRepository(userDataContext);

            IQueryable<User> allUsers = userRepository.GetAll();
            var result = allUsers.ToList();
            return result;
        }
开发者ID:thilinamadushanka,项目名称:FeedReader_Repo,代码行数:11,代码来源:UsersController.cs

示例12: Index

        public ActionResult Index()
        {
            AdministratorIndexVM model = new AdministratorIndexVM();
            UserRepository<Teacher> tRepo = new UserRepository<Teacher>();
            UserRepository<Student> sRepo = new UserRepository<Student>();
            UserRepository<Administrator> aRepo = new UserRepository<Administrator>();

            model.CountTeachers = tRepo.GetAll().Count();
            model.CountStudents = sRepo.GetAll().Count();
            model.CountAdministrators = aRepo.GetAll().Count();

            return View(model);
        }
开发者ID:hristo-enchev,项目名称:UniversitySystem,代码行数:13,代码来源:AdministratorController.cs

示例13: RateSong

        public void RateSong(SongRatingDto rating, string userName)
        {
            using (SmartPlayerEntities context = new SmartPlayerEntities())
            {
                UserRepository userRepo = new UserRepository(context);

                User currentUser = userRepo.GetAll().First(x => x.Email == userName);
                context.UserSongVotes.Add(new UserSongVote()
                    {
                        Rating = rating.Rating,
                        SongId = rating.SongId,
                        UserId = currentUser.Id
                    });
                context.SaveChanges();
            }
        }
开发者ID:AngelVenchev,项目名称:smart-player-ai,代码行数:16,代码来源:MusicService.cs

示例14: GetUser

        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            if(currUser == null){
                var dbcxt = new GazSimpleUsersDbContext();
                var urepo = new UserRepository(dbcxt);
                currUser = urepo.GetAll().FirstOrDefault(u => u.Username == username);

                if(currUser != null) return null;

                MembershipUser user = new MembershipUser(currUser.FirstName, currUser.FirstName, null, currUser.Email, string.Empty,
                    string.Empty, true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);

                return user;
            }

            return null;
        }
开发者ID:RonenZ,项目名称:GazProject,代码行数:17,代码来源:ExtendedSimpleMembershipProvider.cs

示例15: AddGrade

        public ActionResult AddGrade(int studentID, int subjectID)
        {
            GradeAddGradeVM model = new GradeAddGradeVM();

            UserRepository<Student> sRepo = new UserRepository<Student>();
            SubjectRepository subjRepo = new SubjectRepository();
            GradeRepository gRepo = new GradeRepository();

            Student student = sRepo.GetAll(filter: s => s.ID == studentID && s.Course.CourseSubject.Any(sub => sub.SubjectID == subjectID)).FirstOrDefault();

            Subject subject = subjRepo.GetByID(subjectID);

            Grade grade = gRepo.GetAll(filter: g => g.StudentID == student.ID).FirstOrDefault();

            model.StudentID = student.ID;
            model.SubjectID = subject.ID;

            return View(model);
        }
开发者ID:hristo-enchev,项目名称:UniversitySystem,代码行数:19,代码来源:GradeController.cs


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