public virtual IActionResult CreateAgreement([FromBody] AgreementProposal agreement)
        {
            var clientContext = this.HttpContext.Items["ClientContext"] as GolemClientMockAPI.Entities.ClientContext;

            // locate the offerProposalId
            var offerProposal = this.ProposalRepository.GetOfferProposal(agreement.ProposalId);

            var receivingSubscription = this.SubscriptionRepository.GetDemandSubscription(offerProposal.ReceivingSubscriptionId);

            if (offerProposal == null)
            {
                return(StatusCode(404, new ErrorMessage()
                {
                }));                                            // Not Found
            }

            if (clientContext.NodeId != receivingSubscription.Demand.NodeId)
            {
                return(StatusCode(401, new ErrorMessage()
                {
                }));                                            // Unauthorized
            }

            var resultAgreement = this.MarketProcessor.CreateAgreement(agreement.ProposalId, agreement.ValidTo);

            this._logger.LogWithProperties(LogLevel.Information,
                                           clientContext?.NodeId,
                                           "Requestor",
                                           receivingSubscription?.Id,
                                           $"CreateAgreement (AgreementId: {resultAgreement.Id})");

            return(StatusCode(201, resultAgreement.Id));
        }
        public virtual IActionResult GetProposal([FromRoute][Required] string subscriptionId, [FromRoute][Required] string proposalId)
        {
            var clientContext = this.HttpContext.Items["ClientContext"] as GolemClientMockAPI.Entities.ClientContext;

            var subscription = this.SubscriptionRepository.GetDemandSubscription(subscriptionId);

            if (subscription == null)
            {
                return(StatusCode(404)); // Not Found
            }

            if (clientContext.NodeId != subscription.Demand.NodeId)
            {
                return(StatusCode(401)); // Unauthorized
            }

            var offerProposal = this.ProposalRepository.GetOfferProposals(subscriptionId).Where(prop => prop.Id == proposalId).FirstOrDefault();

            if (offerProposal == null)
            {
                return(StatusCode(404)); // Not Found
            }

            var demandProposal = (offerProposal.DemandId == null) ?
                                 new GolemClientMockAPI.Entities.DemandProposal()
            {
                Demand = subscription.Demand
            }  :
            this.ProposalRepository.GetDemandProposal(offerProposal.DemandId);

            var result = new AgreementProposal()
            {
                Id     = proposalId,
                Offer  = this.OfferMapper.MapEntityToProposal(offerProposal),
                Demand = this.DemandMapper.MapEntityToProposal(demandProposal)
            };

            return(StatusCode(200, result));
        }