public override string ToString() { StringBuilder sb = new StringBuilder("{"); sb.Append(ZoneId.ToString() + ","); sb.Append(UserRoleId.ToString() + ","); sb.Append(ReadAccess.ToString() + ","); sb.Append(WriteAccess.ToString() + "}"); return(sb.ToString()); }
/// <summary> /// Gets the list of data for use by the jqgrid plug-in /// </summary> public IActionResult OnGetGridDataGroupedByUserId(string sidx, string sord, int _page, int rows) { // using a groupField in the jqgrid passes that field // along with the field to sort, remove the groupField string groupBy = "CreatedBy asc, "; sidx = sidx.Replace(groupBy, ""); int totalRecords = UserRoles.GetRecordCount(); int startRowIndex = ((_page * rows) - rows); List <UserRoles> objUserRolesCol = UserRoles.SelectSkipAndTake(rows, startRowIndex, sidx + " " + sord); int totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows); if (objUserRolesCol is null) { return(new JsonResult("{ total = 0, page = 0, records = 0, rows = null }")); } var jsonData = new { total = totalPages, _page, records = totalRecords, rows = ( from objUserRoles in objUserRolesCol select new { id = objUserRoles.UserRoleId, cell = new string[] { objUserRoles.UserRoleId.ToString(), objUserRoles.UserId.HasValue ? objUserRoles.UserId.Value.ToString() : "", objUserRoles.RoleId.HasValue ? objUserRoles.RoleId.Value.ToString() : "", objUserRoles.Status.ToString(), objUserRoles.UserId is null ? "" : objUserRoles.UserMaster.CreatedBy } }).ToArray()
protected override PermittedIDsResult CreatePermittedIDFilter(List <string> pNames, List <object> pValues, bool bForReading, out string filterHQL, User user) { Debug.Assert((pNames != null) && (pValues != null), "CreatePermittedIDFilter: impossible to store parameters"); User u = user; Debug.Assert(u != null, "CreatePermittedIDFilter: user is null"); if (!u.UserRoleID.HasValue) { filterHQL = null; return(PermittedIDsResult.None); } StringBuilder sFrom = new StringBuilder(); StringBuilder sWhere = new StringBuilder(); sFrom.AppendFormat("SELECT filtered.ID FROM {0} filtered", typeof(YearlyWorkingDay).Name); PermittedIDsResult result; UserRoleId role = (UserRoleId)(u.UserRoleID.Value); switch (role) { case UserRoleId.GlobalAdmin: result = PermittedIDsResult.All; break; case UserRoleId.Controlling: if (bForReading) { goto case UserRoleId.CountryAdmin; } else { result = PermittedIDsResult.None; } break; case UserRoleId.CountryAdmin: sWhere.Append(sWhere.Length > 0 ? " AND " : " WHERE "); sFrom.AppendFormat(", {0} internal_dao_uc", typeof(UserCountry).Name); sWhere.Append( @"internal_dao_uc.User.ID = :internal_dao_userID AND internal_dao_uc.CountryID = filtered.CountryID"); pNames.Add("internal_dao_userID"); pValues.Add(u.ID); result = PermittedIDsResult.Restricted; break; case UserRoleId.RegionAdmin: if (bForReading) { sWhere.Append(sWhere.Length > 0 ? " AND " : " WHERE "); sFrom.AppendFormat(", {0} internal_dao_r, {1} internal_dao_ur", typeof(Region).Name, typeof(UserRegion).Name); sWhere.AppendFormat( @"internal_dao_ur.User.ID = :internal_dao_userID AND internal_dao_ur.RegionID = internal_dao_r.ID AND internal_dao_r.CountryID = filtered.CountryID"); pNames.Add("internal_dao_userID"); pValues.Add(u.ID); result = PermittedIDsResult.Restricted; } else { result = PermittedIDsResult.None; } break; case UserRoleId.StoreAdmin: if (bForReading) { sWhere.Append(sWhere.Length > 0 ? " AND " : " WHERE "); sFrom.AppendFormat(", {0} internal_dao_s, {1} internal_dao_r, {2} internal_dao_us", typeof(Store).Name, typeof(Region).Name, typeof(UserStore).Name); sWhere.AppendFormat( @"internal_dao_us.User.ID = :internal_dao_userID AND internal_dao_us.StoreID = internal_dao_s.ID AND internal_dao_s.RegionID = internal_dao_r.ID AND internal_dao_r.CountryID = filtered.CountryID"); pNames.Add("internal_dao_userID"); pValues.Add(u.ID); result = PermittedIDsResult.Restricted; } else { result = PermittedIDsResult.None; } break; default: throw new Exception(string.Format("unknown user role : {0}", role.ToString())); } if (sWhere.Length == 0) { filterHQL = null; } else { filterHQL = sFrom.Append(sWhere).ToString(); } return(result); // suppose, we should never call base //return base.CreatePermittedIDFilter(); }