public bool UpdateColumns(Expression <Func <Sys_AdminRole, object> > columns, Sys_AdminRole model, bool isLock = false)
 {
     return(_repository.UpdateColumns(columns, model, isLock) > 0);
 }
 public bool Update(Sys_AdminRole model)
 {
     throw new NotImplementedException();
 }
Exemple #3
0
 public int AddAdminRole(Sys_AdminRole role)
 {
     return(_dataAccess.AddEntity(role));
 }
 public int Insert(Sys_AdminRole model, bool isReturnId)
 {
     return(_repository.Insert(model, isReturnId));
 }
        public IActionResult UpdateRole([FromBody] FromUpdateRole model)
        {
            string code = "000000";

            if (_sysAdminRoleService.IsAny(p => p.Id == model.RoleId))
            {
                try
                {
                    var userId = GetJwtIEntity().UserId;
                    var now    = DateTime.Now;
                    //异步更新角色相关
                    Task.Run(() =>
                    {
                        var role         = new Sys_AdminRole();
                        role.Id          = model.RoleId;
                        role.RoleName    = model.RoleName;
                        role.Remark      = model.Remark;
                        role.IsForbidden = model.IsForbidden;
                        role.ModifyDate  = DateTime.Now;
                        _sysAdminRoleService.UpdateColumns(p => new { p.RoleName, p.Remark, p.IsForbidden, p.ModifyDate }, role, true);
                    });
                    //异步更新角色权限
                    if (model.MenuList.Where(p => p.Status == (int)RoleMenuStatus.update).Count() > 0)
                    {
                        Task.Run(() =>
                        {
                            var perList  = new List <Sys_AdminPermission>();
                            var menuList = model.MenuList.Where(p => p.Status == (int)RoleMenuStatus.update);

                            foreach (var item in menuList)
                            {
                                var perModel         = new Sys_AdminPermission();
                                perModel.Id          = item.PerId;
                                perModel.MenuId      = item.MenuId;
                                perModel.BtnJson     = item.BtnJson;
                                perModel.CrtDate     = now;
                                perModel.RoleId      = model.RoleId;
                                perModel.UserId      = userId;
                                perModel.CheckStatus = item.CheckStatus;
                                perList.Add(perModel);
                            }
                            _sysAdminPermissionService.UpdateList(perList, p => new { p.CheckStatus, p.UserId, p.CrtDate });
                        });
                    }
                    //异步添加角色权限
                    if (model.MenuList.Where(p => p.Status == (int)RoleMenuStatus.add).Count() > 0)
                    {
                        Task.Run(() =>
                        {
                            var perList  = new List <Sys_AdminPermission>();
                            var menuList = model.MenuList.Where(p => p.Status == (int)RoleMenuStatus.add);

                            foreach (var item in menuList)
                            {
                                var perModel = new Sys_AdminPermission();
                                //perModel.Id = item.PerId;
                                perModel.MenuId      = item.MenuId;
                                perModel.BtnJson     = item.BtnJson;
                                perModel.CrtDate     = now;
                                perModel.RoleId      = model.RoleId;
                                perModel.UserId      = userId;
                                perModel.Type        = item.Type;
                                perModel.CheckStatus = item.CheckStatus;
                                perList.Add(perModel);
                            }
                            _sysAdminPermissionService.InsertList(perList);
                        });
                    }
                    //异步删除角色权限
                    if (model.MenuList.Where(p => p.Status == (int)RoleMenuStatus.delete).Count() > 0)
                    {
                        Task.Run(() =>
                        {
                            var perList = model.MenuList.Where(p => p.Status == (int)RoleMenuStatus.delete).Select(p => p.PerId).ToArray();
                            _sysAdminPermissionService.DeleteByIdArray(perList);
                        });
                    }
                }
                catch (Exception ex)
                {
                    _log.LogError(ex.ToString());
                    code = "000100";
                }
            }
            else
            {
                code = "100007";
            }
            return(ReturnJson(code));
        }