示例#1
0
        public async Task <BizServiceResponse> EditAsync(AddOrEditRoleVO vo, Guid currentUserId, string currentUserName)
        {
            var existRole = await roleRepository.FirstOrDefaultAsync(new FindRoleSpecification(code : vo.Code));

            if (existRole == null)
            {
                return(new BizServiceResponse(BizServiceResponseCode.Failed, "不存在该角色"));
            }

            var now = DateTime.UtcNow;

            existRole.Name           = vo.Name;
            existRole.Description    = vo.Description;
            existRole.Status         = vo.Status;
            existRole.ModifiyUserId  = currentUserId;
            existRole.ModifyTime     = now;
            existRole.ModifyUserName = currentUserName;

            var addResult = await roleRepository.UpdateAsync(existRole);

            if (addResult)
            {
                return(new BizServiceResponse(BizServiceResponseCode.Success, "添加角色成功"));
            }
            else
            {
                return(new BizServiceResponse(BizServiceResponseCode.Failed, "添加角色失败"));
            }
        }
示例#2
0
        public async Task <IActionResult> Edit(AddOrEditRoleVO vo)
        {
            var currentUserId   = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var currentUserName = User.FindFirstValue(ClaimTypes.Name);
            var result          = await _roleService.EditAsync(vo, new Guid(currentUserId), currentUserName);

            return(Json(result));
        }
示例#3
0
        public async Task <BizServiceResponse> AddAsync(AddOrEditRoleVO vo, Guid currentUserId, string currentUserName)
        {
            var existRole = await roleRepository.FirstOrDefaultAsync(new FindRoleSpecification(code : vo.Code));

            if (existRole != null)
            {
                return(new BizServiceResponse(BizServiceResponseCode.Failed, "已存在相同编码的角色"));
            }

            var now    = DateTime.UtcNow;
            var entity = new Role
            {
                Code   = vo.Code,
                Name   = vo.Name,
                Status = vo.Status,
                IsSuperAdministrator = false,
                Builtin          = false,
                CreateTime       = now,
                CreateUserGuidId = currentUserId,
                CreateUserName   = currentUserName,
                Description      = vo.Description,
                IsDeleted        = Enums.IsDeleted.No,
                ModifiyUserId    = currentUserId,
                ModifyTime       = now,
                ModifyUserName   = currentUserName,
            };
            var addResult = await roleRepository.AddAsync(entity);

            if (addResult == null)
            {
                return(new BizServiceResponse(BizServiceResponseCode.Failed, "添加角色失败"));
            }
            else
            {
                return(new BizServiceResponse(BizServiceResponseCode.Success, "添加角色成功"));
            }
        }