/// <summary> /// Get Updated Model Data. /// </summary> /// <param name="transaction"> Detail Transaction. </param> /// <returns> Current Data as Object. </returns> private object GetUpdatedModel(IDetailTransaction transaction) { object model = Activator.CreateInstance(transaction.ModelType); MethodInfo tryUpdateModel = typeof(Controller).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(m => m.Name == "TryUpdateModel" && m.GetParameters().Length == 2 && m.GetParameters().Any(p => p.Name == "prefix")).FirstOrDefault().MakeGenericMethod(transaction.ModelType); MethodInfo updateModel = typeof(Controller).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(m => m.Name == "UpdateModel" && m.GetParameters().Length == 2 && m.GetParameters().Any(p => p.Name == "prefix")).FirstOrDefault().MakeGenericMethod(transaction.ModelType); if ((bool) tryUpdateModel.Invoke(this, new object[] { model, transaction.Prefix })) { updateModel.Invoke(this, new object[] { model, transaction.Prefix }); } return model; }
/// <summary> /// Get the Model Detail for binding Create or Query View. /// </summary> /// <param name="id"> Id Field Value. </param> /// <param name="transaction"> Detail Transaction. </param> /// <returns> Model object. </returns> private static object GetCurrentModel(long id, IDetailTransaction transaction) { object model; if (id > 0) { model = transaction.RetrieveList().Cast<object>().Where(p => p.GetValue<long>(transaction.IdProperty) == id).FirstOrDefault(); } else { model = Activator.CreateInstance(transaction.ModelType); } return model; }