Beispiel #1
0
 public static void FixStateOfTrackedEntities(this DbContext context, string userName)
 {
     foreach (var entry in context.ChangeTracker.Entries <IEditableModel>())
     {
         IEditableModel stateInfo = entry.Entity;
         stateInfo.UpdateIfEdited(userName);
         entry.State = ConvertState(stateInfo);
     }
 }
Beispiel #2
0
 private static EntityState ConvertState(IEditableModel entity)
 {
     if (entity.IsNew)
     {
         return(EntityState.Added);
     }
     else if (entity.IsDirty)
     {
         return(EntityState.Modified);
     }
     else if (entity.IsDeleted)
     {
         return(EntityState.Deleted);
     }
     return(EntityState.Unchanged);
 }
Beispiel #3
0
 public static bool RequiresSave(this IEditableModel entity)
 {
     if (entity.IsNew)
     {
         return(true);
     }
     else if (entity.IsDirty)
     {
         return(true);
     }
     else if (entity.IsDeleted)
     {
         return(true);
     }
     return(false);
 }
Beispiel #4
0
 /// <summary>
 /// Applies the proper created and modified settings based upon the state of the model and returns true if it updated any fields.
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 public static bool UpdateIfEdited(this IEditableModel model, string userName)
 {
     if (model.IsNew)
     {
         model.CreatedBy = userName;
         model.CreatedOn = System.DateTime.Now;
         return(true);
     }
     else if (model.IsDirty)
     {
         model.ModifiedBy = userName;
         model.ModifiedOn = System.DateTime.Now;
         return(true);
     }
     return(false);
 }
Beispiel #5
0
        public static void CreateValueEditorViews(IEditableModel model, StackPanel editorViewContext, ModelValueChangedDelegate modelValueChanged = null)
        {
            Type modelType = model.GetType();

            FieldInfo[] fields = modelType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (FieldInfo field in fields)
            {
                ValueEditorAttribute editorAttribute = field.GetCustomAttribute(typeof(ValueEditorAttribute)) as ValueEditorAttribute;

                if (editorAttribute == null)
                {
                    continue;
                }

                ValueEditorView valueEditorView = new ValueEditorView(model, field, modelValueChanged);
                editorViewContext.Children.Add(valueEditorView);
            }
        }
 public ItemEditorView(IEditableModel model) : this()
 {
     ValueEditorUtility.CreateValueEditorViews(model, ValueEditorViewContext);
 }