简体   繁体   中英

Visual Studio C# Web API Project code in class not executed

I am new to the C# community. I created a controller and a class with the class containing some logic from a COM reference that I want to be executed.

When I call the API, it does not seem to be going into the ImportInventory method and no logic is executed in that public string (as seen from the debugging breakpoints).

Can someone please assist on how to get this part of the code executed? I am new to C# and can't seem to find the issue.

Code snippet of the controller:

using MDRDS_PastelIntegrator.Models;
using Microsoft.AspNetCore.Mvc;

namespace MDRDS_PastelIntegrator.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class InventoryController : ControllerBase
    {
        private readonly ILogger<InventoryController> _logger;

        public InventoryController(ILogger<InventoryController> logger)
        {
            _logger = logger;
        }

        [HttpPost(Name = "POSTInventory")]
        public IEnumerable<POSTInventory> Get(string pParameter, string pPath)
        {
            return Enumerable.Range(1, 1).Select(index => new POSTInventory
            {
                Parameter = pParameter,
                Path = pPath
            })
            .ToArray();
        }
    }
}

Code snippet of the class:

namespace MDRDS_PastelIntegrator.Models
{
    public class POSTInventory
    {
        //public string? StrReturn;

        public string? Parameter { get; set; }
        public string? Path { get; set; }

        public string ImportInventory(string Parameter, string Path)
        {
            var SDK = new PasSDK.PastelPartnerSDK();

            //Set License
            var F_GetLisence = new SetLicense();
            F_GetLisence.MethodSetLicense();

            //Set Data Path
            var StrReturn = SDK.SetDataPath(Path);

            if (StrReturn == "0")
            {
                var StrIn = Parameter;
                var StrCodeIn = StrIn;

                //Import Inventory Item
                StrReturn = SDK.ImportInventory(StrIn);
            };

            //Blank return string - No serial number
            if (StrReturn.Length == 0)
            {
                StrReturn = "Serial Number Not Specified.";
                //return StrReturn;
            };

            //Get Result Code
            if (StrReturn == "0")
            {
                StrReturn = "0 = Success";
            }
            else
            {
                StrReturn = "1 = Unsuccessfull";
            };

            return StrReturn;
        }

    }
}

您创建了一个 POSTInventory 对象,但您从未调用此对象的 ImportInventory 方法

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM