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


C# Repository.FindOne方法代码示例

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


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

示例1: AddGroup

        public MessageResultDto AddGroup(string name)
        {
            Group group = null;
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<Group> groupRepository = new Repository<Group>(session);
                var existingGroup = groupRepository.FindOne(new Tuple<Expression<Func<Group, object>>, string>(x => x.Name, name));

                if (null == existingGroup)
                {
                    group = new Group { Name = name };
                    groupRepository.Add(group);
                    transaction.Commit();
                    result.SuccessMessage("Group added successfully", group.Id);
                }
                else
                {
                    result.ErrorMessage("Group with same name already exisits");
                }
            }
            return result;
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:25,代码来源:GroupStorageProxy.cs

示例2: AddUser

        public MessageResultDto AddUser(string firstname, string lastname, string nickname, string username, string password, Guid groupId)
        {
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<Group> groupRepository = new Repository<Group>(session);
                var group = groupRepository.FindOne(x => x.Id == groupId);

                IRepository<User> userRepository = new Repository<User>(session);
                var existingUser = userRepository.FindOne(x => x.Username == username);

                if (null == existingUser)
                {
                    userRepository.Add(new User
                    {
                        FirstName = firstname,
                        LastName = lastname,
                        Nickname = nickname,
                        Username = username,
                        Password = password,
                        Group = group
                    });

                    transaction.Commit();
                }
                else
                {
                    result.ErrorMessage("User with same username already exists");
                }
            }
            return result;
        }
开发者ID:SadiqAhmed,项目名称:MyNotes,代码行数:34,代码来源:UserStorageProxy.cs

示例3: UpdateGroup

        public MessageResultDto UpdateGroup(Guid id, string name)
        {
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<Group> groupRepository = new Repository<Group>(session);
                var group = groupRepository.FindOne(x => x.Id == id);
                group.Name = name;
                groupRepository.Update(group);
                transaction.Commit();
            }
            return result;
        }
开发者ID:SadiqAhmed,项目名称:MyNotes,代码行数:15,代码来源:GroupStorageProxy.cs

示例4: DeleteUser

        public MessageResultDto DeleteUser(Guid id)
        {
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<User> userRepository = new Repository<User>(session);
                var user = userRepository.FindOne(id);
                if (user.Accounts.Count > 0)
                {
                    result.ErrorMessage("User has got accounts registered. Please remove all accounts first");
                }
                else
                {
                    userRepository.Delete(id);
                    transaction.Commit();
                    result.Message = "User deleted successfully";
                }
            }
            return result;
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:22,代码来源:UserStorageProxy.cs

示例5: DeleteGroup

        public MessageResultDto DeleteGroup(Guid id)
        {
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<Group> groupRepository = new Repository<Group>(session);
                var group = groupRepository.FindOne(id);
                if (group.Users.Count > 0)
                {
                    result.ErrorMessage("Group has got users registered. Please remove the user(s) from the group first.");
                }
                else
                {
                    groupRepository.Delete(id);
                    transaction.Commit();
                    result.Message = "Group deleted successfully";
                }
            }
            return result;
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:22,代码来源:GroupStorageProxy.cs

示例6: NhibernateDatabaseContext

        public NhibernateDatabaseContext()
        {
            SessionFactory = CreateSessionFactory();

            using (ISession session = SessionFactory.OpenSession())
            using (var transaction = session.BeginTransaction())
            {
                var groupRepository = new Repository<Group>(session);

                var group = groupRepository.FindOne(x => x.Name == _groupName);

                if (group == null)
                {
                    group = new Group
                    {
                        Name = _groupName,
                        IsSysAccount = true,
                    };

                    var user = new User
                    {
                        FirstName = "System",
                        LastName = "Administrator",
                        Username = "admin",
                        Nickname = "SuperAdmin",
                        Password = "@dm1n",
                        Group = group,
                    };

                    groupRepository.Add(group);
                    (new Repository<User>(session)).Add(user);

                    transaction.Commit();
                }
            }
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:36,代码来源:NhibernateDatabaseContext.cs

示例7: AddUser

        public MessageResultDto AddUser(string firstname, string lastname, string nickname, string username, Guid groupId)
        {
            User user;
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<Group> groupRepository = new Repository<Group>(session);
                var group = groupRepository.FindOne(x => x.Id == groupId);

                IRepository<User> userRepository = new Repository<User>(session);
                var existingUser = userRepository.FindOne(new Tuple<Expression<Func<User, object>>, string>(x => x.Username, username));

                if (null == existingUser)
                {
                    user = new User
                    {
                        FirstName = firstname,
                        LastName = lastname,
                        Nickname = nickname,
                        Username = username,
                        Password = Constants.DEFAULT_PASSWORD,
                        Group = group
                    };
                    userRepository.Add(user);
                    transaction.Commit();
                    result.SuccessMessage("User added successfully", user.Id);
                }
                else
                {
                    result.ErrorMessage("User with same username already exists");
                }
            }
            return result;
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:36,代码来源:UserStorageProxy.cs

示例8: Delete

        public string Delete(string operatorID)
        {
            AjaxResult ajaxResult = new AjaxResult();

            string errorMsg = string.Empty;
            DoResult doResult = DoResult.Failed;
            string actionMessage = string.Empty;
            try
            {
                if (!string.IsNullOrWhiteSpace(operatorID))
                {
                    IRepository<string> repository = new Repository<string>();

                    UnitOfWork.ExecuteWithTrans<Operator>(() =>
                        {
                            repository.Delete<Operator>(operatorID);

                            IDictionary<string, object> parameters = new Dictionary<string, object>();
                            parameters.SafeAdd("OperatorID", operatorID);
                            Employee employee = repository.FindOne<Employee>(parameters);
                            repository.Delete<Employee>(parameters);

                            parameters.Clear();
                            parameters.SafeAdd("EmployeeID", employee.ID);
                            repository.Delete<EmployeeOrg>(parameters);

                            parameters.Clear();
                            parameters.SafeAdd("ObjectID", operatorID);
                            repository.Delete<ObjectRole>(parameters);
                        });


                    doResult = DoResult.Success;

                    //获取提示信息
                    actionMessage = RemarkAttribute.GetEnumRemark(doResult);

                    ajaxResult.RetValue = CurrentId;
                    ajaxResult.PromptMsg = actionMessage;
                }

                ajaxResult.Result = doResult;
            }
            catch (Exception ex)
            {
                actionMessage = RemarkAttribute.GetEnumRemark(doResult);
                log.Error(actionMessage, ex);
            }

            return JsonConvert.SerializeObject(ajaxResult);
        }
开发者ID:AgileEAP,项目名称:WebStack,代码行数:51,代码来源:OrgUserList.aspx.cs

示例9: UpdateUser

        public MessageResultDto UpdateUser(Guid id, string firstname, string lastname, string nickname, string username, string password, Guid groupId)
        {
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<User> userRepository = new Repository<User>(session);
                var user = userRepository.FindOne(x => x.Id == id);

                if (user.Group.Id == groupId)
                {
                    IRepository<Group> groupRepository = new Repository<Group>(session);
                    var group = groupRepository.FindOne(x => x.Id == groupId);
                    user.Group = group;
                }

                user.FirstName = firstname;
                user.LastName = lastname;
                user.Nickname = nickname;
                user.Username = username;
                user.Password = password;

                userRepository.Add(user);

                transaction.Commit();
            }
            return result;
        }
开发者ID:SadiqAhmed,项目名称:MyNotes,代码行数:29,代码来源:UserStorageProxy.cs

示例10: ValidateUser

        public LoggedUserInfoDto ValidateUser(string username, string password)
        {
            LoggedUserInfoDto userDto = null;

            using (ISession session = _sessionFactory.OpenSession())
            {
                IRepository<User> userRepository = new Repository<User>(session);
                var user = userRepository.FindOne(x => x.Username == username && x.Password == password);
                userDto = Mapper.Map<LoggedUserInfoDto>(user);
            }

            return userDto;
        }
开发者ID:SadiqAhmed,项目名称:MyNotes,代码行数:13,代码来源:UserStorageProxy.cs

示例11: ResetPassword

        public MessageResultDto ResetPassword(Guid id)
        {
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<User> userRepository = new Repository<User>(session);
                var user = userRepository.FindOne(id);
                user.Password = Constants.DEFAULT_PASSWORD;
                transaction.Commit();
                result.Message = "Password has been reset successfully";
            }
            return result;
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:15,代码来源:UserStorageProxy.cs

示例12: LockedStatus

        public MessageResultDto LockedStatus(Guid id, bool isLocked)
        {
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<User> userRepository = new Repository<User>(session);
                var user = userRepository.FindOne(id);
                user.IsLocked = isLocked ;
                transaction.Commit();
                result.Message = string.Format("User has been {0} successsfully", isLocked ? "locked" : "unlocked");
            }
            return result;
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:15,代码来源:UserStorageProxy.cs

示例13: GetSingle

        public UserDto GetSingle(Guid id)
        {
            UserDto userDto = null;

            using (ISession session = _sessionFactory.OpenSession())
            {
                IRepository<User> userRepository = new Repository<User>(session);
                var user = userRepository.FindOne(id);
                userDto = Mapper.Map<UserDto>(user);
            }

            return userDto;
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:13,代码来源:UserStorageProxy.cs

示例14: GetSingle

        public GroupDto GetSingle(Guid id)
        {
            GroupDto groupDto = null;

            using (ISession session = _sessionFactory.OpenSession())
            {
                IRepository<Group> groupRepository = new Repository<Group>(session);
                var group = groupRepository.FindOne(id);
                groupDto = Mapper.Map<GroupDto>(group);
            }

            return groupDto;
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:13,代码来源:GroupStorageProxy.cs

示例15: UpdateGroup

        public MessageResultDto UpdateGroup(Guid id, string name)
        {
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                IRepository<Group> groupRepository = new Repository<Group>(session);
                var existingGroup = groupRepository.FindOne(x => x.Id != id, new Tuple<Expression<Func<Group, object>>, string>(x => x.Name, name));

                if (null == existingGroup)
                {
                    var group = groupRepository.FindOne(x => x.Id == id);
                    group.Name = name;
                    groupRepository.Update(group);
                    transaction.Commit();
                    result.SuccessMessage("Group updated successfully", group.Id);
                }
                else
                {
                    result.ErrorMessage("Group with same name already exisits");
                }
            }
            return result;
        }
开发者ID:avijassra,项目名称:MyNotes,代码行数:25,代码来源:GroupStorageProxy.cs


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