Exemple #1
0
        public async Task <RoleSearchResponse> Search(RoleSearchRequest request)
        {
            RoleSearchResponse response = new RoleSearchResponse();

            try
            {
                RefSqlPaging paging = new RefSqlPaging(request.PageIndex, 30);
                RRole[]      roles  = await _roleService.RoleSearch(request.Name, request.Status, request.DepartmentId, paging);

                var departments = await _roleService.DepartmentSearchFromDb(string.Empty, 0, new RefSqlPaging(0, Int32.MaxValue));

                if (roles != null && roles.Length > 0)
                {
                    //    RDepartment[] departments = await _roleService.DepartmentGetFromDb(roles.Select(p => p.Id).ToArray());
                    response.Roles = roles.Select(p => p.ToModel(departments.FirstOrDefault(q => q.Id == p.DepartmentId))).ToArray();
                }
                else
                {
                    response.Roles = new RoleViewModel[0];
                }
                response.Departments = departments.Select(p => p.ToKeyValueTypeStringModel()).ToArray();
                response.SetSucess();
            }
            catch (Exception e)
            {
                response.SetFail(e);
                _logger.LogError(e, e.Message, request);
            }
            return(response);
        }
        public RoleSearchResponse SearchRoles(RoleSearchRequest request)
        {
            request = request ?? new RoleSearchRequest();
            var result = new RoleSearchResponse();

            using (var repository = _platformRepository())
            {
                var query = repository.Roles;

                if (request.Keyword != null)
                {
                    query = query.Where(r => r.Name.Contains(request.Keyword));
                }

                result.TotalCount = query.Count();

                var roles = query
                            .OrderBy(r => r.Name)
                            .Skip(request.SkipCount)
                            .Take(request.TakeCount)
                            .Include(r => r.RolePermissions.Select(rp => rp.Permission))
                            .Include(r => r.RolePermissions.Select(rp => rp.Scopes))
                            .ToArray();

                var roleAllPermissionScopes =
                    result.Roles = roles.Select(r => r.ToCoreModel(_permissionScopeService)).ToArray();
            }

            return(result);
        }
        private async Task LoadUserDetails()
        {
            if (_id.HasValue)
            {
                btnDelete.Show();
                var user = await _userService.GetById <Model.User>(_id);

                txtFirstName.Text = user.FirstName;
                txtLastName.Text  = user.LastName;
                txtEmail.Text     = user.Email;
                txtTelephone.Text = user.PhoneNumber;

                if (user.Image.Length > 0 && user.Image != null)
                {
                    MemoryStream ms    = new MemoryStream(user.Image);
                    Image        image = Image.FromStream(ms);
                    pbAvatar.Image = image;
                }
                var request = new RoleSearchRequest {
                    UserId = user.UserId
                };
                var userRoles = await _roleService.Get <List <Model.Role> >(request);

                var rolesInt = userRoles.Select(x => x.RoleId);
                for (int i = 0; i < clbRoles.Items.Count; i++)
                {
                    var item = (clbRoles.Items[i] as Model.Role).RoleId;
                    if (rolesInt.Contains(item))
                    {
                        clbRoles.SetItemChecked(i, true);
                    }
                }
            }
        }
        public async Task <RoleListViewModel> GetPageList(RoleSearchRequest request)
        {
            var roles = _roles.AsNoTracking().AsQueryable();

            if (request.Term.HasValue())
            {
                roles = roles.Where(a => a.Name.Contains(request.Term));
            }

            var selectedTitles = roles.ProjectTo <RoleViewModel>(_mappingEngine);

            var query = await selectedTitles
                        .OrderBy(a => a.Name)
                        .Skip((request.PageIndex - 1) * 5)
                        .Take(5)
                        .ToListAsync();

            query.ForEach(a =>
            {
                if (a.Permissions != null)
                {
                    a.PermissionsList = _permissionService.GetDescriptions(a.XmlPermission);
                }
            });
            return(new RoleListViewModel {
                SearchRequest = request, Roles = query
            });
        }
Exemple #5
0
        public async Task <string> GenerateCodeAsync()
        {
            var request = new RoleSearchRequest();
            var maxCode = await MaxByRequestAsync(request, RoleAggregateMember.Code);

            return(maxCode == null ? CodeConst.BeginNumber5Digit : maxCode.ExtractNumeric());
        }
Exemple #6
0
        public async Task <IList <Role> > GetRolesByRequestAsync(RoleSearchRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(await QueryByRequest(request).ToPagedListAsync(request));
        }
        public virtual async Task <ActionResult> ListAjax(RoleSearchRequest request)
        {
            var viewModel = await _roleManager.GetPageList(request);

            if (viewModel.Roles == null || !viewModel.Roles.Any())
            {
                return(Content("no-more-info"));
            }
            return(PartialView(MVC.Role.Views.ViewNames._ListAjax, viewModel));
        }
Exemple #8
0
        public async Task <int> CountByRequestAsync(RoleSearchRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var roles = await QueryByRequest(request).CountAsync();

            return(roles);
        }
Exemple #9
0
        public async Task <IActionResult> RoleSearch([FromBody] RoleSearchRequest request)
        {
            try
            {
                //ValidationResult validate = RoleGetByDepartmentIdRequestValidator.ValidateModel(request);
                var response = await _roleAppService.Search(request);

                return(Json(response));
            }
            catch (Exception e)
            {
                _logger.LogError(e, Common.Common.GetMethodName(), request);
                throw;
            }
        }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="aggregateMember"></param>
        /// <returns></returns>
        public async Task <string> MaxByRequestAsync(RoleSearchRequest request, string aggregateMember)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var products = QueryByRequest(request);

            switch (aggregateMember)
            {
            case RoleAggregateMember.Code:
                var memberMax = await products.MaxAsync(model => model.Code);

                return(memberMax);
            }

            return(null);
        }
Exemple #11
0
        public async Task <RoleListViewModel> PrepareListViewModelAsync(RoleSearchRequest request, bool isCurrentUser = false, Guid?userId = null)
        {
            request.CreatedById = await _commonService.GetUserIdAsync(isCurrentUser, userId);

            request.TotalCount = await _roleService.CountByRequestAsync(request);

            var role = await _roleService.GetRolesByRequestAsync(request);

            var roleViewModel = _mapper.Map <IList <RoleViewModel> >(role);
            var viewModel     = new RoleListViewModel
            {
                SearchRequest     = request,
                Roles             = roleViewModel,
                PageSizeList      = await _listManager.GetPageSizeListAsync(),
                SortDirectionList = await _listManager.GetSortDirectionListAsync(),
            };

            return(viewModel);
        }
Exemple #12
0
        /// <inheritdoc />
        ///  <summary>
        ///  </summary>
        ///  <param name="request"></param>
        ///  <returns></returns>
        public IQueryable <Role> QueryByRequest(RoleSearchRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var roles = _roleRepository.AsNoTracking().AsQueryable();

            if (string.IsNullOrEmpty(request.SortMember))
            {
                request.SortMember = SortMember.CreatedOn;
            }
            if (string.IsNullOrEmpty(request.SortDirection))
            {
                request.SortDirection = SortDirection.Desc;
            }

            roles = roles.OrderBy($"{request.SortMember} {request.SortDirection}");

            return(roles);
        }
Exemple #13
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            var userAuth = new UserAuth();

            ControlsHelper.MapControlsToProps(userAuth, this);
            APIService.Username = userAuth.Username;
            APIService.Password = userAuth.Password;

            var roleSearchRequest = new RoleSearchRequest
            {
                Username = APIService.Username,
                Password = APIService.Password
            };

            var roles = await _roleAPIService.Get <List <RoleDTO> >(roleSearchRequest);

            if (roles == null || roles.Count == 0)
            {
                MessageBox.Show("Invalid username or invalid password");
            }
            else if (roles.Select(x => x.Name).Contains(UserType.Administrator) ||
                     roles.Select(x => x.Name).Contains(UserType.SuperAdministrator))
            {
                frmAdminHome frmAdminHome = new frmAdminHome();
                //this.Hide();
                frmAdminHome.Show();
            }
            else if (roles.Select(x => x.Name).Contains(UserType.Organization))
            {
                frmOrganizationHome frmHome = new frmOrganizationHome();
                //this.Hide();
                frmHome.Show();
            }
            else
            {
                MessageBox.Show("Invalid user type");
            }
        }
Exemple #14
0
 public virtual async Task<ActionResult> ListAjax(RoleSearchRequest request)
 {
     var viewModel = await _roleManager.GetPageList(request);
     if (viewModel.Roles == null || !viewModel.Roles.Any()) return Content("no-more-info");
     return PartialView(MVC.Role.Views.ViewNames._ListAjax, viewModel);
 }
        /// <summary>
        /// Search roles by keyword 
        /// </summary>
        /// <exception cref="VirtoCommerce.Platform.Client.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="request">Search parameters.</param>
        /// <returns>Task of ApiResponse (RoleSearchResponse)</returns>
        public async System.Threading.Tasks.Task<ApiResponse<RoleSearchResponse>> SecuritySearchRolesAsyncWithHttpInfo(RoleSearchRequest request)
        {
            // verify the required parameter 'request' is set
            if (request == null)
                throw new ApiException(400, "Missing required parameter 'request' when calling VirtoCommercePlatformApi->SecuritySearchRoles");

            var localVarPath = "/api/platform/security/roles";
            var localVarPathParams = new Dictionary<string, string>();
            var localVarQueryParams = new Dictionary<string, string>();
            var localVarHeaderParams = new Dictionary<string, string>(Configuration.DefaultHeader);
            var localVarFormParams = new Dictionary<string, string>();
            var localVarFileParams = new Dictionary<string, FileParameter>();
            object localVarPostBody = null;

            // to determine the Content-Type header
            string[] localVarHttpContentTypes = new string[] {
                "application/json", 
                "text/json", 
                "application/xml", 
                "text/xml", 
                "application/x-www-form-urlencoded"
            };
            string localVarHttpContentType = ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            string[] localVarHttpHeaderAccepts = new string[] {
                "application/json", 
                "text/json", 
                "application/xml", 
                "text/xml"
            };
            string localVarHttpHeaderAccept = ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);
            if (localVarHttpHeaderAccept != null)
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            localVarPathParams.Add("format", "json");
            if (request.GetType() != typeof(byte[]))
            {
                localVarPostBody = ApiClient.Serialize(request); // http body (model) parameter
            }
            else
            {
                localVarPostBody = request; // byte array
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await ApiClient.CallApiAsync(localVarPath,
                Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (localVarStatusCode >= 400 && (localVarStatusCode != 404 || Configuration.ThrowExceptionWhenStatusCodeIs404))
                throw new ApiException(localVarStatusCode, "Error calling SecuritySearchRoles: " + localVarResponse.Content, localVarResponse.Content);
            else if (localVarStatusCode == 0)
                throw new ApiException(localVarStatusCode, "Error calling SecuritySearchRoles: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);

            return new ApiResponse<RoleSearchResponse>(localVarStatusCode,
                localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                (RoleSearchResponse)ApiClient.Deserialize(localVarResponse, typeof(RoleSearchResponse)));
            
        }
Exemple #16
0
        public virtual async Task <ActionResult> List(RoleSearchRequest request)
        {
            var viewModel = await _roleFactory.PrepareListViewModelAsync(request);

            return(View(MVC.Role.Views.List, viewModel));
        }
        /// <summary>
        /// Search roles by keyword 
        /// </summary>
        /// <exception cref="VirtoCommerce.Platform.Client.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="request">Search parameters.</param>
        /// <returns>Task of RoleSearchResponse</returns>
        public async System.Threading.Tasks.Task<RoleSearchResponse> SecuritySearchRolesAsync(RoleSearchRequest request)
        {
             ApiResponse<RoleSearchResponse> localVarResponse = await SecuritySearchRolesAsyncWithHttpInfo(request);
             return localVarResponse.Data;

        }
        public IHttpActionResult SearchRoles(RoleSearchRequest request)
        {
            var result = _roleService.SearchRoles(request);

            return(Ok(result));
        }
 /// <summary>
 /// Search roles by keyword 
 /// </summary>
 /// <exception cref="VirtoCommerce.Platform.Client.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="request">Search parameters.</param>
 /// <returns>RoleSearchResponse</returns>
 public RoleSearchResponse SecuritySearchRoles(RoleSearchRequest request)
 {
      ApiResponse<RoleSearchResponse> localVarResponse = SecuritySearchRolesWithHttpInfo(request);
      return localVarResponse.Data;
 }