public EntityRelationListResponse Read(List <DbEntity> storageEntityList = null) { EntityRelationListResponse response = new EntityRelationListResponse(); response.Timestamp = DateTime.UtcNow; response.Object = null; try { var relations = Cache.GetRelations(); if (relations != null) { response.Object = relations; response.Hash = Cache.GetRelationsHash(); response.Success = true; response.Message = null; return(response); } relations = DbContext.Current.RelationRepository.Read().Select(x => x.MapTo <EntityRelation>()).ToList(); List <DbEntity> dbEntities = storageEntityList; if (dbEntities == null) { dbEntities = new DbEntityRepository().Read(); } foreach (EntityRelation relation in relations) { var originEntity = dbEntities.Single(x => x.Id == relation.OriginEntityId); var targetEntity = dbEntities.Single(x => x.Id == relation.TargetEntityId); relation.OriginEntityName = originEntity.Name; relation.TargetEntityName = targetEntity.Name; relation.OriginFieldName = originEntity.Fields.Single(x => x.Id == relation.OriginFieldId).Name; relation.TargetFieldName = targetEntity.Fields.Single(x => x.Id == relation.TargetFieldId).Name; } if (relations != null) { Cache.AddRelations(relations); } //we use instance from cache as return value, because in cache we deepcopy collection response.Object = Cache.GetRelations(); response.Hash = Cache.GetRelationsHash(); response.Success = true; response.Message = null; return(response); } catch (Exception e) { response.Success = false; response.Object = null; response.Hash = null; response.Timestamp = DateTime.UtcNow; #if DEBUG response.Message = e.Message + e.StackTrace; #endif return(response); } }
public EntityRelationListResponse Read() { EntityRelationListResponse response = new EntityRelationListResponse(); response.Timestamp = DateTime.UtcNow; response.Object = null; try { response.Object = relationRepository.Read().Select(x => x.MapTo <EntityRelation>()).ToList(); response.Success = true; response.Message = null; return(response); } catch (Exception e) { response.Success = false; response.Object = null; response.Timestamp = DateTime.UtcNow; #if DEBUG response.Message = e.Message + e.StackTrace; #endif return(response); } }