1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using Comal.Classes;
- namespace Comal.Stores
- {
- internal class ScheduleStore : BaseStore<Schedule>
- {
- //private void UpdateActiveScheduleCount(Schedule entity)
- //{
- // Type doctype = entity.DocumentType();
- // var linktype = CoreUtils.TypeList(
- // AppDomain.CurrentDomain.GetAssemblies(),
- // x => (typeof(IEntityLink).GetTypeInfo().IsAssignableFrom(x) && (x.BaseType.GenericTypeArguments.Length == 1) && (x.BaseType.GenericTypeArguments[0] == doctype))
- // ).FirstOrDefault();
- // if (linktype == null)
- // return;
- // var link = Activator.CreateInstance(linktype) as IEntityLink;
- // link.ID = entity.DocumentID;
- // if (entity.HasOriginalValue(x=>x.DocumentID))
- // ((BaseObject)link).OriginalValues["ID"] = entity.GetOriginalValue(x=>x.DocumentID);
- // ParameterExpression parameter = Expression.Parameter(doctype, "x");
- // MemberExpression property = Expression.Property(parameter, "ActiveSchedules");
- // var delegateType = typeof(Func<,>).MakeGenericType(doctype, typeof(int));
- // var tgt = Expression.Lambda(delegateType, property, parameter);
- // //var tgt = CoreUtils.CreateMemberExpression(entity.DocumentType, "ActiveSchedules");
- // Type aggtype = typeof(IntegerAggregate<,>).MakeGenericType(entity.GetType(), doctype);
- // var agg = Activator.CreateInstance(aggtype, null, tgt, AggregateType.Count);
- // Array arr = Array.CreateInstance(aggtype, 1);
- // arr.SetValue(agg, 0);
- // MethodInfo method = this.GetType().GetMethod("UpdateAggregate");
- // MethodInfo generic = method.MakeGenericMethod(doctype);
- // generic.Invoke(this, new object[] { entity, link, arr });
- //}
- //private enum ScheduleAction
- //{
- // Update,
- // Delete
- //}
- //private void CheckScheduleActive(Schedule entity, ScheduleAction action)
- //{
- // if (action == ScheduleAction.Delete)
- // {
- // // Is the stored version of this schedule Active?
- // bool bActive = entity.OriginalValues.ContainsKey("Active") ? (bool)entity.OriginalValues["Active"] : entity.Active;
- // if (bActive)
- // {
- // entity.DocumentID = Guid.Empty;
- // UpdateActiveScheduleCount(entity);
- // }
- // }
- // else
- // {
- // // Is this a new schedule that has already been set to active?
- // if (entity.ID.Equals(Guid.Empty) && entity.Active)
- // UpdateActiveScheduleCount(entity);
- // // Has the Active flag been changed?
- // else if (entity.OriginalValues.ContainsKey("Active"))
- // {
- // bool bOrig = false;
- // bool.TryParse(entity.OriginalValues["Active"].ToString(), out bOrig);
- // bool bCurrent = entity.Active;
- // if (bOrig != bCurrent)
- // {
- // Guid id = entity.DocumentID;
- // if (!bCurrent)
- // entity.DocumentID = Guid.Empty;
- // UpdateActiveScheduleCount(entity);
- // entity.DocumentID = id;
- // }
- // }
- // }
- //}
- protected override void BeforeSave(Schedule entity)
- {
- base.BeforeSave(entity);
- //CheckScheduleActive(entity,ScheduleAction.Update);
- }
- protected override void BeforeDelete(Schedule entity)
- {
- base.BeforeDelete(entity);
- //CheckScheduleActive(entity, ScheduleAction.Delete);
- }
- }
- }
|