コード例 #1
0
        public string ResetPassword(Int32 userID)
        {
            IUnitOfWork        unitOfWork = SessionFactory.GetUnitOfWork;
            IRepository <User> repository = new Repositor <User>(unitOfWork);

            try
            {
                unitOfWork.BeginTransaction();
                var u = repository.Single(c => c.UserID == userID);
                PasswordGenerator generator = new PasswordGenerator(10, u.UserName);
                u.UserPassword = generator.Hash;
                repository.Update(u);
                unitOfWork.CommitTransaction();
                return(generator.Password);
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }
コード例 #2
0
        public Objects.User AddUser(Objects.User user)
        {
            IUnitOfWork        unitOfWork     = SessionFactory.GetUnitOfWork;
            IRepository <User> repository     = new Repositor <User>(unitOfWork);
            IRepository <Role> repositoryRole = new Repositor <Role>(unitOfWork);

            try
            {
                ObjectValidator.IsValid(user);
                PasswordGenerator generator = new PasswordGenerator(10, user.Name);
                user.Password = generator.Password;
                User u = new User();
                u.UserName         = String.IsNullOrWhiteSpace(user.Name) ? null : user.Name;
                u.UserPassword     = generator.Hash;
                u.UserWorkerID     = user.WorkerID;
                u.UserDetachmentID = user.DetachmentID;
                u.UserDescription  = String.IsNullOrWhiteSpace(user.Description) ? null : user.Description;
                if (user.Roles != null)
                {
                    foreach (var item in user.Roles)
                    {
                        var r = repositoryRole.Single(c => c.RoleID == item.ID);
                        u.Roles.Add(r);
                    }
                }
                unitOfWork.BeginTransaction();
                repository.Add(u);
                unitOfWork.CommitTransaction();
                user.ID = u.UserID;
                return(user);
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }