public void CopyAndNew(object sender, EventArgs e) { View.PostEditors(); OnSaving(); if (!View.ValidateData()) { return; } if (NewEntityId == Guid.Empty) { _dynamicDataServiceContext = new DynamicDataServiceContext(); EntityId = NewEntityId; var newEntity = GetEntity(); var metaEntity = MetadataProvider.Instance.EntiyMetadata.Where(c => c.PhysicalName == EntityName).FirstOrDefault(); foreach (var att in metaEntity.Attributes) { if (att.IsCopyEnabled ?? false) { object targetValue = GetDynamicMember(DynamicEntity, att.TableColumnName); newEntity.GetType().GetProperty(att.TableColumnName).SetValue(newEntity, targetValue, null); } } DynamicEntity = new SysBits.DynamicProxies.DynamicProxy(newEntity); WorkingMode = EntityDetailWorkingMode.Add; RefreshEntityId(newEntity); NewEntityId = EntityId; Type entityType = newEntity.GetType(); Type listGenericType = typeof(List <>); Type listType = listGenericType.MakeGenericType(entityType); var list = (IList)Activator.CreateInstance(listType); list.Add(newEntity); BindData(list); } OnEntitySaved(new EventArgs <bool>(true)); }
private bool SaveEntity() { View.PostEditors(); OnSaving(); if (!View.ValidateData()) { return(false); } DynamicDataServiceContext.SaveChanges(); NewEntityId = Guid.Empty; OnSaved(); if (WorkingMode == EntityDetailWorkingMode.Add) { WorkingMode = EntityDetailWorkingMode.Edit; } OnEntitySaved(new EventArgs <bool>(false)); WorkItem.Commands["Refresh"].Execute(); return(true); }