public async Task <IActionResult> MigrateSvc(string cardCode, string oldCardCode, ShopReceipt shop)
        {
            SVCMigrationOperationViewModel svcBody = new SVCMigrationOperationViewModel();

            svcBody.StoredValueCardCode = cardCode;
            svcBody.OldCardCode         = oldCardCode;

            Issuer issuer = new Issuer();

            issuer.Name      = "Vittorio";
            issuer.Address   = "via centomani 11";
            issuer.Telephone = "0000000";
            issuer.EMail     = "*****@*****.**";
            issuer.VATNumber = "222222";

            svcBody.StoredValueCardReceipt.IssuerData = issuer;

            ReceiptProduct receiptProduct = new ReceiptProduct();

            receiptProduct.Code     = cardCode;
            receiptProduct.Name     = "VittorioCard";
            receiptProduct.Price    = 0;
            receiptProduct.Quantity = 1;
            receiptProduct.Family   = "";
            receiptProduct.Mode     = "";

            svcBody.StoredValueCardReceipt.Products.Add(receiptProduct);

            Payment payment = new Payment();

            payment.CardCode = cardCode;

            svcBody.StoredValueCardReceipt.Payments.Add(payment);

            ShopReceipt shopReceipt = new ShopReceipt();

            shopReceipt.IssueDate = DateTime.Now;
            shopReceipt.UserData  = "";

            svcBody.StoredValueCardReceipt.IssueDate = DateTime.Now;
            svcBody.StoredValueCardReceipt.UserData  = "";

            SenderData senderData = new SenderData();

            senderData.Shop       = Constants.SHOP;
            senderData.Terminal   = Constants.TERMINAL;
            senderData.Type       = 0;
            senderData.Number     = 0;
            senderData.CashDrawer = 0;
            senderData.Operator   = "";

            svcBody.StoredValueCardReceipt.SenderData = senderData;

            var migrate = await _svcService.Migrate(svcBody);

            return(View("Migrate", migrate));
        }
Beispiel #2
0
        public async Task <SVCResultViewModel> Migrate(SVCMigrationOperationViewModel model)
        {
            SVCResultViewModel result = new SVCResultViewModel(Constants.MSG_RESULT_MESSAGE_OK, Constants.MSG_RESULT_STATUS_OK, Constants.MSG_RESULT_CODE_OK);

            _logger.LogInformation(string.Format("-- ApiManager - Create started"));

            string jsonMessage = "";

            try
            {
                // Read token from ServerLogin
                string token = await _authentication.GetToken();

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Constants.BASE_ADDRESS);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                    //Read endpoint from CampaignType
                    string endpoint = Constants.API_MIGRATE;

                    HttpResponseMessage response = await client.PutAsync(endpoint, new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"));

                    using (Stream responseStream = await response.Content.ReadAsStreamAsync())
                    {
                        jsonMessage = new StreamReader(responseStream).ReadToEnd();
                    }
                    result = JsonConvert.DeserializeObject <SVCResultViewModel>(jsonMessage);
                }
            }
            catch (System.Exception ex)
            {
                result.ResultMessage = ex.Message;
                result.ResultStatus  = Constants.MSG_RESULT_STATUS_NOK;
                result.ResultCode    = Constants.MSG_RESULT_CODE_KO;
            }

            return(result);
        }