Exemplo n.º 1
0
        public async Task <ActionResult <BaseResponse> > AddRole(string GroupId, [FromBody] RoleAddDto req)
        {
            string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value;
            var    rm      = await _rs.AddRoleAsync(req, Account, GroupId);

            return(rm);
        }
Exemplo n.º 2
0
        public async Task AddRoleAsyncTest()
        {
            var addRoleDto = new AddRoleDto
            {
                Name = DefaultApplicationRoles.Basic
            };
            var rs = await _roleService.AddRoleAsync(addRoleDto);

            Assert.AreEqual(true, rs.Succeeded);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddRole([FromBody] RoleDto roleToAdd)
        {
            var result = await _roleService.AddRoleAsync(roleToAdd);

            if (!result.Succeeded)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Exemplo n.º 4
0
        public async Task <ResultModel> AddRole(AddRoleRequestModel requestModel)
        {
            try
            {
                var model = _mapper.Map <AddRoleModel>(requestModel);
                await _roleService.AddRoleAsync(model);

                return(ResultModel.Success("添加成功"));
            }
            catch (InvalidOperationException ex)
            {
                return(ResultModel.Fail(ex.Message));
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AddRole([FromBody] RoleDetail role)
        {
            var result = await _roleService.AddRoleAsync(role);

            if (result)
            {
                return(Ok());
            }
            else
            {
                ModelState.AddModelError("RoleName", ErrorMessages.WebAdmin_Role_E001);
                return(BadRequest(ModelState));
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> SaveRoleAsync(AppRoleViewModel appRoleVM)
        {
            if (string.IsNullOrEmpty(appRoleVM.id.ToString()))
            {
                var rs = await _roleService.AddRoleAsync(appRoleVM);

                return(new OkObjectResult(rs));
            }
            else
            {
                var rs = await _roleService.UpdateRoleAsync(appRoleVM);

                return(new OkObjectResult(rs));
            }
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Add(AddRoleDto addRoleDto)
        {
            if (!ModelState.IsValid)
            {
                return(View(addRoleDto));
            }
            var rs = await _roleService.AddRoleAsync(addRoleDto);

            if (rs.Succeeded)
            {
                return(RedirectToAction("Index", "Role",
                                        new { area = "Admin", id = rs.Data, succeeded = rs.Succeeded, message = rs.Message }));
            }
            ModelState.AddModelError(string.Empty, rs.Message);
            return(View(addRoleDto));
        }
Exemplo n.º 8
0
        public RoleMutation(IRoleService service)
        {
            Name = "RoleMutation";

            Field <UserGraphType>(
                "createRole",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <InputUserGraphType> > {
                Name = "role"
            }
                    ),
                resolve: context =>
            {
                var role = context.GetArgument <Role>("role");
                return(service.AddRoleAsync(role));
            });
        }
        public async Task <IdentityResult> Handle(CreateOrUpdateRoleCommand request, CancellationToken cancellationToken)
        {
            IdentityResult result;

            try
            {
                result = await _roleService.AddRoleAsync(request);

                await _unitOfWork.CommitAsync();
            }
            catch (Exception)
            {
                await _unitOfWork.RollbackAsync();

                throw;
            }
            return(result);
        }
        public async Task <ActionResult> CreateOrUpdateRole([FromBody] CreateOrUpdateRoleInput input)
        {
            IdentityResult identityResult;

            if (input.Role.Id == Guid.Empty)
            {
                identityResult = await _roleService.AddRoleAsync(input);
            }
            else
            {
                identityResult = await _roleService.EditRoleAsync(input);
            }

            if (identityResult.Succeeded)
            {
                return(Ok());
            }

            return(BadRequest(identityResult.Errors.Select(e => new NameValueDTO(e.Code, e.Description))));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> RoleAdd(RoleEditViewModel viewModel)
        {
            BaseResponse response = null;

            switch (viewModel.ActionType)
            {
            case Core.Enum.ActionType.Create:
                response = await _roleService.AddRoleAsync(viewModel);

                break;

            case Core.Enum.ActionType.Edit:
                response = await _roleService.EditRoleAsync(viewModel);

                break;

            default:
                response = new BaseResponse(System.Net.HttpStatusCode.OK, false, "ActionType錯誤");
                break;
            }
            return(Json(response));
        }
Exemplo n.º 12
0
        public async Task <ActionResult> AddOrUpdateRole(RoleDto data)
        {
            var res = new Role();

            if (data != null)
            {
                var mappedItem = _mapper.Map <RoleDto, Role>(data);
                if (mappedItem.Id > 0)
                {
                    res = await _roleSVC.EditRoleAsync(mappedItem);
                }
                else
                {
                    var roles = await _roleSVC.GetManyRolesAsync(r => r.RoleName.ToLower().Equals(data.RoleName.ToLower()));

                    if (roles.ToList().Count() == 0)
                    {
                        res = await _roleSVC.AddRoleAsync(mappedItem);
                    }
                }
            }
            return(new JsonResult(new { Response = res.Id }));
        }
Exemplo n.º 13
0
 // Create Roles
 public async Task <ISingleResponse <RoleModel> > AddRoleAsync(RoleModel details)
 {
     return(await _roleService.AddRoleAsync(details));
 }
Exemplo n.º 14
0
 public async Task <IResponseOutput> AddRoleAsync(RoleSaveDto dto)
 {
     return(await _roleService.AddRoleAsync(dto));
 }
Exemplo n.º 15
0
        public async Task <IActionResult> AddRole([FromBody] RoleViewModel model)
        {
            await _roleService.AddRoleAsync(model);

            return(CreatedAtAction("GetRoles", new { id = model.RoleId }));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> AddRoleAsync(Roles model)
        {
            var result = await _roleService.AddRoleAsync(model);

            return(Ok(result));
        }