Exemple #1
0
        public IActionResult SavePermission(RoleDto model)
        {
            int id;
            var message = string.Empty;

            UpdateAuditInformation(model);
            var entity = new ApplicationRoleDto {
                ApplicationId = model.ApplicationId, RoleId = model.Id
            };

            if (!ModelState.IsValid)
            {
                message = ModelState.Values.Aggregate(message, (current1, modelState) => modelState.Errors.Aggregate(current1, (current, error) => current + error));
                return(Json(new { success = false, message }));
            }

            foreach (var fullaccessId in model.LinkedFullAccessRolePermissionsIds)
            {
                int.TryParse(fullaccessId, out id);
                entity.RolePermissions.Add(new PermissionDto {
                    AccessLevel = AccessLevel.Full, MenuItemId = id
                });
            }
            foreach (var readonlyRoleId in model.LinkedReadonlyRolePermissionsIds)
            {
                int.TryParse(readonlyRoleId, out id);
                entity.RolePermissions.Add(new PermissionDto {
                    AccessLevel = AccessLevel.Readonly, MenuItemId = id
                });
            }
            model.ApplicationRoles.Add(entity);
            model   = _employeeFacadeApiClient.PutRole(model.Id, model).Result;
            message = string.IsNullOrWhiteSpace(model.ErrorMessage) ? model.SuccessMessage : model.ErrorMessage;
            return(Json(new { success = string.IsNullOrWhiteSpace(model.ErrorMessage), message }));
        }