Permalink
Browse files

Further porting work. Almost done.

  • Loading branch information...
Solutionsdesign
Solutionsdesign committed Jun 13, 2012
1 parent 3e314dc commit 9093301c40d1875275c940446d3bc2fd4088f8a7
View
@@ -99,55 +99,45 @@ public static ForumMessagesTypedList GetLastPostedMessagesInForum(int amount, in
break;
}
// We'll use a dynamic list to retrieve all threads for the given forum in the right order, for the given limiter.
ResultsetFields fields = ThreadGuiHelper.BuildDynamicListForAllThreadsWithStats();
// now build the relations for the dynamic list. We'll join User twice: once for the startuser and one for the lastpost user.
// also, we'll join the last message to the thread. The last message is joined with a custom filter added to the relation.
RelationCollection relations = ThreadGuiHelper.BuildRelationsForAllThreadsWithStats();
// Set up query conditions using Predicate Expressions
// we'll keep the sticky threads filter and the forum filter in separate variables as we'll re-use them later on.
FieldCompareValuePredicate stickyThreadsFilter = (FieldCompareValuePredicate)(ThreadFields.IsSticky == true);
var forumFilter = ThreadFields.ForumID == forumID;
var filter = forumFilter.And(stickyThreadsFilter.Or(ThreadFields.ThreadLastPostingDate >= limiterDate));
var qf = new QueryFactory();
var q = qf.Create();
q.Select(ThreadGuiHelper.BuildQueryProjectionForAllThreadsWithStats(qf));
q.From(ThreadGuiHelper.BuildFromClauseForAllThreadsWithStats(qf));
q.Where(((ThreadFields.IsSticky == true).Or(ThreadFields.ThreadLastPostingDate >= limiterDate)).And(ThreadFields.ForumID == forumID));
// if the user can't view threads started by others, filter out threads started by users different from userID
if(!canViewNormalThreadsStartedByOthers)
{
// caller can't view threads started by others: add a filter so that threads not started by calling user aren't enlisted.
// however sticky threads are always returned so the filter contains a check so the limit is only applied on threads which aren't sticky
// add a filter for sticky threads, add it with 'OR', so sticky threads are always accepted
filter.AddWithAnd((ThreadFields.StartedByUserID == userID).Or(ThreadFields.IsSticky == true));
q.AndWhere((ThreadFields.StartedByUserID == userID).Or(ThreadFields.IsSticky == true));
}
//Set up the sort expressions
SortExpression sorter = new SortExpression(ThreadFields.IsSticky.Descending());
sorter.Add(ThreadFields.IsClosed.Ascending());
sorter.Add(ThreadFields.ThreadLastPostingDate.Descending());
q.OrderBy(ThreadFields.IsSticky.Descending(), ThreadFields.IsClosed.Ascending(), ThreadFields.ThreadLastPostingDate.Descending());
var dao = new TypedListDAO();
var threads = dao.FetchAsDataTable(q);
DataTable threads = new DataTable();
TypedListDAO dao = new TypedListDAO();
// Get the data by fetching the dynamic list into the datatable using the filter and the sorter we just setup.
dao.GetMultiAsDataTable(fields, threads, 0, sorter, filter, relations, true, null, null, 0, 0);
// count # non-sticky threads. If it's below a given minimum, refetch everything, but now don't fetch on date filtered but at least the
// set minimum. Do this ONLY if the user can view other user's threads. If that's NOT the case, don't refetch anything.
DataView stickyThreads = new DataView(threads, ThreadFieldIndex.IsSticky.ToString() + "=false", "", DataViewRowState.CurrentRows);
if((stickyThreads.Count < minNumberOfNonStickyVisibleThreads) && canViewNormalThreadsStartedByOthers)
{
// not enough threads available, fetch again,
threads = new DataTable();
// first fetch the sticky threads.
filter = forumFilter.And(stickyThreadsFilter);
sorter = new SortExpression(ThreadFields.ThreadLastPostingDate.Descending());
dao.GetMultiAsDataTable(fields, threads, 0, sorter, filter, relations, true, null, null, 0, 0);
q = qf.Create();
q.Select(ThreadGuiHelper.BuildQueryProjectionForAllThreadsWithStats(qf));
q.From(ThreadGuiHelper.BuildFromClauseForAllThreadsWithStats(qf));
q.Where((ThreadFields.IsSticky == true).And(ThreadFields.ForumID == forumID));
q.OrderBy(ThreadFields.ThreadLastPostingDate.Descending());
threads = dao.FetchAsDataTable(q);
// then fetch the rest. Fetch it into the same datatable object to append the rows to the already fetched sticky threads (if any)
stickyThreadsFilter.Value=false;
dao.GetMultiAsDataTable(fields, threads, minNumberOfThreadsToFetch, sorter, filter, relations, true, null, null, 0, 0);
q = qf.Create();
q.Select(ThreadGuiHelper.BuildQueryProjectionForAllThreadsWithStats(qf));
q.From(ThreadGuiHelper.BuildFromClauseForAllThreadsWithStats(qf));
q.Where((ThreadFields.IsSticky == false).And(ThreadFields.ForumID == forumID));
q.Limit(minNumberOfThreadsToFetch);
q.OrderBy(ThreadFields.ThreadLastPostingDate.Descending());
dao.FetchAsDataTable(q, threads);
// sort closed threads to the bottom. Do this in-memory as it's a sort operation after projection. Doing it on the server would mean
// a sort operation before projection.
View
@@ -100,14 +100,11 @@ public static bool ModifySection(int ID, string name, string description, short
/// <returns>True if succeeded, false otherwise</returns>
public static bool DeleteSection(int ID)
{
// trying to delete the entity directly from the database without first loading it.
// for that we use an entity collection and use the DeleteMulti method with a filter on the PK.
PredicateExpression deleteFilter = new PredicateExpression();
deleteFilter.Add(SectionFields.SectionID == ID);
// trying to delete the entity directly from the database without first loading it.
// for that we use an entity collection and use the DeleteMulti method with a filter on the PK.
SectionCollection sections = new SectionCollection();
// try to delete the entity
int deletedRows = sections.DeleteMulti(deleteFilter);
int deletedRows = sections.DeleteMulti(SectionFields.SectionID == ID);
// there should only be one deleted row, since we are filtering by the PK.
// return true if there's 1, otherwise false.
View
@@ -29,6 +29,9 @@
using SD.LLBLGen.Pro.ORMSupportClasses;
using SD.HnD.DAL.DaoClasses;
using System.Collections.Generic;
using SD.LLBLGen.Pro.QuerySpec.SelfServicing;
using SD.LLBLGen.Pro.QuerySpec;
using SD.HnD.DAL.FactoryClasses;
namespace SD.HnD.BL
{
@@ -44,18 +47,19 @@ public static class SecurityGuiHelper
public static RoleCollection GetAllRoles()
{
RoleCollection toReturn = new RoleCollection();
toReturn.GetMulti(null, 0, new SortExpression(RoleFields.RoleDescription | SortOperator.Ascending));
toReturn.GetMulti(null, 0, new SortExpression(RoleFields.RoleDescription.Ascending()));
return toReturn;
}
/// <summary>
/// Gets all audit actions.
/// </summary>
/// <returns></returns>
public static AuditActionCollection GetAllAuditActions()
{
AuditActionCollection toReturn = new AuditActionCollection();
toReturn.GetMulti(null, 0, new SortExpression(AuditActionFields.AuditActionDescription | SortOperator.Ascending));
toReturn.GetMulti(null, 0, new SortExpression(AuditActionFields.AuditActionDescription.Ascending()));
return toReturn;
}
@@ -80,13 +84,16 @@ public static RoleAuditActionCollection GetAllAuditActionsForRole(int roleID)
/// <returns>All audit data objects (polymorphic)</returns>
public static AuditDataCoreCollection GetAllAuditsForUser(int userID)
{
var qf = new QueryFactory();
var q = qf.AuditDataCore
.Where(AuditDataCoreFields.UserID==userID)
.OrderBy(AuditDataCoreFields.AuditedOn.Descending())
.Limit(50)
.WithPath(AuditDataMessageRelatedEntity.PrefetchPathMessage.WithSubPath(MessageEntity.PrefetchPathThread),
AuditDataThreadRelatedEntity.PrefetchPathThread);
AuditDataCoreCollection toReturn = new AuditDataCoreCollection();
// setup polymorphic prefetch paths:
PrefetchPath path = new PrefetchPath((int)EntityType.AuditDataCoreEntity);
path.Add(AuditDataMessageRelatedEntity.PrefetchPathMessage).SubPath.Add(MessageEntity.PrefetchPathThread);
path.Add(AuditDataThreadRelatedEntity.PrefetchPathThread);
toReturn.GetMulti((AuditDataCoreFields.UserID == userID),
50, new SortExpression(AuditDataCoreFields.AuditedOn | SortOperator.Descending), null, path);
toReturn.GetMulti(q);
return toReturn;
}
@@ -110,7 +117,7 @@ public static IPBanCollection GetAllIPBans(int pageNo, int pageSize, bool prefet
path = new PrefetchPath((int)EntityType.IPBanEntity);
path.Add(IPBanEntity.PrefetchPathSetByUser);
}
toReturn.GetMulti(null, 0, new SortExpression(IPBanFields.Range | SortOperator.Ascending), null, path, pageNo, pageSize);
toReturn.GetMulti(null, 0, new SortExpression(IPBanFields.Range.Ascending()), null, path, pageNo, pageSize);
return toReturn;
}
@@ -135,24 +142,24 @@ public static DataView GetAllRolesWithStatisticsAsDataView()
// create dynamic list, with all fields of Role and 3 extra fields: one field for the # of users in the role, one field which
// signals if the role is the defaultnewuserrole and one field which signals if the role is the anonymous role. The # of users field is
// used in the query, the other two fields are added later for efficiency.
ResultsetFields fields = new ResultsetFields((int)RoleFieldIndex.AmountOfFields + 1);
fields.DefineField(RoleFields.RoleID, 0);
fields.DefineField(RoleFields.RoleDescription, 1);
// now add the # of users subquery to the resultset. This will result in the query:
// (
// SELECT COUNT(UserID)
// FROM RoleUser
// WHERE RoleUser.RoleID = Role.RoleID
// ) AS AmountUsersInRole
fields.DefineField(new EntityField("AmountUsersInRole",
new ScalarQueryExpression(RoleUserFields.UserID.SetAggregateFunction(AggregateFunction.Count),
(RoleUserFields.RoleID == RoleFields.RoleID))), 2);
// fetch the data into a datatable.
DataTable results = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, results, 0, new SortExpression( RoleFields.RoleDescription | SortOperator.Ascending ),
null, null, true, null, null, 0, 0);
var qf = new QueryFactory();
var q = qf.Create()
.Select(RoleFields.RoleID,
RoleFields.RoleDescription,
// now add the # of users subquery to the resultset. This will result in the query:
// (
// SELECT COUNT(UserID)
// FROM RoleUser
// WHERE RoleUser.RoleID = Role.RoleID
// ) AS AmountUsersInRole
qf.Create()
.Select(RoleUserFields.UserID.Count())
.CorrelatedOver(RoleUserFields.RoleID == RoleFields.RoleID)
.ToScalar()
.As("AmountUsersInRole"))
.OrderBy(RoleFields.RoleDescription.Ascending());
var dao = new TypedListDAO();
var results = dao.FetchAsDataTable(q);
// we now fetch the system data which contains the two role id's we've to check with in the results to return.
SystemDataEntity systemData = SystemGuiHelper.GetSystemSettings();
@@ -210,9 +217,7 @@ public static RoleSystemActionRightCollection GetSystemActionRightRolesForRole(i
public static ForumRoleForumActionRightCollection GetForumActionRightRolesFoForumRole(int roleID, int forumID)
{
ForumRoleForumActionRightCollection toReturn = new ForumRoleForumActionRightCollection();
PredicateExpression filter = new PredicateExpression(ForumRoleForumActionRightFields.RoleID == roleID);
filter.AddWithAnd((ForumRoleForumActionRightFields.ForumID==forumID));
toReturn.GetMulti(filter);
toReturn.GetMulti((ForumRoleForumActionRightFields.RoleID == roleID).And(ForumRoleForumActionRightFields.ForumID==forumID));
return toReturn;
}
@@ -224,7 +229,7 @@ public static ForumRoleForumActionRightCollection GetForumActionRightRolesFoForu
public static ActionRightCollection GetAllActionRightsApplybleToAForum()
{
ActionRightCollection toReturn = new ActionRightCollection();
toReturn.GetMulti((ActionRightFields.AppliesToForum == true), 0, new SortExpression( ActionRightFields.ActionRightID | SortOperator.Ascending ) );
toReturn.GetMulti((ActionRightFields.AppliesToForum == true), 0, new SortExpression( ActionRightFields.ActionRightID.Ascending()) );
return toReturn;
}
@@ -301,22 +306,18 @@ public static ForumRoleForumActionRightCollection GetForumsActionRightsForUser(i
/// <returns>fetched collection</returns>
public static AuditActionCollection GetAuditActionsForUser(int userID)
{
AuditActionCollection auditActions = new AuditActionCollection();
// the subquery in the filter requires joins as the filter's subquery has to filter on fields in related entities:
// WHERE AuditActionID IN (SELECT AuditActionID FROM RoleAuditAction INNER JOIN Role ... INNER JOIN RoleUser ... WHERE RoleUser.UserID=userID)
RelationCollection relations = new RelationCollection();
relations.Add(RoleAuditActionEntity.Relations.RoleEntityUsingRoleID);
relations.Add(RoleEntity.Relations.RoleUserEntityUsingRoleID);
relations.Add(new EntityRelation(RoleAuditActionFields.RoleID, RoleUserFields.RoleID, RelationType.ManyToMany));
var qf = new QueryFactory();
var q = qf.AuditAction
.Where(AuditActionFields.AuditActionID
.In(qf.Create()
.Select(RoleAuditActionFields.AuditActionID)
.From(qf.RoleAuditAction
.InnerJoin(qf.Role).On(RoleAuditActionFields.RoleID==RoleFields.RoleID)
.InnerJoin(qf.RoleUser).On(RoleFields.RoleID==RoleUserFields.RoleID))
.Where(RoleUserFields.UserID==userID)));
PredicateExpression filter = new PredicateExpression();
filter.Add(new FieldCompareSetPredicate(AuditActionFields.AuditActionID,
RoleAuditActionFields.AuditActionID,
SetOperator.In,
(RoleUserFields.UserID == userID), relations));
auditActions.GetMulti(filter);
AuditActionCollection auditActions = new AuditActionCollection();
auditActions.GetMulti(q);
return auditActions;
}
View
@@ -28,6 +28,7 @@
using SD.HnD.DAL;
using SD.HnD.DAL.HelperClasses;
using SD.LLBLGen.Pro.QuerySpec;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Collections.Generic;
@@ -245,7 +246,7 @@ public static bool ModifyRole(List<int> actionRightIDs, int roleID, string roleD
trans.Add(roleActionRights);
// delete all role-systemactionright combinations directly from the database, by issuing a direct delete on the database, using a filter
// on roleid
roleActionRights.DeleteMulti((RoleSystemActionRightFields.RoleID == roleID));
roleActionRights.DeleteMulti(RoleSystemActionRightFields.RoleID == roleID);
// add new role-systemactionright entities which we'll save to the database after that
foreach(int actionRightID in actionRightIDs)
@@ -347,7 +348,7 @@ public static bool SaveForumActionRightsForForumRole(List<int> actionRightIDs, i
try
{
// first remove the existing rows for the role
forumRightsPerRole.DeleteMulti((ForumRoleForumActionRightFields.RoleID == roleID) & (ForumRoleForumActionRightFields.ForumID == forumID));
forumRightsPerRole.DeleteMulti((ForumRoleForumActionRightFields.RoleID == roleID).And(ForumRoleForumActionRightFields.ForumID == forumID));
// THEN add new ones
foreach(int actionRightID in actionRightIDs)
Oops, something went wrong.

0 comments on commit 9093301

Please sign in to comment.