public IdedEntityViewModel(IdedEntity entity) : base(entity) { if (entity != null) { Id = entity.Id; } }
public void Update <T>(T obj) where T : ModelEntity, new() { obj.BeforeSave(); if (obj is IdedEntity) { IdedEntity idEntity = obj as IdedEntity; if (idEntity.OldId > 0) { if (idEntity.Id != idEntity.OldId) { T o = new T(); IdedEntity newEntity = o as IdedEntity; newEntity.Id = idEntity.Id; orMapper.Load <T>(o); if (!o.Loaded) { //NewId not exist, create the new one and delete the old one using (TransactionScope scope = new TransactionScope()) { newEntity.Id = idEntity.OldId; orMapper.Delete <T>(o); orMapper.Insert <T>(obj); scope.Complete(); return; } } else { //NewId exist return; } } } } orMapper.Update <T>(obj); }