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


C# UserRepository.Find方法代码示例

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


在下文中一共展示了UserRepository.Find方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddUser_should_save

        public void AddUser_should_save()
        {
            string username = "save" + Guid.NewGuid();

            var user = new User
            {
                 Email = "[email protected]",
                 FirstName = "john",
                 IsActive = true,
                 LastName = "haigh",
                 PasswordHash = "asdf",
                 Username = username
            };

            var svc = new UserService();
            svc.AddUser(user);

            var repo = new UserRepository();

            var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();

            // Test
            repoUser.ShouldNotBeNull();

            // Cleanup user
            repo.Delete(repoUser);
            repo.Save();

            var results2 = repo.Find(u => u.Username == username);
            var userFound2 = results2.FirstOrDefault();

            Assert.IsNull(userFound2, "Tried to get user but the user was found");
        }
开发者ID:versosystems,项目名称:account-lib,代码行数:33,代码来源:UserServiceTests.cs

示例2: ChangeInfo

 public ActionResult ChangeInfo(User user)
 {
     userRsy = new UserRepository();
     if(userRsy.Authentication(UserName,Ninesky.Common.Text.Sha256(user.Password))==0)
     {
         var _user = userRsy.Find(UserName);
         _user.Gender = user.Gender;
         _user.Email = user.Email;
         _user.QQ = user.QQ;
         _user.Tel = user.Tel;
         _user.Address = user.Address;
         _user.PostCode = user.PostCode;
         if (userRsy.Update(_user))
         {
             Notice _n = new Notice { Title = "修改资料成功", Details = "您已经成功修改资料!", DwellTime = 5, NavigationName = "用户首页", NavigationUrl = Url.Action("Default", "User") };
             return RedirectToAction("UserNotice", "Prompt", _n);
         }
         else
         {
             Error _e = new Error { Title = "修改资料失败", Details = "在修改用户资料时时,更新的资料未能保存到数据库", Cause = "系统错误", Solution = Server.UrlEncode("<li>返回<a href='" + Url.Action("ChangeInfo", "User") + "'>修改资料</a>页面,输入正确的信息后重新操作</li><li>联系网站管理员</li>") };
             return RedirectToAction("UserError", "Prompt", _e);
         }
     }
     else
     {
         ModelState.AddModelError("Password","密码错误!");
         return View();
     }
 }
开发者ID:Jopix,项目名称:dotnet,代码行数:29,代码来源:UserController.cs

示例3: Find_By_Guid

        public void Find_By_Guid()
        {
            IUserRepository userRepository = new UserRepository(this.Client, this.Database);

            User accountUser = new User("name",  Guid.NewGuid().ToString(), "password");
            userRepository.Save(accountUser);

            User accountUserLoaded = userRepository.Find(accountUser.Guid);
            Assert.IsTrue(accountUserLoaded.Id == accountUserLoaded.Id);
        }
开发者ID:Appacts,项目名称:mobile-analytics-server,代码行数:10,代码来源:UserRepositoryIntegration.cs

示例4: Find_By_Email_And_Password

        public void Find_By_Email_And_Password()
        {
            IUserRepository userRepository = new UserRepository(this.Client, this.Database);

            User accountUser = new User("name", Guid.NewGuid().ToString(), "password");
            userRepository.Save(accountUser);

            User accountUserFound = userRepository.Find(accountUser.Email, accountUser.Password);
            Assert.IsNotNull(accountUserFound);
        }
开发者ID:Appacts,项目名称:mobile-analytics-server,代码行数:10,代码来源:UserRepositoryIntegration.cs

示例5: EditUserFormViewModel

 public EditUserFormViewModel( IUnitOfWork unitOfWork, int id )
 {
     var userRepository = new UserRepository(unitOfWork);
     var user = userRepository.Find(id);
     if( user == null ) throw new NotFoundException();
     UserId = id;
     UserName = user.UserName;
     LoginName = user.LoginName;
     DepartMentId = user.DepartMentId;
     Password = user.PasswordHash;
     Activated = user.Activated;
     UserRoles =  user.Roles;
 }
开发者ID:bearing09,项目名称:Jspm,代码行数:13,代码来源:UserFormViewModel.cs

示例6: AddUser_should_save_with_user_properties

        public void AddUser_should_save_with_user_properties()
        {
            string username = "save_with_user_propertie" + Guid.NewGuid();

            var user = new User
            {
                Email = "[email protected]",
                FirstName = "john",
                IsActive = true,
                LastName = "haigh",
                PasswordHash = "asdf",
                Username = username
            };

            var svc = new UserService();
            svc.AddUser(user);

            var repo = new UserRepository();

            var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();

            // Test
            repoUser.Email.ShouldEqual(user.Email);
            repoUser.FirstName.ShouldEqual(user.FirstName);
            repoUser.LastName.ShouldEqual(user.LastName);
            repoUser.IsActive.ShouldEqual(user.IsActive);
            repoUser.PasswordHash.ShouldEqual(user.PasswordHash);
            repoUser.Username.ShouldEqual(user.Username);

            // Cleanup user
            repo.Delete(repoUser);
            repo.Save();

            var results2 = repo.Find(u => u.Username == username);
            var userFound2 = results2.FirstOrDefault();

            userFound2.ShouldBeNull();
        }
开发者ID:versosystems,项目名称:account-lib,代码行数:38,代码来源:UserServiceTests.cs

示例7: UpdateUserMessage

        public void UpdateUserMessage()
        {
            using (var uow = new CapriconContext())
            {
                var userMessageRepository = new UserMessageRepository(uow);

                var existingUserMessage = userMessageRepository.Find(um => um.Id == 1).FirstOrDefault();

                Assert.IsNotNull(existingUserMessage);

                //retreive an existing user
                var userRepository = new UserRepository(uow);
                var existingUser = userRepository.Find(u => u.UserId == 1).FirstOrDefault();

                Assert.IsNotNull(existingUser);

                //retreive an existing message
                var messageRepository = new MessageRepository(uow);
                var existingMessage = messageRepository.Find(m => m.MessageId == 1).FirstOrDefault();

                Assert.IsNotNull(existingMessage);

                //edit an existing user message
                existingUserMessage.User = existingUser;
                existingUserMessage.Message = existingMessage;

                userMessageRepository.Attach(existingUserMessage);
                uow.Entry(existingUserMessage).State = EntityState.Modified;

                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, existingUser);
                Assert.AreEqual(savedUserMessages[0].Message, existingMessage);
            };
        }
开发者ID:shyakaster,项目名称:CARPRICONRELOADED,代码行数:61,代码来源:UserMessageTests.cs

示例8: Update

        public void Update()
        {
            IUserRepository userRepository = new UserRepository(this.Client, this.Database);

            User accountUser = new User("name", Guid.NewGuid().ToString(), "password");
            userRepository.Save(accountUser);

            User accountUserLoaded = userRepository.Find(accountUser.Id);

            accountUserLoaded.Active = false;
            accountUserLoaded.Password = "password";
            accountUserLoaded.DateModified = DateTime.Now;

            userRepository.Update(accountUserLoaded);

            User accountUserUpdate = userRepository.Find(accountUser.Id);

            Assert.IsTrue(accountUserUpdate.Active == accountUserLoaded.Active);
        }
开发者ID:Appacts,项目名称:mobile-analytics-server,代码行数:19,代码来源:UserRepositoryIntegration.cs

示例9: Return_Null_For_Wrong_Email

 public void Return_Null_For_Wrong_Email()
 {
     IUserRepository userRepository = new UserRepository(this.Client, this.Database);
     Assert.IsNull(userRepository.Find(Guid.NewGuid().ToString()));
 }
开发者ID:Appacts,项目名称:mobile-analytics-server,代码行数:5,代码来源:UserRepositoryIntegration.cs

示例10: GetUserByUsername_should_getuser

        public void GetUserByUsername_should_getuser()
        {
            string username = "getbyusername" + Guid.NewGuid();

            var user = new User
            {
                Email = "[email protected]",
                FirstName = "john",
                IsActive = true,
                LastName = "haigh",
                PasswordHash = "asdf",
                Username = username
            };

            var svc = new UserService();
            svc.AddUser(user);

            // main test
            var userAssert = svc.GetUserByUsername(username);

            userAssert.ShouldNotBeNull();

            // Assert
            var repo = new UserRepository();

            var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();

            // Cleanup user
            repo.Delete(repoUser);
            repo.Save();

            var results2 = repo.Find(u => u.Username == username);
            var userFound2 = results2.FirstOrDefault();

            userFound2.ShouldBeNull();
        }
开发者ID:versosystems,项目名称:account-lib,代码行数:36,代码来源:UserServiceTests.cs

示例11: ChangePassword

 public ActionResult ChangePassword(UserChangePassword userChangePassword)
 {
     userRsy = new UserRepository();
     if (userRsy.Authentication(UserName, Common.Text.Sha256(userChangePassword.Password)) == 0)
     {
         var _user = userRsy.Find(UserName);
         if (_user == null)
         {
             Error _e = new Error { Title = "修改密码失败", Details = "修改密码时,系统查询不到用户信息", Cause = Server.UrlEncode("<li>用户在修改密码界面停留的时间过长,登录信息已失效。</li><li>系统错误。</li>"), Solution = Server.UrlEncode("<li>返回<a href='" + Url.Action("ChangePassword", "User") + "'>修改密码</a>页面,输入正确的信息后重新注册</li><li>联系网站管理员</li>") };
             return RedirectToAction("Error", "Prompt", _e);
         }
         _user.Password = Common.Text.Sha256(userChangePassword.NewPassword);
         if (userRsy.Update(_user))
         {
             Notice _n = new Notice { Title = "成功修改密码", Details = "您已经成功修改密码,请牢记您的新密码!", DwellTime = 5, NavigationName = "登陆页面", NavigationUrl = Url.Action("Login", "User") };
             return RedirectToAction("Notice", "Prompt", _n);
         }
         else
         {
             Error _e = new Error { Title = "修改密码失败", Details = "修改密码时,更新数据库失败!", Cause = Server.UrlEncode("<li>系统错误。</li>"), Solution = Server.UrlEncode("<li>返回<a href='" + Url.Action("ChangePassword", "User") + "'>修改密码</a>页面,输入正确的信息后重新注册</li><li>联系网站管理员</li>") };
             return RedirectToAction("Error", "Prompt", _e);
         }
     }
     else
     {
         ModelState.AddModelError("Password", "原密码不正确,请重新输入");
         return View();
     }
 }
开发者ID:Jopix,项目名称:dotnet,代码行数:29,代码来源:UserController.cs

示例12: DeleteUser

        public void DeleteUser()
        {
            using (var uow = new CapriconContext())
            {
                var userRep = new UserRepository(uow);
                var existingUser = userRep.Find(u => u.UserId == 2).FirstOrDefault();

                Assert.IsNotNull(existingUser);

                int userId;
                if (existingUser != null)
                {
                    userId = existingUser.UserId;

                    //Delete employee
                    userRep.Delete(existingUser);

                    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");
                    }

                    Assert.IsNull(userRep.Find(u => u.UserId == userId).FirstOrDefault());
                }
                else //no userss were selected
                    Assert.Fail("No user was selected");
            }
        }
开发者ID:shyakaster,项目名称:CARPRICONRELOADED,代码行数:46,代码来源:UserTests.cs


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