Exemple #1
0
        public async Task <IActionResult> PostAdd([FromBody] Role value)
        {
            try
            {
                _logger.LogDebug("Inserting role");
                bool success = await _roleService.AddAsync(value);

                if (success)
                {
                    _logger.LogDebug("Roles insert operation success.");
                    return(Ok("Role created successfully"));
                }
                else
                {
                    _logger.LogDebug("Roles insert operation failed. Duplicate role.");
                    return(Conflict("Duplicate Role"));
                }
            }
            catch (Exception ex)
            {
                //log
                _logger.LogError("An Exception occured: {ex}", ex.Message);
                _logger.LogError("Stack Trace: {ex}", ex.StackTrace);
                return(BadRequest());
            }
        }
        public async Task <IActionResult> Add(AddOrEditRoleVO vo)
        {
            var currentUserId   = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var currentUserName = User.FindFirstValue(ClaimTypes.Name);
            var result          = await _roleService.AddAsync(vo, new Guid(currentUserId), currentUserName);

            return(Json(result));
        }
        protected async Task HandleValidSubmit()
        {
            Role = IsNew ? await RoleService.AddAsync(Role) : await RoleService.UpdateAsync(Role.Id, Role);

            await JsRuntime.InvokeAsync <object>("HideModal", "roleModal");

            await CloseEventCallback.InvokeAsync(true);

            StateHasChanged();
        }
        public async Task <IActionResult> Create(RoleDetailViewModel model)
        {
            if (ModelState.IsValid)
            {
                var permissionList = model.Permissions?.Split(',') ?? new string[] { };
                var role           = await _roleService.AddAsync(model.Role, permissionList);

                ShowAlertSuccess($"Added Role \"{role.Name}\"!");
                return(RedirectToAction(nameof(Edit), new { id = role.Id }));
            }

            model.UnselectedPermissions = (await _roleService.GetAllPermissionsAsync())
                                          .Except(model.SelectedPermissions);

            PageTitle = "Create Role";
            return(View("Detail", model));
        }
Exemple #5
0
        public async Task <IHttpActionResult> PostRole(IdentityRolePostModel role)
        {
            var newRole = await RoleService.AddAsync(role);

            return(CreatedAtRoute("RoleRoute", new { id = newRole.Id }, newRole));
        }