public HttpResponseMessage GetAllHierachy(HttpRequestMessage request) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; IEnumerable <Function> model; if (User.IsInRole("Admin")) { model = _functionService.GetAll(string.Empty); } else { model = _functionService.GetAllWithPermission(User.Identity.GetUserId()); } IEnumerable <FunctionViewModel> modelVm = Mapper.Map <IEnumerable <Function>, IEnumerable <FunctionViewModel> >(model); var parents = modelVm.Where(x => x.Parent == null); foreach (var parent in parents) { parent.ChildFunctions = modelVm.Where(x => x.ParentId == parent.ID).ToList(); } response = request.CreateResponse(HttpStatusCode.OK, parents); return response; })); }
public HttpResponseMessage GetAllHierachy(HttpRequestMessage request, string userName) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; IEnumerable <Function> model; if (userName == "admin") { model = _functionService.GetAll(string.Empty); } else { //model = _functionService.GetAll(string.Empty); //var myString = "2fdaa74a-ccd1-4fa0-a256-9349f7c5e4bc"; model = _functionService.GetAllWithPermission(userName); } IEnumerable <FunctionViewModel> modelVm = Mapper.Map <IEnumerable <Function>, IEnumerable <FunctionViewModel> >(model); var parents = modelVm.Where(x => x.Parent == null); foreach (var parent in parents) { parent.ChildFunctions = modelVm.Where(x => x.ParentId == parent.ID).ToList(); } response = request.CreateResponse(HttpStatusCode.OK, parents); return response; })); }
public async Task <IActionResult> GetAllHierachy() { var hasPermission = await _authorizationService.AuthorizeAsync(User, "FUNCTION", Operations.Read); if (hasPermission.Succeeded == false) { return(new BadRequestObjectResult(CommonConstants.Forbidden)); } string userId = User.GetSpecialClaimsApi("Id"); List <FunctionViewModel> funtionVm; if (User.CheckIsAdminApi()) { funtionVm = _functionService.GetAll(string.Empty); } else { funtionVm = _functionService.GetAllWithPermission(userId); } List <FunctionViewModel> parents = funtionVm.FindAll(x => x.ParentId == null); foreach (var parent in parents) { parent.ChildFunctions = funtionVm.Where(x => x.ParentId == parent.Id).ToList(); } return(new OkObjectResult(parents)); }
public async Task <IActionResult> GetAllHierachyAsync() { var roles = ((ClaimsIdentity)User.Identity) .Claims.FirstOrDefault(x => x.Type == CommonConstants.UserClaims.Roles); bool IsAdmin = false; if (roles != null) { var listRole = JsonConvert.DeserializeObject <List <string> >(roles.Value).ToArray(); if (listRole.Contains(CommonConstants.AppRole.AdminRole)) { IsAdmin = true; } } IEnumerable <FunctionViewModel> model; if (IsAdmin) { var functions = _functionService.GetAll(string.Empty); model = functions.Result; } else { var userId = _userManager.GetUserId(User); model = _functionService.GetAllWithPermission(userId); } var parents = model.Where(x => x.ParentId == null); foreach (var parent in parents) { parent.ChildFunctions = model.Where(x => x.ParentId == parent.Id).ToList(); } return(new OkObjectResult(parents)); }
public HttpResponseMessage GetAllHierarchy(HttpRequestMessage request) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; IEnumerable <Function> model; if (User.IsInRole("Admin")) { model = _functionService.GetAll(string.Empty); } else { model = _functionService.GetAllWithPermission(User.Identity.GetUserId()); } IEnumerable <FunctionViewModel> modelVm = Mapper.Map <IEnumerable <Function>, IEnumerable <FunctionViewModel> >(model); var parents = modelVm.Where(x => x.Parent == null); foreach (var parent in parents) { parent.ChildFunctions = modelVm.Where(x => x.ParentId == parent.ID).ToList(); } response = request.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(parents, Formatting.None, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); return response; })); }
public async Task <IViewComponentResult> InvokeAsync() { var roles = ((ClaimsIdentity)User.Identity).Claims.FirstOrDefault(x => x.Type == CommonConstants.UserClaim.Roles); List <FunctionViewModel> functions; if (roles != null && roles.Value.Split(";").Contains(CommonConstants.AppRole.Admin)) { functions = await _functionService.GetAll(string.Empty); } else { functions = await _functionService.GetAllWithPermission(User.Identity.Name); } return(View(functions)); }
public async Task <HttpResponseMessage> GetAllHierachy(HttpRequestMessage request) { return(await CreateHttpResponse(request, () => { HttpResponseMessage response = null; IEnumerable <Function> model; model = _functionService.GetAllWithPermission(User.Identity.GetUserId()); IEnumerable <FunctionViewModel> modelVm = Mapper.Map <IEnumerable <Function>, IEnumerable <FunctionViewModel> >(model); var parents = modelVm.Where(x => x.Parent == null); foreach (var parent in parents) { parent.ChildFunctions = modelVm.Where(x => x.ParentId == parent.ID).ToList(); } response = request.CreateResponse(HttpStatusCode.OK, parents); return response; })); }
public async Task <IActionResult> GetAll() { List <FunctionViewModel> model; if (User.IsInRole("Admin")) { model = _functionService.GetAll(); } else { model = await _functionService.GetAllWithPermission(User.Identity.Name); } var parents = model.Where(x => x.ParentId == null); foreach (var parent in parents) { parent.ChildFunctions = model.Where(x => x.ParentId == parent.Id).ToList(); } return(new OkObjectResult(parents)); }
// IViewComponentResult // using Microsoft.AspNetCore.Mvc; public async Task <IViewComponentResult> InvokeAsync() { try { //var roles = ((ClaimsPrincipal)User).GetSpecificClaim("Roles"); //List<FunctionViewModel> functions; //if (roles.Split(";").Contains(CommonConstants.AppRole.Admin)) //{ // functions = await _functionService.GetAll(string.Empty); // //functions = await _functionService.GetAllList(); //} //else //{ // functions = await _functionService.GetAll(string.Empty); // functions = await _functionService.GetAll(string.Empty); //} //else //{ // functions = await _functionService.GetAll(string.Empty); //} var roles = ((ClaimsIdentity)User.Identity).Claims.FirstOrDefault(x => x.Type == CommonConstants.UserClaims.Roles); List <FunctionViewModel> functions; if (roles != null && roles.Value.Split(";").Contains(CommonConstants.AppRole.Admin) || roles != null && roles.Value.Split(";").Contains(CommonConstants.AppRole.Rico)) { functions = await _functionService.GetAll(string.Empty); } else { functions = await _functionService.GetAllWithPermission(User.Identity.Name); } return(View(functions)); } catch (System.Exception ex) { throw ex; } }
public IActionResult GetAllHierachy() { IEnumerable <FunctionViewModel> model; model = CurrentRoleNames.Contains("Administrator") ? _functionService.GetAll(string.Empty) : _functionService.GetAllWithPermission(CurrentRoleIds); var parents = model.Where(x => x.Parent == null); var functionViewModels = parents as IList <FunctionViewModel> ?? parents.ToList(); foreach (var parent in functionViewModels) { parent.ChildFunctions = model.Where(x => x.ParentId == parent.Id).ToList(); } return(Ok(functionViewModels)); }