Exemple #1
0
        public async Task SaveForm(UserEntity entity)
        {
            var db = await this.BaseRepository().BeginTrans();

            try
            {
                if (entity.Id.IsNullOrZero())
                {
                    await entity.Create();

                    await db.Insert(entity);
                }
                else
                {
                    await db.Delete <UserBelongEntity>(t => t.UserId == entity.Id);

                    // 密码不进行更新,有单独的方法更新密码
                    entity.Password = null;
                    await entity.Modify();

                    await db.Update(entity);
                }
                // 职位
                if (!string.IsNullOrEmpty(entity.PositionIds))
                {
                    foreach (long positionId in TextHelper.SplitToArray <long>(entity.PositionIds, ','))
                    {
                        UserBelongEntity positionBelongEntity = new UserBelongEntity();
                        positionBelongEntity.UserId     = entity.Id;
                        positionBelongEntity.BelongId   = positionId;
                        positionBelongEntity.BelongType = UserBelongTypeEnum.Position.ParseToInt();
                        await positionBelongEntity.Create();

                        await db.Insert(positionBelongEntity);
                    }
                }
                // 角色
                if (!string.IsNullOrEmpty(entity.RoleIds))
                {
                    foreach (long roleId in TextHelper.SplitToArray <long>(entity.RoleIds, ','))
                    {
                        UserBelongEntity departmentBelongEntity = new UserBelongEntity();
                        departmentBelongEntity.UserId     = entity.Id;
                        departmentBelongEntity.BelongId   = roleId;
                        departmentBelongEntity.BelongType = UserBelongTypeEnum.Role.ParseToInt();
                        await departmentBelongEntity.Create();

                        await db.Insert(departmentBelongEntity);
                    }
                }
                await db.CommitTrans();
            }
            catch
            {
                await db.RollbackTrans();

                throw;
            }
        }
Exemple #2
0
        public async Task <TData <string> > SaveForm(UserBelongEntity entity)
        {
            var obj = new TData <string>();
            await _userBelongService.SaveForm(entity);

            obj.Data = entity.Id.ParseToString();
            obj.Tag  = 1;
            return(obj);
        }
        public async Task SaveUserPositions(long userId, List <long> pIds)
        {
            foreach (var pId in pIds.Distinct())
            {
                var entity = new UserBelongEntity();
                entity.UserId     = userId;
                entity.BelongId   = pId;
                entity.BelongType = UserBelongTypeEnum.Position.ParseToInt();

                await SaveForm(entity);
            }
        }
        public async Task SaveUserRoles(long userId, List <long> roleIds)
        {
            foreach (var roleId in roleIds.Distinct())
            {
                var entity = new UserBelongEntity();
                entity.UserId     = userId;
                entity.BelongId   = roleId;
                entity.BelongType = UserBelongTypeEnum.Role.ParseToInt();

                await SaveForm(entity);
            }
        }
        public async Task SaveForm(UserBelongEntity entity)
        {
            if (entity.Id.IsNullOrZero())
            {
                await entity.Create();

                await this.BaseRepository().Insert(entity);
            }
            else
            {
                await this.BaseRepository().Update(entity);
            }
        }
 public async Task SaveForm(UserBelongEntity entity)
 {
     if (entity.Id.IsNullOrZero())
     {
         // 默认赋值
         entity.Id         = IdGeneratorHelper.Instance.GetId();
         entity.CreatorId  = NetHelper.HttpContext.User.FindFirstValue("UserId").ParseToLong();
         entity.CreateTime = DateTime.Now;
         await _userBelongEntityDB.InsertNowAsync(entity);
     }
     else
     {
         await _userBelongEntityDB.UpdateNowAsync(entity, ignoreNullValues : true);
     }
 }
        public async Task <List <UserBelongEntity> > GetList(UserBelongEntity entity)
        {
            var expression = LinqExtensions.True <UserBelongEntity>();

            if (entity != null)
            {
                if (entity.BelongType != null)
                {
                    expression = expression.And(t => t.BelongType == entity.BelongType);
                }
                if (entity.UserId != null)
                {
                    expression = expression.And(t => t.UserId == entity.UserId);
                }
            }
            var list = await this.BaseRepository().FindList(expression);

            return(list.ToList());
        }