private JsTreeViewModel ConvertToJsTreeObject(ProjectFilterParam treeDoc, bool isLable = false, bool isEdit = false) { JsTreeViewModel jsTree = new JsTreeViewModel(); jsTree.text = treeDoc.Name; jsTree.id = treeDoc.Id.ToString(); jsTree.left_iscount = treeDoc.IsCount.HasValue ? treeDoc.IsCount.Value : false; jsTree.left_paramnames = ""; jsTree.left_paramvalues = treeDoc.ParamValue; jsTree.icon = "far fa-folder"; jsTree.parent = treeDoc.ParentID.Value == Guid.Empty ? "#" : treeDoc.ParentID.Value.ToString(); jsTree.state = new JsTreeStateObject() { opened = true }; var m_datacontext = "{ \"ParamValues\" : \"" + treeDoc.ParamValue + "\"," + " \"ParentDocument\" : \"" + treeDoc.ParentID + "\" }"; jsTree.li_attr = new { datacontext = m_datacontext, islable = isLable, isedit = isEdit }; return(jsTree); }
public bool Save(ProjectFilterParamDto dto, Guid currenUserId) { using (var scope = _dbContextScopeFactory.Create()) { if (dto.ParentID == null || dto.ParentID == Guid.Empty) { var entityParent = _objectRepository.GetAll().Where(x => x.ParentID == Guid.Empty && x.Code == "TASK").FirstOrDefault(); dto.ParentID = entityParent.Id; } if (dto.Id != Guid.Empty) { var entity = _objectRepository.GetAll().Where(x => x.Id == dto.Id).FirstOrDefault(); entity.Name = dto.Name; entity.Code = string.Format("TASK_{0}", string.Join("", dto.Name.ToUpper().Split(' '))); entity.IsCount = dto.IsCount; entity.IsPrivate = dto.IsPrivate; entity.IsLable = dto.IsLable; entity.ParamValue = dto.ParamValue; entity.NoOrder = dto.NoOrder; entity.ParentID = dto.ParentID; entity.ModifiedBy = currenUserId; entity.ModifiedDate = DateTime.Now; _objectRepository.Modify(entity); scope.SaveChanges(); } else { var entity = new ProjectFilterParam(); entity.Id = Guid.NewGuid(); entity.IsActive = true; entity.Name = dto.Name; entity.IsCount = dto.IsCount; entity.IsPrivate = dto.IsPrivate; entity.IsLable = dto.IsLable; entity.ParamValue = dto.ParamValue; entity.NoOrder = dto.NoOrder; entity.ParentID = dto.ParentID; entity.CreatedBy = currenUserId; entity.CreatedDate = DateTime.Now; _objectRepository.Add(entity); scope.SaveChanges(); } } return(true); }
public bool CheckPermission(ProjectFilterParam projectFilterParam, Guid currentUserId) { bool isPermission = false; if (projectFilterParam.IsPrivate == true || projectFilterParam.CreatedBy.Value == currentUserId) { isPermission = true; } if (!isPermission && projectFilterParam.IsPrivate == false && !string.IsNullOrEmpty(projectFilterParam.Roles)) { var RoleStr = projectFilterParam.Roles.Split(new char[] { ',' }).ToList(); List <Guid> Guids = new List <Guid>(); foreach (var item in RoleStr) { Guids.Add(new Guid(item)); } var users = _userServices.GetUserByRoles(Guids); if (users.Any(e => e.Id == currentUserId)) { isPermission = true; } } if (!isPermission && projectFilterParam.IsPrivate == false && !string.IsNullOrEmpty(projectFilterParam.Users)) { if (projectFilterParam.Users.Contains(currentUserId.ToString())) { isPermission = true; } } if (!isPermission && projectFilterParam.IsPrivate == false && string.IsNullOrEmpty(projectFilterParam.Users) && string.IsNullOrEmpty(projectFilterParam.Roles)) { isPermission = true; } return(isPermission); }
/// có filter theo module code /// </summary> /// <param name="userID">mã tài khoản cần user xét</param> /// <param name="moduleCode"></param> /// <returns></returns> public List <ProjectFilterParam> GetRootCheckSubProjectFilterParams(Guid userID) { var models = new List <ProjectFilterParam>(); List <ProjectFilterParam> listUserTree = null; using (var scope = _dbContextScopeFactory.Create()) { var dbcontext = scope.DbContexts.Get <TaskContext>(); listUserTree = _objectRepository.GetAll().Where( tfd => tfd.IsActive == true && tfd.ParentID.HasValue && tfd.Code != null && ( tfd.Code.Contains("TASK") //|| tfd.Code.Contains("UQ") || tfd.Code.Contains("BG") //|| tfd.Code == "HSCN" || tfd.Code == "HSCT" ) ).ToList(); if (!listUserTree.Any()) { ProjectFilterParam filter = new ProjectFilterParam() { Code = "TASK", CreatedBy = null, CreatedDate = DateTime.Now, IsActive = true, IsLable = true, Id = Guid.NewGuid(), Name = "Bộ lọc", NoOrder = 0, }; ProjectFilterParam filterChild = new ProjectFilterParam() { Code = "TASK", CreatedBy = null, CreatedDate = DateTime.Now, IsActive = true, IsLable = false, Id = Guid.NewGuid(), ParentID = filter.Id, Name = "Tất cả", NoOrder = 0, }; _objectRepository.Add(filter); _objectRepository.Add(filterChild); scope.SaveChanges(); listUserTree = _objectRepository.GetAll().Where( tfd => tfd.IsActive == true && tfd.ParentID.HasValue && tfd.Code != null && ( tfd.Code.Contains("TASK") //|| tfd.Code.Contains("UQ") || tfd.Code.Contains("BG") //|| tfd.Code == "HSCN" || tfd.Code == "HSCT" ) ).ToList(); } // translate //foreach (var item in listUserTree) //{ // item.Name = TranslateTreeFilterResource(item); //} #region Get list user delegations tree filterdocument var userDelegation = listUserTree.Find(t => t.Code == "UQ"); if (userDelegation != null) { var userDelegationRepository = new RepositoryBase <UserDelegation>(dbcontext); var userDelegations = userDelegationRepository.GetAll(t => t.IsActive == true && t.ToUserID == userID && t.ToDate.Value >= DateTime.Now).ToList(); if (userDelegations.Any() == false) { listUserTree.Remove(userDelegation); } } #endregion #region Get list user handover tree filterdocument var userHandover = listUserTree.Find(t => t.Code == "BG"); if (userHandover != null) { var userUserHandoverRepository = new RepositoryBase <UserHandOver>(dbcontext); var userHandovers = userUserHandoverRepository.GetAll(t => t.IsActive == true && t.ToUserID == userID).ToList(); if (userHandovers.Any() == false) { listUserTree.Remove(userHandover); } } #endregion #region Filter by role permission if (listUserTree != null) { foreach (var menuTree in listUserTree) { if (menuTree.IsPrivate != true || menuTree.CreatedBy == userID) { models.Add(menuTree); } } } #endregion } return(models); }