/*
         * 测试环境 需要在本地创建一个数据库  名称见app.config
         */

        /// <summary>
        /// 测试事务提交
        /// </summary>
        public static void AddTransactionScope()
        {
            User u = new User
            {
                Id              = Guid.NewGuid(),
                DepartmentId    = Guid.NewGuid(),
                Email           = "*****@*****.**",
                Enabled         = true,
                Mobile          = "1254555555",
                NickName        = "小久",
                Password        = "******",
                UserName        = "******",
                RegisterDate    = DateTime.Now,
                Remark          = string.Empty,
                IsAdministrator = false,
            };

            Role r = new Role
            {
                Name     = "sdsd",
                Id       = Guid.NewGuid(),
                Enabled  = true,
                ParentId = Guid.NewGuid(),
                Remark   = "sdsdsd"
            };

            UserRoleRelationship ur = new UserRoleRelationship
            {
                Id     = Guid.NewGuid(),
                RoleId = r.Id,
                UserId = u.Id
            };

            using (BaseRepository repository = PermissionService.Factory())
            {
                using (TransactionScope trans = new TransactionScope())
                {
                    try
                    {
                        repository.AddEntities(u);
                        repository.AddEntities(r);
                        repository.AddEntities(ur, true);
                        trans.Complete();
                    }
                    catch (Exception exception)
                    {
                        throw new Exception(exception.Message);
                    }
                    finally
                    {
                        trans.Dispose();
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 写入登陆日志
        /// </summary>
        /// <param name="u"></param>
        public void Add(user u)
        {
            QQWry.NET.QQWryLocator    qqWry = new QQWry.NET.QQWryLocator(System.Web.HttpContext.Current.Server.MapPath(Config.GetValue <string>("qqwry")));
            BaseRepository <loginlog> dal   = new BaseRepository <loginlog>();
            loginlog log = new loginlog();

            log.Uid     = u.Id;
            log.Ip      = ClientIp.GetClientIP();
            log.LogTime = DateTime.Now;
            log.Address = qqWry.Query(log.Ip).Country;
            dal.AddEntities(log);
        }
Exemplo n.º 3
0
        //添加
        public T AddEntities(T entity)
        {
            var addentity = IBR.AddEntities(entity);

            if (addentity != null)
            {
                return(addentity);
            }
            else
            {
                return(null);
            }
        }