Exemple #1
0
        public async Task <ActionResponse> EditUserRightsByNames(string userId, string[] roles, string[] functions, string[] accessedRights,
                                                                 string[] deniedRights)
        {
            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    return(new ActionResponse
                    {
                        Message = "Wrong id",
                        Status = ActionStatus.Warning
                    });
                }

                roles          = roles ?? new string[0];
                functions      = functions ?? new string[0];
                accessedRights = accessedRights ?? new string[0];
                deniedRights   = deniedRights ?? new string[0];

                if (accessedRights.Intersect(deniedRights).Any())
                {
                    return(new ActionResponse
                    {
                        Status = ActionStatus.Warning,
                        Message = "Accessed and denied must not have same Rights"
                    });
                }

                await _securityContext.EditUserRightsByNames(userId, roles,
                                                             functions,
                                                             accessedRights,
                                                             deniedRights);

                return(new ActionResponse
                {
                    Status = ActionStatus.Success
                });
            }
            catch (SecurityDbException e)
            {
                return(new ActionResponse
                {
                    Status = ActionStatus.Warning,
                    Message = PrettyExceptionHelper.GetMessage(e)
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ActionResponse
                {
                    Status = ActionStatus.Error,
                    Message = "Something went wrong!"
                });
            }
        }