コード例 #1
0
        public void Create(AspNetUserModel model, out string id)
        {
            try
            {
                _unitOfWork.BeginTransaction();

                id = "";

                var passwordHash = new PasswordHasher();
                var password     = passwordHash.HashPassword(model.Password);

                var entity = Mapper.Map <AspNetUserModel, AspNetUser>(model);
                entity.PasswordHash  = password;
                entity.SecurityStamp = Guid.NewGuid().ToString();
                entity.Id            = Guid.NewGuid().ToString();
                _repository.Insert(entity);

                /*var repository = _repository.GetRepository<IdentityUserRole>();
                 * var reposRole = _repository.GetRepository<AspNetRole>();
                 * repository.Insert(new IdentityUserRole()
                 * {
                 *  UserId = entity.Id,
                 *  RoleId = reposRole.Find(c=> c.Name == model.RoleName).Id
                 * });*/

                id = entity.Id;

                _unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback();
                throw new Exception(ex.Message);
            }
        }