コード例 #1
0
        private async Task UpdateChangedRelationshipsAsync(MarketEvaluationPointDataModel marketEvaluationPointDataModel)
        {
            var changedRelationships = GetChangedRelationships(marketEvaluationPointDataModel);

            if (changedRelationships.Count == 0)
            {
                return;
            }

            var updateStatement =
                $"UPDATE [dbo].[Relationships] " +
                "SET [EffectuationDate] = @EffectuationDate, [State] = @State " +
                "WHERE [Id] = @Id";

            var parameters = new List <dynamic>();

            marketEvaluationPointDataModel.Relationships?.ForEach(model =>
            {
                parameters.Add(new
                {
                    Id = model.Id,
                    EffectuationDate = model.EffectuationDate,
                    State            = model.State,
                });
            });

            await Connection.ExecuteAsync(
                updateStatement,
                parameters)
            .ConfigureAwait(false);
        }
コード例 #2
0
        private async Task InsertAddedRelationshipsAsync(MarketEvaluationPointDataModel marketEvaluationPointDataModel)
        {
            var addedRelationships = GetAddedRelationships(marketEvaluationPointDataModel);

            if (addedRelationships.Count == 0)
            {
                return;
            }

            var insertStatement =
                $"DECLARE @MarketParticipantId NVARCHAR(50) " +
                $"SET @MarketParticipantId = (SELECT Id AS MarketParticipantId FROM [dbo].[MarketParticipants] WHERE Mrid = @Mrid)" +
                $"INSERT INTO [dbo].[Relationships] (MarketEvaluationPoint_Id, MarketParticipant_Id, Type, EffectuationDate, State) " +
                "VALUES (@MarketEvaluationPointId, @MarketParticipantId, @Type, @EffectuationDate, @State)";

            var parameters = new List <dynamic>();

            addedRelationships.ForEach(relationshipDataModel =>
            {
                parameters.Add(new
                {
                    Mrid = relationshipDataModel.Mrid,
                    MarketEvaluationPointId = marketEvaluationPointDataModel.Id,
                    Type             = relationshipDataModel.Type,
                    EffectuationDate = relationshipDataModel.EffectuationDate,
                    State            = relationshipDataModel.State,
                });
            });

            await Connection.ExecuteAsync(
                insertStatement,
                parameters).ConfigureAwait(false);
        }
コード例 #3
0
        private static MeteringPointSnapshot CreateMarketEvaluationPointSnapshot(MarketEvaluationPointDataModel marketEvaluationPointDataModel, List <RelationshipDataModel> relationshipDataModels)
        {
            var relationshipsSnapshot = relationshipDataModels.Select(r =>
                                                                      new RelationshipSnapshot(r.Id, r.Mrid !, r.Type, r.EffectuationDate, r.State))
                                        .ToList();

            var meteringPointSnapshot = new MeteringPointSnapshot(
                marketEvaluationPointDataModel.Id,
                marketEvaluationPointDataModel.GsrnNumber,
                marketEvaluationPointDataModel.Type,
                relationshipsSnapshot,
                marketEvaluationPointDataModel.ProductionObligated,
                marketEvaluationPointDataModel.PhysicalState,
                marketEvaluationPointDataModel.RowVersion);

            return(meteringPointSnapshot);
        }
コード例 #4
0
        private async Task InsertAsync(MarketEvaluationPointDataModel dataModel)
        {
            var insertStatement =
                $"INSERT INTO [dbo].[MarketEvaluationPoints] (GsrnNumber, Type, ProductionObligated, PhysicalState, RowVersion) " +
                "VALUES (@GsrnNumber, @Type, @ProductionObligated, @PhysicalState, @Version);SELECT CAST(SCOPE_IDENTITY() as int)";

            dataModel.Id = await Connection.ExecuteScalarAsync <int>(
                insertStatement,
                param : new
            {
                GsrnNumber          = dataModel.GsrnNumber,
                Type                = dataModel.Type,
                ProductionObligated = dataModel.ProductionObligated,
                PhysicalState       = dataModel.PhysicalState,
                Version             = 0,
            }).ConfigureAwait(false);

            await InsertAddedRelationshipsAsync(dataModel).ConfigureAwait(false);
        }
コード例 #5
0
        private async Task UpdateRowVersionOrThrowAsync(MarketEvaluationPointDataModel dataModel)
        {
            var updateStatement =
                "UPDATE [dbo].[MarketEvaluationPoints] " +
                "SET RowVersion = @Version " +
                "WHERE Id = @Id AND RowVersion = @PreviousVersion";

            var recordsUpdated = await Connection.ExecuteAsync(
                updateStatement,
                param : new
            {
                Id = dataModel.Id,
                PreviousVersion = dataModel.RowVersion,
                Version         = dataModel.RowVersion + 1,
            }).ConfigureAwait(false);

            if (recordsUpdated != 1)
            {
                throw new DBConcurrencyException();
            }
        }
コード例 #6
0
 private static List <RelationshipDataModel> GetChangedRelationships(MarketEvaluationPointDataModel marketEvaluationPoint)
 {
     return(marketEvaluationPoint.Relationships
            .Where(r => r.Id != default(int))
            .ToList());
 }