Ejemplo n.º 1
0
        public IActionResult Permission(int id, List <int> menuIds)
        {
            var response = new ReponseOutPut();

            response.Code    = "success";
            response.Message = "分配权限成功";

            if (menuIds == null || menuIds.Count() <= 0)
            {
                return(new JsonResult(JsonConvert.SerializeObject(response)));
            }

            var role = new SysRole();

            role.Id               = id;
            role.LastUpdateBy     = _context.Admin.Id;
            role.LastUpdateByName = _context.Admin.UserName;
            role.LastUpdateDate   = DateTime.Now;

            var result = _roleService.UpdatePermission(role, menuIds);

            if (result < 0)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "error";
                response.Message = "分配权限失败";
            }
            return(new JsonResult(JsonConvert.SerializeObject(response)));
        }
Ejemplo n.º 2
0
        public IActionResult Add(MenuInput menuInputModel)
        {
            var response = new ReponseOutPut();
            //校验菜单系统名称是否存在
            var isExistSystermName = _menuService.ExistMenuByMenuSystermName(menuInputModel.MenuSystermName);

            if (isExistSystermName)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "menu_exsit_menuSystermName";
                response.Message = "菜单系统名称已存在";
                return(new JsonResult(JsonConvert.SerializeObject(response)));
            }

            SysMenu sysMenu = _mapper.Map <MenuInput, SysMenu>(menuInputModel);

            sysMenu.CreateBy         = _context.Admin.Id;
            sysMenu.CreatebyName     = _context.Admin.UserName;
            sysMenu.CreateDate       = DateTime.Now;
            sysMenu.LastUpdateBy     = _context.Admin.Id;
            sysMenu.LastUpdateByName = _context.Admin.UserName;
            sysMenu.LastUpdateDate   = sysMenu.CreateDate;


            if (menuInputModel.FirstParentMenuId <= 0)
            {
                sysMenu.ParentMenuId = 0;
            }
            else
            {
                if (menuInputModel.SecondParentMenuId <= 0)
                {
                    sysMenu.ParentMenuId = menuInputModel.FirstParentMenuId;
                }
                else
                {
                    if (menuInputModel.ThirdParentMenuId <= 0)
                    {
                        sysMenu.ParentMenuId = menuInputModel.SecondParentMenuId;
                    }
                    else
                    {
                        sysMenu.ParentMenuId = menuInputModel.ThirdParentMenuId;
                        sysMenu.MenuType     = MenuType.Function;//三级菜单选中,代表是功能
                    }
                }
            }
            var result = _menuService.AddMenu(sysMenu);

            if (result < 0)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "menu_add_error";
                response.Message = "新增菜单失败";
            }

            return(new JsonResult(JsonConvert.SerializeObject(response)));
        }
Ejemplo n.º 3
0
        public IActionResult Add(AdminInput param)
        {
            var response = new ReponseOutPut();

            response.Code    = "menu_add_success";
            response.Message = "新增账号成功";
            if (!ModelState.IsValid)
            {
                response.Status = ReutnStatus.Error;
                response.Code   = "param_vaild_error";

                var errorProperty = ModelState.Values.First(m => m.ValidationState == ModelValidationState.Invalid);
                response.Message = errorProperty.Errors.First().ErrorMessage;//验证不通过的 //全局配置一个验证不通过就不在验证了,只存在一个错误信息

                return(new JsonResult(JsonConvert.SerializeObject(response)));
            }

            // 检查用户名是否重复
            var isExistUserName = _adminService.ExistAdminUserName(param.UserName);

            if (isExistUserName)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "username_is_exist";
                response.Message = "用户名已经存在";
                return(new JsonResult(JsonConvert.SerializeObject(response)));
            }

            SysAdmin admin = _mapper.Map <AdminInput, SysAdmin>(param);

            admin.CreateBy         = _context.Admin.Id;
            admin.CreatebyName     = _context.Admin.UserName;
            admin.CreateDate       = DateTime.Now;
            admin.LastUpdateBy     = admin.CreateBy;
            admin.LastUpdateByName = admin.CreatebyName;
            admin.LastUpdateDate   = admin.CreateDate;



            var result = _adminService.AddAdmin(admin, param.RoleIds);

            if (result < 0)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "menu_add_error";
                response.Message = "新增账号失败";
            }

            return(new JsonResult(JsonConvert.SerializeObject(response)));
        }
Ejemplo n.º 4
0
        public IActionResult Delete(int id)
        {
            var response = new ReponseOutPut();
            var result   = _adminService.Delete(id);

            if (result < 0)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "error";
                response.Message = "删除账号失败";
            }

            return(new JsonResult(JsonConvert.SerializeObject(response)));
        }
Ejemplo n.º 5
0
        public IActionResult Delete(int id)
        {
            var result = _roleService.DeleteRoleById(id);

            var response = new ReponseOutPut();

            response.Code    = "role_delete_success";
            response.Message = "角色删除成功";
            if (result < 0)
            {
                response.Code    = "role_delete_error";
                response.Message = "角色删除失败";
            }
            return(new JsonResult(JsonConvert.SerializeObject(response)));
        }
Ejemplo n.º 6
0
        public IActionResult Add(RoleInput param)
        {
            var response = new ReponseOutPut();

            response.Code    = "role_add_success";
            response.Message = "新增角色成功";
            if (!ModelState.IsValid)
            {
                response.Status = ReutnStatus.Error;
                response.Code   = "param_vaild_error";

                var errorProperty = ModelState.Values.First(m => m.ValidationState == ModelValidationState.Invalid);
                response.Message = errorProperty.Errors.First().ErrorMessage;//验证不通过的 //全局配置一个验证不通过就不在验证了,只存在一个错误信息

                return(new JsonResult(JsonConvert.SerializeObject(response)));
            }

            // 检查用户名是否重复
            var isExistUserName = _roleService.ExistRoleName(param.RoleName);

            if (isExistUserName)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "rolename_is_exist";
                response.Message = "角色名称已经存在";
                return(new JsonResult(JsonConvert.SerializeObject(response)));
            }

            SysRole role = _mapper.Map <RoleInput, SysRole>(param);

            role.CreateBy         = _context.Admin.Id;
            role.CreatebyName     = _context.Admin.UserName;
            role.CreateDate       = DateTime.Now;
            role.LastUpdateBy     = role.CreateBy;
            role.LastUpdateByName = role.CreatebyName;
            role.LastUpdateDate   = role.CreateDate;

            var result = _roleService.AddRole(role, param.AdminIds);

            if (result < 0)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "role_add_error";
                response.Message = "新增角色失败";
            }

            return(new JsonResult(JsonConvert.SerializeObject(response)));
        }
Ejemplo n.º 7
0
        public IActionResult Edit(MenuInput param)
        {
            var response = new ReponseOutPut();

            response.Code    = "success";
            response.Message = "更新菜单成功";
            if (!ModelState.IsValid)
            {
                response.Status = ReutnStatus.Error;
                response.Code   = "param_vaild_error";

                var errorProperty = ModelState.Values.First(m => m.ValidationState == ModelValidationState.Invalid);
                response.Message = errorProperty.Errors.First().ErrorMessage;//验证不通过的 //全局配置一个验证不通过就不在验证了,只存在一个错误信息

                return(new JsonResult(JsonConvert.SerializeObject(response)));
            }

            //校验菜单系统名称是否存在
            var isExistSystermName = _menuService.ExistMenuByMenuSystermName(param.MenuSystermName, param.Id);

            if (isExistSystermName)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "menu_exsit_menuSystermName";
                response.Message = "菜单系统名称已存在";
                return(new JsonResult(JsonConvert.SerializeObject(response)));
            }

            SysMenu model = _mapper.Map <MenuInput, SysMenu>(param);

            model.LastUpdateBy     = _context.Admin.Id;
            model.LastUpdateByName = _context.Admin.UserName;
            model.LastUpdateDate   = DateTime.Now;


            if (param.FirstParentMenuId <= 0)
            {
                model.ParentMenuId = 0;
            }
            else
            {
                if (param.SecondParentMenuId <= 0)
                {
                    model.ParentMenuId = param.FirstParentMenuId;
                }
                else
                {
                    if (param.ThirdParentMenuId <= 0)
                    {
                        model.ParentMenuId = param.SecondParentMenuId;
                    }
                    else
                    {
                        model.ParentMenuId = param.ThirdParentMenuId;
                        model.MenuType     = MenuType.Function;//三级菜单选中,代表是功能
                    }
                }
            }

            var result = _menuService.Update(model);

            if (result < 0)
            {
                response.Status  = ReutnStatus.Error;
                response.Code    = "error";
                response.Message = "更新菜单失败";
            }
            return(new JsonResult(JsonConvert.SerializeObject(response)));
        }