コード例 #1
0
        public async Task <UserPermission> GetAllUserPermission(UserPermissionEmployeeIdDetails employeeIdDetails)
        {
            var userPermission = FindByCondition(x => x.EmployeeId == employeeIdDetails.EmployeeId)
                                 .SingleOrDefault();

            return(await Task.FromResult(userPermission));
        }
コード例 #2
0
        public async Task <List <int> > GetUserPermissionsByEmployeeId(UserPermissionEmployeeIdDetails userPermissionEmployeeIdDetails)
        {
            var userPermissions = FindByCondition(x => string.Equals(x.EmployeeId.Trim(), userPermissionEmployeeIdDetails.EmployeeId.Trim(), StringComparison.OrdinalIgnoreCase) && x.IsDeleted == false)
                                  .Select(x => x.Id)
                                  .ToList();

            return(await Task.FromResult(userPermissions));
        }
コード例 #3
0
        public async Task <UserPermission> GetUserPermission(UserPermissionEmployeeIdDetails userPermissionEmployeeIdDetails)
        {
            var userPermission = FindByCondition(x => x.EmployeeId == userPermissionEmployeeIdDetails.EmployeeId.ToString() && x.IsDeleted == false)
                                 .Include(x => x.Role)
                                 .SingleOrDefault();

            return(await Task.FromResult(userPermission));
        }
コード例 #4
0
        /// <summary>
        /// Deletes the userPermission.
        /// </summary>
        /// <param name="userPermissionEmployeeIdDetails">The userPermission identifier details.</param>
        /// <returns></returns>
        public async Task <CSSResponse> DeleteUserPermission(UserPermissionEmployeeIdDetails userPermissionEmployeeIdDetails)
        {
            var userPermission = await _repository.UserPermissions.GetUserPermission(userPermissionEmployeeIdDetails);

            if (userPermission == null)
            {
                return(new CSSResponse(HttpStatusCode.NotFound));
            }

            userPermission.IsDeleted = true;

            _repository.UserPermissions.UpdateUserPermission(userPermission);
            await _repository.SaveAsync();

            return(new CSSResponse(HttpStatusCode.NoContent));
        }
コード例 #5
0
        /// <summary>
        /// Gets the userPermission.
        /// </summary>
        /// <param name="userPermissionEmployeeIdDetails">The userPermission identifier details.</param>
        /// <returns></returns>
        public async Task <CSSResponse> GetUserPermission(UserPermissionEmployeeIdDetails userPermissionEmployeeIdDetails)
        {
            var userPermission = await _repository.UserPermissions.GetUserPermission(userPermissionEmployeeIdDetails);

            if (userPermission == null)
            {
                // call the agent admins api to check if the user exists on agent admins
                HttpClient client = new HttpClient();
                var        apiUrl = _config.GetValue <string>("GlobalConfiguration:GatewayUrl");
                client.BaseAddress = new Uri(apiUrl);
                var urlParameters = $"agentadmins/employees/{userPermissionEmployeeIdDetails.EmployeeId}";

                // Add an Accept header for JSON format.
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = client.GetAsync(urlParameters).Result;

                if (response.IsSuccessStatusCode)
                {
                    string responseStream = await response.Content.ReadAsStringAsync();

                    UserPermissionAgent agentPermission = JsonConvert.DeserializeObject <UserPermissionAgent>(responseStream);
                    // map the response to new userPermission intended for agents
                    userPermission = new UserPermission {
                        EmployeeId = agentPermission.EmployeeId, Firstname = agentPermission.Firstname, Lastname = agentPermission.Lastname, Sso = agentPermission.Sso
                    };
                }
                else
                {
                    return(new CSSResponse(HttpStatusCode.NotFound));
                }
            }

            var mappedPermission = _mapper.Map <UserPermissionDTO>(userPermission);

            return(new CSSResponse(mappedPermission, HttpStatusCode.OK));
        }
コード例 #6
0
        /// <summary>
        /// Updates the userPermission.
        /// </summary>
        /// <param name="userPermissionEmployeeIdDetails">The userPermission identifier details.</param>
        /// <param name="userPermissionDetails">The userPermission details.</param>
        /// <returns></returns>
        public async Task <CSSResponse> UpdateUserPermission(UserPermissionEmployeeIdDetails userPermissionEmployeeIdDetails, UpdateUserPermissionDTO userPermissionDetails)
        {
            UserPermission userPermission = await _repository.UserPermissions.GetUserPermission(userPermissionEmployeeIdDetails);

            if (userPermission == null)
            {
                return(new CSSResponse(HttpStatusCode.NotFound));
            }

            if (userPermission.Sso != userPermissionDetails.Sso)
            {
                var userPermissions = await _repository.UserPermissions.GetUserPermissionsBySso(new UserPermissionSsoDetails { Sso = userPermissionDetails.Sso });

                if (userPermissions?.Count > 0 && userPermissions.IndexOf(userPermission.Id) == -1)
                {
                    return(new CSSResponse($"User Permission with sso '{userPermissionDetails.Sso}' already exists.", HttpStatusCode.Conflict));
                }
            }

            if (userPermission.EmployeeId != userPermissionDetails.EmployeeId)
            {
                var userPermissions = await _repository.UserPermissions.GetUserPermissionsByEmployeeId(new UserPermissionEmployeeIdDetails { EmployeeId = userPermissionDetails.EmployeeId });

                if (userPermissions?.Count > 0 && userPermissions.IndexOf(userPermission.Id) == -1)
                {
                    return(new CSSResponse($"User Permission with employeeId '{userPermissionDetails.EmployeeId}' already exists.", HttpStatusCode.Conflict));
                }
            }


            var userPermissionRequest = _mapper.Map(userPermissionDetails, userPermission);

            _repository.UserPermissions.UpdateUserPermission(userPermissionRequest);

            await _repository.SaveAsync();

            return(new CSSResponse(HttpStatusCode.NoContent));
        }