/// <summary> /// Get Role By Id /// </summary> /// <param name="id">role id</param> /// <returns>returns _EditPopUp partial view</returns> public async Task <ActionResult> LoadEditRolePopUp(int id) { try { RoleViewModel roleVM = new RoleViewModel(); var roleList = new SORoleDto(); var responseRoles = await Get("sorole/GetRoleById/" + id); if (responseRoles.StatusCode == HttpStatusCode.OK) { roleList = await responseRoles.Content.ReadAsAsync <SORoleDto>(); roleVM = roleMapper.ToObject(roleList); } var responseFeatures = await Get("sofeature/GetAllFeatures"); List <FeatureViewModel> features = new List <FeatureViewModel>(); if (responseFeatures.StatusCode == HttpStatusCode.OK) { var featureList = await responseFeatures.Content.ReadAsAsync <IEnumerable <SOFeatureDto> >(); features = featureMapper.ToObjects(featureList).ToList(); } var responseCategories = await Get("category/GetAllCategories"); List <CategoryViewModel> categories = new List <CategoryViewModel>(); if (responseCategories.StatusCode == HttpStatusCode.OK) { var categoryList = await responseCategories.Content.ReadAsAsync <IEnumerable <SOCategoryDto> >(); categories = categoryMapper.ToObjects(categoryList).ToList(); } roleVM = SetRoleViewModel(roleVM, categories, features); List <string> checkedPermissions = new List <string>(); checkedPermissions = SetPermissions(roleList, checkedPermissions); return(Json(new { Status = 1, Data = RenderRazorViewToString("_EditPopUp", roleVM), IsActive = roleVM.IsActive, checkedPermissions, SelectedHomePage = roleVM.SOMenuId })); } catch (Exception ex) { logger.Error(ex.Message); return(Json(new { Status = 0, Data = "error", Message = ex.Message })); } }
/// <summary> /// Sets the permissions. /// </summary> /// <param name="roleList">The i role.</param> /// <param name="checkedPermissions">The checked permissions.</param> /// <returns>return permissions</returns> public List <string> SetPermissions(SORoleDto roleList, List <string> checkedPermissions) { try { foreach (var item in roleList.SORolePermissions) { if (item.ReadPermission == true) { checkedPermissions.Add("readcheckboxEdit_" + item.FeatureId); } if (item.CreatePermission == true) { checkedPermissions.Add("createcheckboxEdit_" + item.FeatureId); } if (item.UpdatePermission == true) { checkedPermissions.Add("updatecheckboxEdit_" + item.FeatureId); } if (item.DeletePermission == true) { checkedPermissions.Add("deletecheckboxEdit_" + item.FeatureId); } if (item.ApprovePermission == true) { checkedPermissions.Add("approvecheckboxEdit_" + item.FeatureId); } if (item.DeAvtivatePermission == true) { checkedPermissions.Add("deactivatecheckboxEdit_" + item.FeatureId); } } return(checkedPermissions); } catch (Exception ex) { logger.Error(ex.Message); return(null); } }