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(Expression1 expression) +392.Add(Expression
NHibernate.Criterion.QueryOver1 expression) +1072.Where(Expression
NHibernate.Criterion.QueryOver1 expression) +422.NHibernate.IQueryOver.Where(Expression`1 expression) +42
NHibernate.Criterion.QueryOver
One simple way to start would be to just break out the common functionality using a
Funcfor the difference and get rid of most of the duplication.