Example #1
0
        public IActionResult AddSysUser([FromBody] FromAddSysUser model)
        {
            string code = "000000";
            var    user = AutoMapperExt.MapTo <Sys_User>(model);

            user.Password = Encrypt.EncryptPsw(user.Password);

            Log_Admin logAdmin = new Log_Admin();

            var now = DateTime.Now;

            if (_sysUserService.IsAny(p => p.UserName == user.UserName))
            {
                return(ReturnJson("100001"));
            }
            else
            {
                user.LastIp      = HttpContextExtension.GetIp(HttpContext);
                user.LastLogDate = now;
                user.CrtUser     = GetJwtIEntity().Name;
                user.CrtDate     = now;
                user.Id          = _sysUserService.Insert(user, false);

                if (user.Id > 0 && !string.IsNullOrEmpty(user.HeadImgUrl))
                {
                    //更改图片状态
                    _sysUploadService.UpdateUploadStatusAsync(UploadTypeEnum.image, user.HeadImgUrl, UploadStatusEnum.使用中);
                }

                if (user.Id > 0 && model.RoleList.Count > 0)
                {
                    //异步执行角色权限配置
                    Task.Run(() =>
                    {
                        var perList = new List <Sys_UserRole>();
                        foreach (var item in model.RoleList)
                        {
                            var perModel    = new Sys_UserRole();
                            perModel.RoleId = item.RoleId;
                            perModel.UserId = user.Id;
                            perList.Add(perModel);
                        }
                        _sysUserService.InsertList(perList);
                    });
                }
                else if (user.Id == 0)
                {
                    code = "000001";
                }

                logAdmin.Remark = "账号:" + user.UserName + "注册成功";

                logAdmin.TypeId = (int)EnumLogAdminType.add_sysUser;//添加用户时的类型Id
            }

            logAdmin.OtherId     = user.Id.ToString();
            logAdmin.CrtUserId   = GetJwtIEntity().UserId;
            logAdmin.CrtUserName = GetJwtIEntity().Name;
            _logAdmin.LogAdmin(logAdmin, HttpContext);
            return(ReturnJson(code));
        }
Example #2
0
        public IActionResult AddMenu([FromBody] FromAddMenu model)
        {
            var       sysAdminMenu = AutoMapperExt.MapTo <Sys_AdminMenu>(model);
            string    code         = "000000";
            Log_Admin logAdmin     = new Log_Admin();

            if (sysAdminMenu.Id == 0)
            {
                //新增
                var maxMenu = _sysAdminMenuService.GetEntity(p => p.Pid == sysAdminMenu.Pid, p => p.Id, true);
                if (maxMenu == null)
                {
                    var parentMenu = _sysAdminMenuService.GetEntityById(sysAdminMenu.Pid);
                    if (parentMenu != null)
                    {
                        sysAdminMenu.Orders = 1;
                        sysAdminMenu.Level  = parentMenu.Level + 1;
                    }
                    else
                    {
                        return(ReturnJson("100004"));
                    }
                }
                else
                {
                    sysAdminMenu.Orders = maxMenu.Orders + 1;
                    sysAdminMenu.Level  = maxMenu.Level;
                }
                sysAdminMenu.CrtUser = GetJwtIEntity().Name;
                sysAdminMenu.CrtDate = DateTime.Now;
                logAdmin.OtherId     = _sysAdminMenuService.Insert(sysAdminMenu).ToString();
            }
            else
            {
                var adminMenu = _sysAdminMenuService.GetEntityById(sysAdminMenu.Id);
                if (adminMenu != null)
                {
                    if (adminMenu.Orders != sysAdminMenu.Orders)
                    {
                        //修改排序
                        bool reuslt = _sysAdminMenuService.UpdateMenuOrders(sysAdminMenu.Orders, adminMenu);
                        if (!reuslt)
                        {
                            code = "000001";
                        }
                    }
                    //修改其他字段
                    if (!_sysAdminMenuService.UpdateColumns(p => new { p.Tag, p.Icon, p.IsShow, p.MenuName, p.Url }, sysAdminMenu))
                    {
                        return(ReturnJson("000001"));
                    }

                    logAdmin.OtherId = sysAdminMenu.Id.ToString();
                }
                else
                {
                    code = "100005";
                }
            }

            logAdmin.CrtUserId   = GetJwtIEntity().UserId;
            logAdmin.CrtUserName = GetJwtIEntity().Name;
            _logAdmin.LogAdmin(logAdmin, HttpContext);
            return(ReturnJson(code));
        }