Example #1
0
        public async Task <IActionResult> Put(int id, [FromBody] RoleDetailsDto model)
        {
            var roleId         = id;
            var roleDetailsDto = model;

            var role = await Executor.GetQuery <GetRoleByIdQuery>().Process(q => q.ExecuteAsync(roleId));

            Mapper.Map(roleDetailsDto, role);

            try
            {
                Executor.CommandChain()
                .AddCommand <UpdateRoleCommand>(c => c.Execute(role))
                .AddCommand <UpdateRoleClaimsCommand>(c => c.Execute(role, roleDetailsDto.Permissions))
                .ExecuteAllWithTransaction();

                Executor.GetHandler <UpdateRoleRouteStagesHandler>()
                .Process <int>(h => h.Execute(roleId, roleDetailsDto.RoleStages));
            }
            catch (Exception e)
            {
                throw new DatabaseException(e.InnerException?.Message ?? e.Message);
            }

            return(NoContent());
        }
Example #2
0
        public async Task <IActionResult> Put(int id, [FromBody] RoleDetailsDto model)
        {
            await _mediator.Send(new Update.Command {
                RoleDetailsDto = model, RoleId = id
            });

            return(NoContent());
        }
Example #3
0
        public async Task ExecuteAsync(RoleDetailsDto roleDetailsDto)
        {
            var role = _mapper.Map <ApplicationRole>(roleDetailsDto);

            NormalizeRoleCode(role);
            try
            {
                var resultOfRoleCreated = await _roleManager.CreateAsync(role);

                if (resultOfRoleCreated.Succeeded == false)
                {
                    throw new ValidationException(string.Join(", ", resultOfRoleCreated.Errors.Select(x => x.Description)));
                }

                await _roleClaimsUpdater.UpdateAsync(role, roleDetailsDto.Permissions);

                await _roleRouteStagesUpdater.UpdateAsync(role.Id, roleDetailsDto.RoleStages);
            }
            catch (Exception e)
            {
                throw new DatabaseException(e.InnerException?.Message ?? e.Message);
            }
        }
Example #4
0
        public async Task <IActionResult> Post([FromBody] RoleDetailsDto model)
        {
            await _mediator.Send(new Create.Command(model));

            return(NoContent());
        }
Example #5
0
        public async Task <IActionResult> Post([FromBody] RoleDetailsDto model)
        {
            await Executor.GetHandler <CreateRoleHandler>().Process(h => h.ExecuteAsync(model));

            return(NoContent());
        }
Example #6
0
 private void MapFromDto(Domain.Entities.Security.ApplicationRole role, RoleDetailsDto roleDto)
 {
     _mapper.Map(roleDto, role);
 }
Example #7
0
 private Domain.Entities.Security.ApplicationRole MapFromDto(RoleDetailsDto roleDto)
 {
     return(_mapper.Map <Domain.Entities.Security.ApplicationRole>(roleDto));
 }
Example #8
0
 public Command(RoleDetailsDto roleDetailsDto)
 {
     RoleDetailsDto = roleDetailsDto;
 }