public static IList <Comment> GetAuthorizedComments(string nlihcId, User user) { var crit = new DaoCriteria(); crit.Expressions.Add(new EqualExpression("NlihcId", nlihcId)); // Anonymous users get only public comments if (user == null) { crit.Expressions.Add(new EqualExpression("AccessLevel", CommentAccessLevel.Public)); return(_dao.Get(crit)); } // This kind of query is difficult in FastDAO, so, expecting that the number // of comments on a given property will be reasonable, prune off unauthorized // comments from the entire property comment list var comments = _dao.Get(crit); // SysAdmins can see everything if (user.IsSysAdmin()) { return(comments); } var authComments = new List <Comment>(); foreach (var comment in comments) { switch (comment.AccessLevel) { case CommentAccessLevel.Public: authComments.Add(comment); break; case CommentAccessLevel.Network: if (user.IsNetworked()) { authComments.Add(comment); } break; case CommentAccessLevel.SameOrg: if (user.Organization == comment.AssociatedOrgId) { authComments.Add(comment); } break; } } return(authComments); }
/// <summary> /// Get an organization by id. /// </summary> /// <param name="orgId">The id of the org object to get.</param> /// <returns></returns> public static Organization getOrgById(int orgId) { IList <Organization> result = _orgDao.Get("Id", orgId); if (result.Count == 0) { return(null); } else { return(result[0]); } }
public static IList <User> GetUsers(int page, int pageSize, SortOrder sortOrder) { // Get all users, within the paging restrictions, sorted by Name DaoCriteria crit = new DaoCriteria(); // Start recordset at the begining of the page crit.Start = (page * pageSize) - (pageSize); // Number of records to include crit.Limit = pageSize; // Order it by the requested column if (sortOrder != null) { crit.Orders.Add(sortOrder); } else { // Have a default sort of Name, Asc if nothing passed in crit.Orders.Add(new SortOrder("Name", SortType.Asc)); } // Execute and return the query return(_userDao.Get(crit)); }
public static IList <T> GetRows <T>(string nlihcId, IList <SecurityRole> roles) where T : class, IDisplaySortable, new() { var dao = new FastDAO <T>(Config.GetConfig("PDP.Data"), "PDB"); var crit = new DaoCriteria(new EqualExpression("NlihcId", nlihcId)); var sortField = Activator.CreateInstance <T>().GetSortField(); crit.Orders.Add(new SortOrder(sortField, SortType.Desc)); return(DisplayForRole(ResourceMap[typeof(T)], roles) ? dao.Get(crit) : null); }
/// <summary> /// Refresh the cached role per resource settings /// </summary> public static void ReloadRoles() { var childen = Dao.Get(); _roles = new Dictionary <ChildResourceType, SecurityRole>(); foreach (var child in childen) { _roles.Add(child.Resource, child.RoleForDisplay); } }
public static IList <PdbUploadRevision> GetUploadRevisions(UploadTypes type) { var crit = new DaoCriteria(); crit.Expressions.Add(new EqualExpression("Type", type.ToString())); crit.Orders.Add(new SortOrder("Date", SortType.Desc)); crit.Limit = MaxRevisionsReturned; var revisions = _urDao.Get(crit); return(revisions); }
/// <summary> /// Generate csv as string from target data set /// </summary> /// <returns></returns> public String Export() { // Filehelpers doesn't support creating a header row for writing // the csv file, so use the class mapping order. var header = string.Join(",", _readDao.ClassMap.AllDataColsInOrder.ToArray()); var rows = _readDao.Get(); var engine = new FileHelperEngine <T> { HeaderText = header }; engine.AfterWriteRecord += EngineOnAfterWriteRecord; return(engine.WriteString(rows)); }
private static void AssertMissingColumns(ClassMapping mapping, string fieldName, object uninitVal) { FastDAO<CsvTestObj> dao = new FastDAO<CsvTestObj>( new CsvDescriptor(CsvConnectionType.Directory, "..\\..\\Tests\\"), mapping); DictionaryDao dictDao = new DictionaryDao( new CsvDescriptor(CsvConnectionType.Directory, "..\\..\\Tests\\"), mapping); IList<CsvTestObj> objs = dao.Get(); IList<CheckedDictionary<string, object>> dicts = dictDao.Get(); Assert.AreEqual(12, objs.Count, "Wrong number of real objects."); Assert.AreEqual(12, dicts.Count, "Wrong number of dictionaries."); for (int x = 0; x < objs.Count; x++) { object val; switch (fieldName) { case "One": val = objs[x].One; break; case "Two": val = objs[x].Two; break; case "Three": val = objs[x].Three; break; case "Four": val = objs[x].Four; break; case "Five": val = objs[x].Five; break; default: throw new ArgumentException("Field " + fieldName + " isn't handled yet.", "fieldName"); } Assert.AreEqual(uninitVal, val, "Field '" + fieldName + "' should be uninitialized because it is unmapped, but isn't."); Assert.IsFalse(dicts[x].ContainsKey(fieldName), "Field '" + fieldName + "' should not be in the dictionary because it is unmapped."); } }