public async Task <ActionResult> Create(Models.DTOs.Entity dto)
        {
            //push to chain
            Models.ChainSettings setting = Global.Chains.SingleOrDefault(s => s.Name == id);

            using (Clients.Client client = new Clients.Client(setting.Host, setting.RPCUser, setting.RPCPassword, setting.Port))
            {
                String hex      = Helpers.SerialisationHelper.ToHex(dto);
                var    response = await client.PublishStreamItem(id, "Entity", dto.Id.ToString(), hex);

                ViewBag.Response = "";
                return(RedirectToAction("Index"));
            }
        }
Exemple #2
0
        public async Task <ActionResult> Create(ViewModels.DataEntityViewModel viewModel)
        {
            if (!String.IsNullOrEmpty(viewModel.Data))
            {
                Byte[] data = Encoding.ASCII.GetBytes(viewModel.Data);
                Byte[] key  = Convert.FromBase64String(viewModel.PrivateKey);

                Byte[] encryptedData = EncryptByteArray(key, data);

                Models.DTOs.DataEntity dataDto = new Models.DTOs.DataEntity()
                {
                    Id = viewModel.Id
                };
                dataDto.Data = Convert.ToBase64String(encryptedData);

                Models.DTOs.Access accessDto = new Models.DTOs.Access()
                {
                    ConsumingEntityId  = viewModel.ConsumingEntityId,
                    PublishingEntityId = viewModel.PublishingEntityId,
                    DataId             = dataDto.Id,
                    PrivateKey         = viewModel.PrivateKey
                };

                //push to chain
                Models.ChainSettings setting = Global.Chains.SingleOrDefault(s => s.Name == "gbst");
                using (Clients.Client client = new Clients.Client(setting.Host, setting.RPCUser, setting.RPCPassword, setting.Port))
                {
                    String hex        = Helpers.SerialisationHelper.ToHex(dataDto);
                    var    dataTask   = client.PublishStreamItem("gbst", "Data", dataDto.Id.ToString(), hex);
                    var    accessTask = client.PublishStreamItem("gbst", "Access", dataDto.Id.ToString(), hex);

                    await Task.WhenAll(accessTask, dataTask);
                }
            }

            return(View());
        }