private static void DeleteViewColoumnAndChilds(DBEntities context, List <MetaViewColumn> viewColumns, MetaViewColumn viewColumn) { for (int index = 0; index < viewColumns.Count; index++) { if (viewColumns[index].ParentId == viewColumn.Id) { DeleteViewColoumnAndChilds(context, viewColumns, viewColumns[index]); } } context.MetaViewColumn.DeleteObject(viewColumn); viewColumns.Remove(viewColumn); }
private void SyncViewColumns(MetaView target, List<MetaViewColumnModel> columnModel, DBEntities context) { MetaViewColumnModel.CreateMap(); var viewColumns = context.MetaViewColumn.Include("Attribute").Where(c => c.MetaViewId == target.Id).ToList(); foreach (var item in columnModel) { item.NeedSave = NeedSave(item, columnModel); } foreach (var item in columnModel) { item.NeedSave = NeedSaveSpecial(item, columnModel); } foreach (var item in columnModel) { MetaViewColumnModel item1 = item; var viewColumn = viewColumns.FirstOrDefault(c => c.Id == item1.Id); if (viewColumn == null) { if (!item.NeedSave) continue; viewColumn = new MetaViewColumn() { Id = item.Id }; Mapper.Map(item, viewColumn); viewColumn.MetaViewId = target.Id; context.MetaViewColumn.AddObject(viewColumn); } else { if (item.NeedSave) { Mapper.Map(item, viewColumn); viewColumn.MetaViewId = target.Id; } else { context.MetaViewColumn.DeleteObject(viewColumn); } } } for (int i = 0; i < viewColumns.Count; i++) { var viewColumn = viewColumns[i]; var item = columnModel.FirstOrDefault(c => c.Id == viewColumn.Id); if (item == null) { context.MetaViewColumn.DeleteObject(viewColumns[i]); viewColumns.RemoveAt(i); i--; } else if (viewColumn.ParentId == null && viewColumn.Attribute.EntityId != target.MasterEntityId) { DeleteViewColoumnAndChilds(context, viewColumns, viewColumn); i = -1; } else if (viewColumn.ParentId != null && viewColumn.Attribute != null) { var parent = viewColumns.FirstOrDefault(c => c.Id == viewColumn.ParentId); if (parent != null && parent.Attribute.TypeId == (byte)AttributeType.Reference) { if (parent.Attribute.ReferencedEntityId != viewColumn.Attribute.EntityId) { DeleteViewColoumnAndChilds(context, viewColumns, viewColumn); i = -1; } } } } }
private void SyncViewColumns(MetaView target, List <MetaViewColumnModel> columnModel, DBEntities context) { MetaViewColumnModel.CreateMap(); var viewColumns = context.MetaViewColumn.Include("Attribute").Where(c => c.MetaViewId == target.Id).ToList(); foreach (var item in columnModel) { item.NeedSave = NeedSave(item, columnModel); } foreach (var item in columnModel) { item.NeedSave = NeedSaveSpecial(item, columnModel); } foreach (var item in columnModel) { MetaViewColumnModel item1 = item; var viewColumn = viewColumns.FirstOrDefault(c => c.Id == item1.Id); if (viewColumn == null) { if (!item.NeedSave) { continue; } viewColumn = new MetaViewColumn() { Id = item.Id }; Mapper.Map(item, viewColumn); viewColumn.MetaViewId = target.Id; context.MetaViewColumn.AddObject(viewColumn); } else { if (item.NeedSave) { Mapper.Map(item, viewColumn); viewColumn.MetaViewId = target.Id; } else { context.MetaViewColumn.DeleteObject(viewColumn); } } } for (int i = 0; i < viewColumns.Count; i++) { var viewColumn = viewColumns[i]; var item = columnModel.FirstOrDefault(c => c.Id == viewColumn.Id); if (item == null) { context.MetaViewColumn.DeleteObject(viewColumns[i]); viewColumns.RemoveAt(i); i--; } else if (viewColumn.ParentId == null && viewColumn.Attribute.EntityId != target.MasterEntityId) { DeleteViewColoumnAndChilds(context, viewColumns, viewColumn); i = -1; } else if (viewColumn.ParentId != null && viewColumn.Attribute != null) { var parent = viewColumns.FirstOrDefault(c => c.Id == viewColumn.ParentId); if (parent != null && parent.Attribute.TypeId == (byte)AttributeType.Reference) { if (parent.Attribute.ReferencedEntityId != viewColumn.Attribute.EntityId) { DeleteViewColoumnAndChilds(context, viewColumns, viewColumn); i = -1; } } } } }
private static void DeleteViewColoumnAndChilds(DBEntities context, List<MetaViewColumn> viewColumns, MetaViewColumn viewColumn) { for (int index = 0; index < viewColumns.Count; index++) { if (viewColumns[index].ParentId == viewColumn.Id) { DeleteViewColoumnAndChilds(context, viewColumns, viewColumns[index]); } } context.MetaViewColumn.DeleteObject(viewColumn); viewColumns.Remove(viewColumn); }