Exemplo n.º 1
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <param name="contextModel"></param>
        /// <returns></returns>
        public async Task <ContextModel> CreateOrUpdate(ContextModel contextModel)
        {
            if (contextModel.Id == Guid.Empty)
            {
                contextModel = NewContextModel(contextModel);
            }

            var contextDb = await _contextRepository.FindBy(s => s.Id == contextModel.Id).ConfigureAwait(false);

            if (contextDb == null)
            {
                var context = AutoMapper.Mapper.Map <Context>(contextModel);
                _contextRepository.Create(context);
                _contextRepository.Save(false, false, contextModel.Id);
            }
            else
            {
                AutoMapper.Mapper.Map(contextModel, contextDb);
                _contextRepository.Update(contextDb);
                _contextRepository.Save(false, false, contextModel.Id);
            }

            var contract = await BenChainApi.Client.Contract.AddContractWithHttpMessagesAsync(contextModel.Id, contextModel.Token1, contextModel.Token2, contextModel.FileCheckSum, contextModel.ContextHash).ConfigureAwait(false);


            //First Signator
            await _signatorServices.CreateOrUpdate(CreatedNewSignator(contextModel));

            switch (contextModel.Ref)
            {
            case 0:
                //Case 1
                //Second Signator
                var signator = CreatedNewSignator(contextModel);
                signator.ParticipantId = Guid.NewGuid(); // tweede
                await _signatorServices.CreateOrUpdate(signator);

                break;

            case 1:
                //Case 2
                //Second Signator
                break;

            case 2:
                //Case 3
                //Second Signator
                break;
            }

            return(contextModel);
        }