I'm thinking an enum might be the way to go, and depending on the action (create, delete) it replaces the characters? Then I'd have to store a variable for "--", "++", ">=" and ">" hrrmm. Any simple suggestions would be great, and I could use it as a future reference as to how I might tackle a problem like this!
public void ArrangeCategoriesOrderOnCreate(Category category)
{
var tx = _session.BeginTransaction();
var categories = _session.QueryOver<Category>()
.Where(c => c.Parent.Id == category.Parent.Id && c.OrderInList >= category.OrderInList) // the >= category.OrderInList here
.List<Category>();
foreach(var item in categories)
{
item.OrderInList++; // The ++ here.
_session.SaveOrUpdate(item);
}
tx.Commit();
}
public void ArrangeCategoriesOrderOnDelete(Category category)
{
var tx = _session.BeginTransaction();
var categories = _session.QueryOver<Category>()
.Where(c => c.Parent.Id == category.Parent.Id && c.OrderInList > category.OrderInList) // the > category.OrderInList here
.List<Category>();
foreach(var item in categories)
{
item.OrderInList--; // the -- here.
_session.SaveOrUpdate(item);
}
tx.Commit();
}
Edit 1
Could not determine member type from Invoke, Invoke(value(CumbriaMD.Infrastructure.DataServices.CategoryDataServices+<>c_DisplayClass8).orderComparer, c.OrderInList, value(CumbriaMD.Infrastructure.DataServices.CategoryDataServices+<>c_DisplayClass8).category.OrderInList), System.Linq.Expressions.InvocationExpression
Trace:
[Exception: Could not determine member type from Invoke, Invoke(value(CumbriaMD.Infrastructure.DataServices.CategoryDataServices+<>c_DisplayClass8).orderComparer, c.OrderInList, value(CumbriaMD.Infrastructure.DataServices.CategoryDataServices+<>c_DisplayClass8).category.OrderInList), System.Linq.Expressions.InvocationExpression] NHibernate.Impl.ExpressionProcessor.ProcessBooleanExpression(Expression expression) +1113 NHibernate.Impl.ExpressionProcessor.ProcessExpression(Expression expression) +114 NHibernate.Impl.ExpressionProcessor.ProcessAndExpression(BinaryExpression expression) +85 NHibernate.Impl.ExpressionProcessor.ProcessBinaryExpression(BinaryExpression expression) +124 NHibernate.Impl.ExpressionProcessor.ProcessExpression(Expression expression) +95 NHibernate.Impl.ExpressionProcessor.ProcessLambdaExpression(LambdaExpression expression) +52 NHibernate.Impl.ExpressionProcessor.ProcessExpression(Expression
1 expression) +39 NHibernate.Criterion.QueryOver
2.Add(Expression1 expression) +107 NHibernate.Criterion.QueryOver
2.Where(Expression1 expression) +42 NHibernate.Criterion.QueryOver
2.NHibernate.IQueryOver.Where(Expression`1 expression) +42