public IActionResult Update(int id) { var model = _functionService.GetById(id); model.Categories = _functionService.FunctionsSelectListItem(id: id); return(View(model)); }
public async Task <IViewComponentResult> InvokeAsync() { var roles = ((ClaimsPrincipal)User).GetSpecificClaim("Roles"); List <FunctionViewModel> functions = new List <FunctionViewModel>(); if (roles.Split(";").Contains(CommonConstants.AppRole.AdminRole)) { functions = await _functionService.GetAll(string.Empty); } else { foreach (var item in roles.Split(";")) { var role = await _roleService.GetByName(item); if (role != null) { var permissions = _roleService.GetListFunctionWithRole((Guid)role.Id); foreach (var per in permissions) { if (!functions.Any(x => x.Id == per.FunctionId)) { functions.Add(_functionService.GetById(per.FunctionId)); } } } } } return(View(functions)); }
public async Task <IViewComponentResult> InvokeAsync() { var stringRoles = ((ClaimsPrincipal)User).GetSpecificClaim("Roles"); List <FunctionViewModel> functions; if (stringRoles.Split(";").Contains(CommonConstants.AppRole.AdminRole)) { functions = await _functionService.GetAll(string.Empty); } else { //TODO: Get by permission var roles = stringRoles.Split(";"); var roleId = _roleService.GetByName(roles[0]).Result; var permissions = _roleService.GetListFunctionWithRole(roleId).Result; functions = new List <FunctionViewModel>(); foreach (var permission in permissions) { if (permission.CanRead == true) { functions.Add(_functionService.GetById(permission.FunctionId)); } } } return(View(functions)); }
public HttpResponseMessage Details(HttpRequestMessage request, string id) { if (string.IsNullOrEmpty(id)) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, nameof(id) + " không có giá trị.")); } else { var model = _functionService.GetById(id); if (model == null) { return(request.CreateErrorResponse(HttpStatusCode.NoContent, "No data")); } var modelVm = Mapper.Map <Function, FunctionViewModel>(model); return(request.CreateResponse(HttpStatusCode.OK, modelVm)); } }
public async Task <IActionResult> GetById(string id) { var result = await _authorizationService.AuthorizeAsync(User, CommonConstants.Functions.Role, Operations.Read); if (!result.Succeeded) { return(new ForbidResult()); } return(new OkObjectResult(_functionService.GetById(id))); }
public IHttpActionResult Get(string id) { return(CreateResponse(() => { var model = _functionService.GetById(id); if (model == null) { return Content(HttpStatusCode.NotFound, ApiMessage.FunctionNotFound); } return Ok(Mapper.Map <FunctionDto>(model)); })); }
public async Task <IActionResult> GetFunctionById(TRequest <RequesId> request) { var response = new Response <object>(); try { response.Data = await _functionService.GetById(request.value.Id); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message + "," + ex.InnerException; } return(Ok(response)); }
///TODO- need to add this profile fields in db and api public IActionResult GetFunctionByID(int id) { var function = _service.GetById(id); if (function == null) { return(new UnauthorizedResult()); } FunctionDto functionDto = new FunctionDto() { ID = function.ID, Name = function.Name }; return(Ok(functionDto)); }
public async Task <IViewComponentResult> InvokeAsync() { var roles = ((ClaimsPrincipal)User).GetSpecificClaim("Roles"); List <FunctionViewModel> functions; if (roles.Split(";").Contains(CommonConstants.AdminRole)) { functions = await _functionService.GetAll(string.Empty); } else { var appRoles = new List <AppRoleViewModel>(); var permissions = new List <PermissionViewModel>(); functions = new List <FunctionViewModel>(); var splitRoles = roles.Split(';'); foreach (var item in splitRoles) { var functionByRole = await _roleService.GetByName(item); appRoles.Add(functionByRole); } foreach (var item in appRoles) { var query = _roleService.GetListFunctionMenuWithRole(item.Id.Value); permissions.AddRange(query); } foreach (var item in permissions) { var query = _functionService.GetById(item.FunctionId); functions.Add(query); } } return(await Task.Run(() => View(functions))); }
public IActionResult GetById(string id) { var model = _functionService.GetById(id); return(new OkObjectResult(model)); }
public async Task <IActionResult> GetById(string id) { var model = await _functionService.GetById(id); return(new ObjectResult(model)); }
public async Task <IActionResult> Detail(string functionId) { var function = await _functionService.GetById(functionId); return(Ok(function)); }