public EntityCollection<CatalogsEntity> GetAllParent(SortExpression sort) { EntityCollection<CatalogsEntity> cats = new EntityCollection<CatalogsEntity>(); SortExpression _sort = new SortExpression(); if (sort != null) { _sort = sort; } else { _sort.Add(CatalogsFields.CatalogName | SortOperator.Ascending); } IPredicateExpression predicate = new PredicateExpression(); predicate.Add(CatalogsFields.ParentId == 0); predicate.AddWithAnd(CatalogsFields.IsVisible == true); RelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(predicate); using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter()) { adapter.FetchEntityCollection(cats, filter, 0, _sort); } return cats; }
public AdminSitesCollection GetAdminSites(int siteUserGuid) { MCB.MasterPiece.Data.CollectionClasses.AdminSitesCollection adminSites = new AdminSitesCollection(); IRelationCollection relations = new RelationCollection(); relations.Add(AdminSitesEntity.Relations.AdminSiteModuleEntityUsingSiteGuid); relations.Add(AdminSiteModuleEntity.Relations.AdminUserAccessEntityUsingSiteModuleGuid); relations.Add(AdminUserAccessEntity.Relations.AdminUserEntityUsingUserGuid); IPredicateExpression filter = new PredicateExpression(); filter.Add(AdminUserAccessFields.UserGuid == siteUserGuid); filter.AddWithAnd(AdminSitesFields.AccountingMarkAsInactive != 1); IPredicateExpression sensitiveDataFilter = new PredicateExpression(); sensitiveDataFilter.Add(AdminUserFields.HasAccessToSitesWithSensitiveData == 1); sensitiveDataFilter.AddWithOr(AdminSitesFields.SiteContainsSensitiveData == 0); filter.AddWithAnd(sensitiveDataFilter); ISortExpression sort = new SortExpression(); sort.Add(AdminSitesFields.CostumerFullname | SortOperator.Ascending); adminSites.GetMulti(filter, 0, sort, relations); return(adminSites); }
/// <summary> /// Creates the attachment filter. The filter filters on attachments with the specified approvalstate in the threads viewable by the calling user. /// </summary> /// <param name="accessableForums">The accessable forums.</param> /// <param name="forumsWithApprovalRight">The forums with approval right.</param> /// <param name="forumsWithThreadsFromOthers">The forums with threads from others.</param> /// <param name="userID">The user ID.</param> /// <param name="filter">The filter.</param> /// <returns>ready to use predicate expression for fetch actions on attachments with the approval state specified in the threads /// matching the forumID's.</returns> private static PredicateExpression CreateAttachmentFilter(List <int> accessableForums, List <int> forumsWithApprovalRight, List <int> forumsWithThreadsFromOthers, int userID, bool approvalState) { PredicateExpression filter = new PredicateExpression(); // specify the filter for the accessable forums. Do this by a fieldcomparerange predicate and filter on Thread.ForumID. As 'accessableForums' is a list // the following statement will create a fieldcomparerange predicate for us. if (accessableForums.Count == 1) { // optimization, specify the only value instead of the range, so we won't get a WHERE Field IN (@param) query which is slow on some // databases, but we'll get a WHERE Field == @param filter.Add(ThreadFields.ForumID == accessableForums[0]); } else { filter.Add(ThreadFields.ForumID == accessableForums); } // specify the filter for the forums with approval rights: if (forumsWithApprovalRight.Count == 1) { // optimization, specify the only value instead of the range, so we won't get a WHERE Field IN (@param) query which is slow on some // databases, but we'll get a WHERE Field == @param filter.Add(ThreadFields.ForumID == forumsWithApprovalRight[0]); } else { filter.Add(ThreadFields.ForumID == forumsWithApprovalRight); } // Also filter on the threads viewable by the passed in userid, which is the caller of the method. If a forum isn't in the list of // forumsWithThreadsFromOthers, only the sticky threads and the threads started by userid should be counted / taken into account. filter.AddWithAnd(ThreadGuiHelper.CreateThreadFilter(forumsWithApprovalRight, userID)); // as last filter, we'll add a filter to only get the data for attachments which aren't approved yet. filter.AddWithAnd(AttachmentFields.Approved == false); return(filter); }
public MembershipEntity GetMember(string uName, string password) { MembershipCollection memberships = new MembershipCollection(); PredicateExpression filter = new PredicateExpression(); filter.AddWithAnd(MembershipFields.UserName == uName); filter.AddWithAnd(MembershipFields.Password == Business.Encryption.SHA1Encryption.EncryptMessage(password)); filter.AddWithAnd(MembershipFields.Status == true); memberships.GetMulti(filter); if (memberships.Count > 0) return memberships.FirstOrDefault(); else return null; }
/// <summary> /// Handles the Click event of the btnSearchPK control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void btnSearchPk_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } _filter = new PredicateExpression(); _filter.AddWithAnd(CustomerCustomerDemoFields.CustomerId == (System.String)Convert.ChangeType(tbxCustomerId.Text, typeof(System.String))); _filter.AddWithAnd(CustomerCustomerDemoFields.CustomerTypeId == (System.String)Convert.ChangeType(tbxCustomerTypeId.Text, typeof(System.String))); if ((SearchClicked != null) && (_filter.Count > 0)) { SearchClicked(this, new EventArgs()); } }
/// <summary> /// Handles the Click event of the btnSearchPK control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void btnSearchPk_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } _filter = new PredicateExpression(); _filter.AddWithAnd(OrderDetailFields.OrderId == (System.Int32)Convert.ChangeType(tbxOrderId.Text, typeof(System.Int32))); _filter.AddWithAnd(OrderDetailFields.ProductId == (System.Int32)Convert.ChangeType(tbxProductId.Text, typeof(System.Int32))); if ((SearchClicked != null) && (_filter.Count > 0)) { SearchClicked(this, new EventArgs()); } }
/// <summary> /// Handles the Click event of the btnSearchPK control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void btnSearchPk_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } _filter = new PredicateExpression(); _filter.AddWithAnd(EmployeeTerritoryFields.EmployeeId == (System.Int32)Convert.ChangeType(tbxEmployeeId.Text, typeof(System.Int32))); _filter.AddWithAnd(EmployeeTerritoryFields.TerritoryId == (System.String)Convert.ChangeType(tbxTerritoryId.Text, typeof(System.String))); if ((SearchClicked != null) && (_filter.Count > 0)) { SearchClicked(this, new EventArgs()); } }
/// <summary> /// Removes all users which ID's are stored in UsersToRemove, from the role with ID RoleID. /// </summary> /// <param name="userIDsToRemove">ArrayList with UserIDs of the users to Remove</param> /// <param name="roleID">ID of role the users will be removed from</param> /// <returns>true if succeeded, false otherwise</returns> public static bool RemoveUsersFromRole(List <int> userIDsToRemove, int roleID) { if (userIDsToRemove.Count <= 0) { return(true); } // we'll delete all role-user combinations for the users in the given range plus for the given role. // if there's just one user, we'll use an optimization, as the range query will result in an IN (param, param... ) query, // and an field IN (param) query, is much slower compared to field = param, at least on Sqlserver. // produce the filter which will be used to filter out the entities to delete. PredicateExpression filter = new PredicateExpression(); if (userIDsToRemove.Count == 1) { // use compare value predicate instead filter.Add((RoleUserFields.UserID == userIDsToRemove[0])); } else { // add a range filter filter.Add((RoleUserFields.UserID == userIDsToRemove)); } // add the filter for the role as with AND. filter.AddWithAnd((RoleUserFields.RoleID == roleID)); // delete the entities directly from the database. As this gives a single DELETE statement, we don't have to start a transaction manually. RoleUserCollection roleUsers = new RoleUserCollection(); return(roleUsers.DeleteMulti(filter) > 0); }
public static Double GetPurchases(Boolean sinceInception) { PurchaseHistoryCollection purchaseHistoryCollection = new PurchaseHistoryCollection(); try { Decimal totalPurchases = 0; if (!sinceInception) { PredicateExpression filter = new PredicateExpression(PurchaseHistoryFields.PurchaseTime >= DateTime.Now.Date); filter.AddWithAnd(PurchaseHistoryFields.PurchaseTime < DateTime.Now.Date.AddDays(1)); purchaseHistoryCollection.GetMulti(filter); } purchaseHistoryCollection.GetMulti(null); foreach (PurchaseHistoryEntity ece in purchaseHistoryCollection) { totalPurchases = totalPurchases + ece.AmountPaid; } return((Double)totalPurchases); } catch { return(0.00); } }
public virtual EntityCollection <ExcludeMatchDateEntity> GetExcludedDates(DateTime queryDate, long?tournamentId, long?roundId, long?teamId) { var filter = new RelationPredicateBucket(); var scopeFilter = new PredicateExpression(); // Condition 1: excluded on tournament level if (tournamentId != null) { scopeFilter.AddWithOr(ExcludeMatchDateFields.TournamentId == tournamentId); } // Condition 2: OR excluded on round level if (roundId != null) { scopeFilter.AddWithOr(ExcludeMatchDateFields.RoundId == roundId); } // Condition 3: OR excluded on team level if (teamId != null) { scopeFilter.AddWithOr(ExcludeMatchDateFields.TeamId == teamId); } filter.PredicateExpression.Add(scopeFilter); // Condition 4: AND date between from/to dates (including limiting dates) var dateFilter = new PredicateExpression(); dateFilter.AddWithAnd(ExcludeMatchDateFields.DateFrom <= queryDate.Date); dateFilter.AddWithAnd(ExcludeMatchDateFields.DateTo >= queryDate.Date); filter.PredicateExpression.Add(dateFilter); var excluded = new EntityCollection <ExcludeMatchDateEntity>(new ExcludeMatchDateEntityFactory()); using (var da = _appDb.DbContext.GetNewAdapter()) { da.FetchEntityCollection(excluded, filter); da.CloseConnection(); } //(return adapter.GetDbCount(new ExcludeMatchDateEntityFactory().CreateFields(), filter) == 0); return(excluded); }
public SourceCodeOrderDetail GetForSourceCodeIdAndOrderDetailId(long sourceCodeId, long orderDetailId) { IPredicateExpression predicateExpression = new PredicateExpression(SourceCodeOrderDetailFields.OrderDetailId == orderDetailId); predicateExpression.AddWithAnd(SourceCodeOrderDetailFields.SourceCodeId == sourceCodeId); return(GetByPredicate(predicateExpression).SingleOrDefault()); }
/// <summary> /// Creates a predicate expression filter based on the query string passed in. /// </summary> /// <param name="queryString">The query string with PK field names and values.</param> /// <returns>a predicate expression with a filter on the pk fields and values.</returns> public PredicateExpression CreateFilter(NameValueCollection queryString) { PredicateExpression toReturn = new PredicateExpression(); string valueFromQueryString = null; valueFromQueryString = queryString["EmployeeId"]; if (valueFromQueryString != null) { toReturn.AddWithAnd(EmployeeTerritoryFields.EmployeeId == (System.Int32)Convert.ChangeType(valueFromQueryString, typeof(System.Int32))); } valueFromQueryString = queryString["TerritoryId"]; if (valueFromQueryString != null) { toReturn.AddWithAnd(EmployeeTerritoryFields.TerritoryId == (System.String)Convert.ChangeType(valueFromQueryString, typeof(System.String))); } return(toReturn); }
/// <summary> /// Creates a predicate expression filter based on the query string passed in. /// </summary> /// <param name="queryString">The query string with PK field names and values.</param> /// <returns>a predicate expression with a filter on the pk fields and values.</returns> public PredicateExpression CreateFilter(NameValueCollection queryString) { PredicateExpression toReturn = new PredicateExpression(); string valueFromQueryString = null; valueFromQueryString = queryString["CustomerId"]; if (valueFromQueryString != null) { toReturn.AddWithAnd(CustomerCustomerDemoFields.CustomerId == (System.String)Convert.ChangeType(valueFromQueryString, typeof(System.String))); } valueFromQueryString = queryString["CustomerTypeId"]; if (valueFromQueryString != null) { toReturn.AddWithAnd(CustomerCustomerDemoFields.CustomerTypeId == (System.String)Convert.ChangeType(valueFromQueryString, typeof(System.String))); } return(toReturn); }
public MembershipEntity GetMember(string uName, string password) { MembershipCollection memberships = new MembershipCollection(); PredicateExpression filter = new PredicateExpression(); filter.AddWithAnd(MembershipFields.UserName == uName); filter.AddWithAnd(MembershipFields.Password == Business.Encryption.SHA1Encryption.EncryptMessage(password)); filter.AddWithAnd(MembershipFields.Status == true); memberships.GetMulti(filter); if (memberships.Count > 0) { return(memberships.FirstOrDefault()); } else { return(null); } }
/// <summary> /// Creates a predicate expression filter based on the query string passed in. /// </summary> /// <param name="queryString">The query string with PK field names and values.</param> /// <returns>a predicate expression with a filter on the pk fields and values.</returns> public PredicateExpression CreateFilter(NameValueCollection queryString) { PredicateExpression toReturn = new PredicateExpression(); string valueFromQueryString = null; valueFromQueryString = queryString["OrderId"]; if (valueFromQueryString != null) { toReturn.AddWithAnd(OrderDetailFields.OrderId == (System.Int32)Convert.ChangeType(valueFromQueryString, typeof(System.Int32))); } valueFromQueryString = queryString["ProductId"]; if (valueFromQueryString != null) { toReturn.AddWithAnd(OrderDetailFields.ProductId == (System.Int32)Convert.ChangeType(valueFromQueryString, typeof(System.Int32))); } return(toReturn); }
public AdminUserEntity GetAdminUser(int userGuid) { var filter = new PredicateExpression(); filter.AddWithAnd(AdminUserFields.UserGuid == userGuid); var userCollection = new AdminUserCollection(); userCollection.GetMulti(filter); return(userCollection.FirstOrDefault()); }
/// <summary> /// Returns valid entities which are valid for given moment in time. /// Valid entities have: /// 1. Begining is not NULL AND is LESS than given moment in time. /// 2. End is NULL OR is GREATER OR EQUAL than given moment in time. /// </summary> public static PredicateExpression FilterValidEntities(DateTime momentInTime, EntityField2 validFromDateTimeField, EntityField2 validToDateTimeField) { PredicateExpression predicateExpression = new PredicateExpression(); predicateExpression.Add(validFromDateTimeField != DBNull.Value & validFromDateTimeField <= momentInTime); predicateExpression.AddWithAnd(validToDateTimeField == DBNull.Value | validToDateTimeField >= momentInTime); return predicateExpression; }
private static IPredicate BuildPredicateTree(Func <string, IEntityField2> fieldGetter, Func <string, List <IEntityRelation>, IEntityField2> relatedFieldGetter, FilterNode filterNode, List <IEntityRelation> inferredRelationsList) { if (filterNode.NodeCount > 0) { if (filterNode.NodeType == FilterNodeType.Root && filterNode.Nodes.Count > 0) { if (filterNode.NodeCount == 1) { return(BuildPredicateTree(fieldGetter, relatedFieldGetter, filterNode.Nodes[0], inferredRelationsList)); } var predicate = new PredicateExpression(); foreach (var childNode in filterNode.Nodes) { var newPredicate = BuildPredicateTree(fieldGetter, relatedFieldGetter, childNode, inferredRelationsList); if (newPredicate != null) { predicate.AddWithAnd(newPredicate); } } return(predicate); } else if (filterNode.NodeType == FilterNodeType.AndExpression || filterNode.NodeType == FilterNodeType.OrExpression) { var predicate = new PredicateExpression(); foreach (var childNode in filterNode.Nodes) { var newPredicate = BuildPredicateTree(fieldGetter, relatedFieldGetter, childNode, inferredRelationsList); if (newPredicate != null) { if (filterNode.NodeType == FilterNodeType.OrExpression) { predicate.AddWithOr(newPredicate); } else { predicate.AddWithAnd(newPredicate); } } } return(predicate); } } else if (filterNode.ElementCount > 0) { // convert elements to IPredicate var nodePredicate = BuildPredicateFromClauseNode(fieldGetter, relatedFieldGetter, filterNode, inferredRelationsList); if (nodePredicate != null) { return(nodePredicate); } } return(null); }
public AdminUserCollection GetAdminUserCollection(SiteAdminTypeEnum adminSiteType, string userName, string email, string token) { var userCollection = new AdminUserCollection(); if (string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(email) && string.IsNullOrEmpty(token)) { return(userCollection); } var filter = new PredicateExpression(); var relations = new RelationCollection(); if (adminSiteType == SiteAdminTypeEnum.Accumolo) { relations.Add(AdminUserEntityBase.Relations.AdminUserAccessEntityUsingUserGuid); relations.Add(AdminUserAccessEntityBase.Relations.AdminSiteModuleEntityUsingSiteModuleGuid); relations.Add(AdminSiteModuleEntityBase.Relations.AdminSitesEntityUsingSiteGuid); filter.AddWithAnd(AdminSitesFields.AccountingMarkAsInactive != 1); } else if (adminSiteType == SiteAdminTypeEnum.Management) { filter.Add(AdminUserFields.UserManagementAccess == true); } if (!string.IsNullOrEmpty(userName)) { filter.AddWithAnd(AdminUserFields.UserName == userName); } if (!string.IsNullOrEmpty(email)) { filter.AddWithAnd(AdminUserFields.UserEmail == email); } if (!string.IsNullOrEmpty(token)) { filter.AddWithAnd(AdminUserFields.UserPasswordResetToken == token); filter.AddWithAnd(AdminUserFields.TokenExpiration >= DateTime.Now); } userCollection.GetMulti(filter, relations); return(userCollection); }
public static EntityCollection <GroupRecordPermissionEntity> GetGroupPermissions(int groupUID, int entityTypeGUID, int uID) { //User Entity Type 2 EntityCollection <GroupRecordPermissionEntity> l_coll = new EntityCollection <GroupRecordPermissionEntity>(); //Create filter for GUID's IPredicateExpression l_filter = new PredicateExpression(); l_filter.Add(GroupRecordPermissionFields.RecordUID == uID); l_filter.AddWithAnd(GroupRecordPermissionFields.EntityTypeGUID == entityTypeGUID); l_filter.AddWithAnd(GroupRecordPermissionFields.GroupUID == groupUID); //Add to a bucket RelationPredicateBucket l_bucket = new RelationPredicateBucket(l_filter); //Retreive data DataAccessAdapter l_daa = new DataAccessAdapter(); l_daa.FetchEntityCollection(l_coll, l_bucket); return(l_coll); }
public static int GetDaysSupportRequests() { SupportIssueCollection supportIssueCollection = new SupportIssueCollection(); try { PredicateExpression filter = new PredicateExpression(SupportIssueFields.CreateTime >= DateTime.Now.Date); filter.AddWithAnd(SupportIssueFields.CreateTime < DateTime.Now.Date.AddDays(1)); return(supportIssueCollection.GetDbCount(filter)); } catch { return(0); } }
public static int GetActiveDevices() { DeviceCollection ecDeviceCollection = new DeviceCollection(); try { PredicateExpression filter = new PredicateExpression(DeviceFields.LastReportTime >= DateTime.Now.Date); filter.AddWithAnd(DeviceFields.LastReportTime < DateTime.Now.Date.AddDays(1)); return(ecDeviceCollection.GetDbCount(filter)); } catch { return(0); } }
public static Int64 GetDaysExceptions() { ExceptionLogCollection exceptionLogCollection = new ExceptionLogCollection(); try { PredicateExpression filter = new PredicateExpression(ExceptionLogFields.ReceivedTime >= DateTime.Now.Date); filter.AddWithAnd(ExceptionLogFields.ReceivedTime < DateTime.Now.Date.AddDays(1)); return(exceptionLogCollection.GetDbCount(filter)); } catch { return(0L); } }
public Auction.Domain.Bidder GetByNumberAndEvent(int number, long eventId, ref IAuctionTransaction trans) { using(var records = new BidderCollection()) { var filter = new PredicateExpression(BidderFields.EventId == eventId); filter.AddWithAnd(BidderFields.Number == number); if(trans != null) { trans.Add(records); } records.GetMulti(filter, 1); var b = records.ToList().FirstOrDefault(); return new Bidder() { Id = b.Id, Number = number, Name = b.Name, EventId = eventId, Phone = b.Phone }; } }
/// <summary> /// Gets the matches (<see cref="PlannedMatchRow"/>s) for a venue, which are occupied within the given <see cref="DateTimePeriod"/> of a tournament. /// </summary> /// <param name="venueId"></param> /// <param name="searchPeriod"></param> /// <param name="tournamentId"></param> /// <param name="cancellationToken"></param> /// <returns>Returns the matches (<see cref="PlannedMatchRow"/>s) for a venue, which are occupied within the given <see cref="DateTimePeriod"/> of a tournament.</returns> public virtual async Task <List <PlannedMatchRow> > GetOccupyingMatchesAsync(long venueId, DateTimePeriod searchPeriod, long tournamentId, CancellationToken cancellationToken) { using var da = _dbContext.GetNewAdapter(); var metaData = new LinqMetaData(da); var matchIds = await(from m in metaData.Match where m.Round.TournamentId == tournamentId && m.VenueId == venueId && !m.IsComplete && m.PlannedStart.HasValue && m.PlannedEnd.HasValue && (m.PlannedStart <= searchPeriod.End && searchPeriod.Start <= m.PlannedEnd) // overlapping periods select m.Id).ExecuteAsync <List <long> >(cancellationToken); var filter = new PredicateExpression(PlannedMatchFields.TournamentId == tournamentId); filter.AddWithAnd(PlannedMatchFields.Id.In(matchIds)); return(matchIds.Count > 0 ? await new MatchRepository(_dbContext).GetPlannedMatchesAsync(filter, cancellationToken) : new List <PlannedMatchRow>()); }
public DocumentEntity GetByID(Guid ID) { EntityCollection<DocumentEntity> items = new EntityCollection<DocumentEntity>(); IPredicateExpression predicate = new PredicateExpression(); predicate.Add(DocumentFields.Id == ID); predicate.AddWithAnd(DocumentFields.IsDeleted == false); RelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(predicate); using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter()) { adapter.FetchEntityCollection(items, filter); } if (items != null && items.Count > 0) return items[0]; return null; }
public CodeMarkEntity GetByCode(string code) { EntityCollection<CodeMarkEntity> items = new EntityCollection<CodeMarkEntity>(); IPredicateExpression predicate = new PredicateExpression(); predicate.Add(CodeMarkFields.Code == code); predicate.AddWithAnd(CodeMarkFields.IsDeleted == false); RelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(predicate); using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter()) { adapter.FetchEntityCollection(items, filter); } if (items != null && items.Count > 0) return items[0]; return null; }
public bool IsExistsGroupName(string GroupName, string PositionId) { EntityCollection<AdvertsPositionEntity> items = new EntityCollection<AdvertsPositionEntity>(); IPredicateExpression predicate = new PredicateExpression(); predicate.Add(AdvertsPositionFields.GroupName == GroupName); predicate.AddWithAnd(AdvertsPositionFields.PositionId == PositionId); RelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(predicate); using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter()) { adapter.FetchEntityCollection(items, filter); } if (items != null && items.Count > 0) return true; return false; }
public IEnumerable <ShippingDetailOrderDetail> GetForOrderDetailId(long orderDetailId) { IPredicateExpression predicateExpression = new PredicateExpression(ShippingDetailOrderDetailFields.IsActive == true); predicateExpression.AddWithAnd(ShippingDetailOrderDetailFields.OrderDetailId == orderDetailId); var prefetchPath = new PrefetchPath2(EntityType.ShippingDetailOrderDetailEntity) { ShippingDetailOrderDetailEntity.PrefetchPathShippingDetail }; var entityCollection = new EntityCollection <ShippingDetailOrderDetailEntity>(); IRelationPredicateBucket bucket = new RelationPredicateBucket(predicateExpression); using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { adapter.FetchEntityCollection(entityCollection, bucket, prefetchPath); } return(Mapper.MapMultiple(entityCollection).ToList()); }
/// <summary> /// Returns predicate which returns single (on none) entity for given moment in time. /// Vraća predikat koji filtrira jedan entitet koji je validan za dani momentInTime. /// </summary> /// <param name="setFilter">Additional filter which applies before datetime predicate.</param> public static PredicateExpression FilterValidEntities(DateTime momentInTime, EntityField2 validDateTimeField, IPredicateExpression setFilter) { PredicateExpression newSetFilter; if (null != setFilter) { newSetFilter = new PredicateExpression(setFilter); newSetFilter.AddWithAnd(validDateTimeField <= momentInTime); } else { newSetFilter = new PredicateExpression(validDateTimeField <= momentInTime); } PredicateExpression toReturn = new PredicateExpression(); toReturn.Add(validDateTimeField <= momentInTime); toReturn.Add(new FieldCompareSetPredicate(validDateTimeField, null, validDateTimeField, null, SetOperator.GreaterEqualAll, newSetFilter)); return toReturn; }
public static Int64 GetScanCount(Boolean sinceInception) { //Random r = new Random(); //Thread.Sleep(20); //Int64 Newvalue = r.Next(); //return Newvalue; ScanHistoryCollection scanHistoryCollection = new ScanHistoryCollection(); try { if (sinceInception) { return((long)scanHistoryCollection.GetDbCount()); } PredicateExpression filter = new PredicateExpression(ScanHistoryFields.ScanStartTime >= DateTime.Now.Date); filter.AddWithAnd(ScanHistoryFields.ScanStartTime < DateTime.Now.Date.AddDays(1)); return(scanHistoryCollection.GetDbCount(filter)); } catch { return(0L); } }
/// <summary> /// Creates the thread filter. Filters on the threads viewable by the passed in userid, which is the caller of the method. /// If a forum isn't in the list of forumsWithThreadsFromOthers, only the sticky threads and the threads started by userid should /// be counted / taken into account. /// </summary> /// <param name="forumsWithThreadsFromOthers">The forums with threads from others.</param> /// <param name="userID">The user ID.</param> /// <returns>ready to use thread filter.</returns> internal static IPredicateExpression CreateThreadFilter(List <int> forumsWithThreadsFromOthers, int userID) { var threadFilter = new PredicateExpression(); if ((forumsWithThreadsFromOthers != null) && (forumsWithThreadsFromOthers.Count > 0)) { PredicateExpression onlyOwnThreadsFilter = new PredicateExpression(); // accept only those threads who aren't in the forumsWithThreadsFromOthers list and which are either started by userID or sticky. // the filter on the threads not in the forums listed in the forumsWithThreadsFromOthers if (forumsWithThreadsFromOthers.Count == 1) { // optimization, specify the only value instead of the range, so we won't get a WHERE Field IN (@param) query which is slow on some // databases, but we'll get a WHERE Field == @param // accept all threads which are in a forum located in the forumsWithThreadsFromOthers list threadFilter.Add((ThreadFields.ForumID == forumsWithThreadsFromOthers[0])); onlyOwnThreadsFilter.Add(ThreadFields.ForumID != forumsWithThreadsFromOthers[0]); } else { // accept all threads which are in a forum located in the forumsWithThreadsFromOthers list threadFilter.Add((ThreadFields.ForumID == forumsWithThreadsFromOthers)); onlyOwnThreadsFilter.Add(ThreadFields.ForumID != forumsWithThreadsFromOthers); } // the filter on either sticky or threads started by the calling user onlyOwnThreadsFilter.AddWithAnd((ThreadFields.IsSticky == true).Or(ThreadFields.StartedByUserID == userID)); threadFilter.AddWithOr(onlyOwnThreadsFilter); } else { // there are no forums enlisted in which the user has the right to view threads from others. So just filter on // sticky threads or threads started by the calling user. threadFilter.Add((ThreadFields.IsSticky == true).Or(ThreadFields.StartedByUserID == userID)); } return(threadFilter); }
/// <summary> /// Removes all users which ID's are stored in UsersToRemove, from the role with ID RoleID. /// </summary> /// <param name="userIDsToRemove">ArrayList with UserIDs of the users to Remove</param> /// <param name="roleID">ID of role the users will be removed from</param> /// <returns>true if succeeded, false otherwise</returns> public static bool RemoveUsersFromRole(List<int> userIDsToRemove, int roleID) { if(userIDsToRemove.Count<=0) { return true; } // we'll delete all role-user combinations for the users in the given range plus for the given role. // if there's just one user, we'll use an optimization, as the range query will result in an IN (param, param... ) query, // and an field IN (param) query, is much slower compared to field = param, at least on Sqlserver. // produce the filter which will be used to filter out the entities to delete. PredicateExpression filter = new PredicateExpression(); if(userIDsToRemove.Count == 1) { // use compare value predicate instead filter.Add((RoleUserFields.UserID == userIDsToRemove[0])); } else { // add a range filter filter.Add((RoleUserFields.UserID == userIDsToRemove)); } // add the filter for the role as with AND. filter.AddWithAnd((RoleUserFields.RoleID == roleID)); // delete the entities directly from the database. As this gives a single DELETE statement, we don't have to start a transaction manually. RoleUserCollection roleUsers = new RoleUserCollection(); return (roleUsers.DeleteMulti(filter) > 0); }
/// <summary> /// Za svaki član this.rules kolekcije kreira jedan Predicate. /// Ako je rules.Count == 0 vraća NULL /// </summary> /// <returns>PredicateExpression</returns> /// <param name="entityFieldsType">Ako se filtrira artikl onda typeof(ArtiklFields)</param> /// <param name="getEntityFieldTypeFunction">Funkcija prima string (EntityFields type name) a vraća tip. Ako se desi da se filtrira po entitetu vezanom na glavni entitet (RacunGlava.Partner) tada se koristi ova funkcija za dohvat EntityFieldsType preko refleksije.</param> public PredicateExpression KreirajPredicate(Type entityFieldsType, Func<string, Type> getEntityFieldTypeFunction) { PredicateExpression toReturn = null; if (rules.Count() > 0) { toReturn = new PredicateExpression(); foreach (JqGridFilterItem item in rules) { Predicate predicateToAdd = JqGridFilter.KreirajPredikatIzJqGridFilterItem(entityFieldsType, item, getEntityFieldTypeFunction); if (predicateToAdd != null) { if (groupOp.ToUpper() == "AND") { toReturn.AddWithAnd(predicateToAdd); } else if (groupOp.ToUpper() == "OR") { toReturn.AddWithOr(predicateToAdd); } } } } return toReturn; }
public EntityCollection<EventsEntity> GetEvents(string EventType) { EntityCollection<EventsEntity> items = new EntityCollection<EventsEntity>(); IPredicateExpression predicate = new PredicateExpression(); predicate.Add(EventsFields.EventType == EventType); predicate.AddWithAnd(EventsFields.Approved == false); RelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(predicate); SortExpression sort = new SortExpression(); sort.Add(EventsFields.CreatedDate | SortOperator.Descending); using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter()) { adapter.FetchEntityCollection(items, filter); } return items; }
/// <summary> /// Creates the thread filter. Filters on the threads viewable by the passed in userid, which is the caller of the method. /// If a forum isn't in the list of forumsWithThreadsFromOthers, only the sticky threads and the threads started by userid should /// be counted / taken into account. /// </summary> /// <param name="forumsWithThreadsFromOthers">The forums with threads from others.</param> /// <param name="userID">The user ID.</param> /// <returns>ready to use thread filter.</returns> internal static IPredicateExpression CreateThreadFilter(List<int> forumsWithThreadsFromOthers, int userID) { var threadFilter = new PredicateExpression(); if((forumsWithThreadsFromOthers != null) && (forumsWithThreadsFromOthers.Count > 0)) { PredicateExpression onlyOwnThreadsFilter = new PredicateExpression(); // accept only those threads who aren't in the forumsWithThreadsFromOthers list and which are either started by userID or sticky. // the filter on the threads not in the forums listed in the forumsWithThreadsFromOthers if(forumsWithThreadsFromOthers.Count == 1) { // optimization, specify the only value instead of the range, so we won't get a WHERE Field IN (@param) query which is slow on some // databases, but we'll get a WHERE Field == @param // accept all threads which are in a forum located in the forumsWithThreadsFromOthers list threadFilter.Add((ThreadFields.ForumID == forumsWithThreadsFromOthers[0])); onlyOwnThreadsFilter.Add(ThreadFields.ForumID != forumsWithThreadsFromOthers[0]); } else { // accept all threads which are in a forum located in the forumsWithThreadsFromOthers list threadFilter.Add((ThreadFields.ForumID == forumsWithThreadsFromOthers)); onlyOwnThreadsFilter.Add(ThreadFields.ForumID != forumsWithThreadsFromOthers); } // the filter on either sticky or threads started by the calling user onlyOwnThreadsFilter.AddWithAnd((ThreadFields.IsSticky == true).Or(ThreadFields.StartedByUserID == userID)); threadFilter.AddWithOr(onlyOwnThreadsFilter); } else { // there are no forums enlisted in which the user has the right to view threads from others. So just filter on // sticky threads or threads started by the calling user. threadFilter.Add((ThreadFields.IsSticky == true).Or(ThreadFields.StartedByUserID == userID)); } return threadFilter; }
public void RemoveFromEvent(long donorId, long eventId, ref IAuctionTransaction trans) { using (var records = new AuctionEventDonorCollection()) { var filter = new PredicateExpression { AuctionEventDonorFields.DonorId == donorId }; filter.AddWithAnd(AuctionEventDonorFields.EventId == eventId); records.DeleteMulti(filter); } }
public EntityCollection<CatalogsEntity> GetByParentIdNotId(int Id, int ParentId) { EntityCollection<CatalogsEntity> cats = new EntityCollection<CatalogsEntity>(); SortExpression _sort = new SortExpression(); _sort.Add(CatalogsFields.CatalogName | SortOperator.Ascending); IPredicateExpression predicate = new PredicateExpression(); predicate.Add(CatalogsFields.ParentId == ParentId); predicate.AddWithAnd(CatalogsFields.Id != Id); RelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(predicate); using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter()) { adapter.FetchEntityCollection(cats, filter, 0, _sort); } return cats; }
private static IPredicate BuildPredicateTree(Func<string, IEntityField2> fieldGetter, Func<string, List<IEntityRelation>, IEntityField2> relatedFieldGetter, FilterNode filterNode, List<IEntityRelation> inferredRelationsList) { if (filterNode.NodeCount > 0) { if (filterNode.NodeType == FilterNodeType.Root && filterNode.Nodes.Count > 0) { if (filterNode.NodeCount == 1) return BuildPredicateTree(fieldGetter, relatedFieldGetter, filterNode.Nodes[0], inferredRelationsList); var predicate = new PredicateExpression(); foreach (var childNode in filterNode.Nodes) { var newPredicate = BuildPredicateTree(fieldGetter, relatedFieldGetter, childNode, inferredRelationsList); if (newPredicate != null) predicate.AddWithAnd(newPredicate); } return predicate; } else if (filterNode.NodeType == FilterNodeType.AndExpression || filterNode.NodeType == FilterNodeType.OrExpression) { var predicate = new PredicateExpression(); foreach (var childNode in filterNode.Nodes) { var newPredicate = BuildPredicateTree(fieldGetter, relatedFieldGetter, childNode, inferredRelationsList); if (newPredicate != null) { if (filterNode.NodeType == FilterNodeType.OrExpression) predicate.AddWithOr(newPredicate); else predicate.AddWithAnd(newPredicate); } } return predicate; } } else if (filterNode.ElementCount > 0) { // convert elements to IPredicate var nodePredicate = BuildPredicateFromClauseNode(fieldGetter, relatedFieldGetter, filterNode, inferredRelationsList); if (nodePredicate != null) return nodePredicate; } return null; }