Как я могу отправить ответ json, который содержит сложные объекты - PullRequest
0 голосов
/ 16 марта 2020

Привет всем, я работаю над API, который содержит много объектов в своем ответе Json. Я использую почтальона для тестирования.

Каждый раз, когда я отслеживаю свой код, ответ правильно заполняется в Visual Studio, пока мы не достигнем уровня, на котором этот ответ должен отображаться в Почтальоне. Он показывает мне, что не может получить никакого ответа.

Мой c# код:

 public SMS1234EvaluationSearchResponse SMS1234EvaluationSearchButton(int ChannelsValue, bool ClosedSMS, bool Rerouted, bool Evaluated, bool NotEvaluated, bool Nominated, DateTime FromDate, DateTime ToDate, CycleUserInfo oCycleUserInfo, int PageSize, int CurrentPageIndex, int QuerySelectedIndex, List<LookupObject> NamesTo)
    {
        DirectoryService oDirectoryServices = new DirectoryService();
        ErrorModel error = new ErrorModel();
        SMS1234EvaluationSearchResponse oResponse = new SMS1234EvaluationSearchResponse();
        try
        {
            int S1 = 0;
            int S2 = 0;
            int S3 = 0;
            int S4 = 0;
            int S5 = 0;
            int S6 = 0;
            int F1 = 0;
            int F2 = 0;
            int F3 = 0;
            String flg = "";


            if (ClosedSMS)
            {
                S1 = 2; S2 = 2; S3 = 2; S4 = 2; S5 = 2; S6 = 2;
            }
            else if (Rerouted)
            {
                S1 = 5; S2 = 5; S3 = 5; S4 = 5; S5 = 5; S6 = 5;
            }
            else
            {
                S1 = 0; S2 = 1; S3 = 2; S4 = 3; S5 = 4; S6 = 5;
            }

            if (ClosedSMS)
            {
                flg = "0,1,2";
                F1 = 0; F2 = 1; F3 = 2;
            }
            else if (Evaluated)
            {
                flg = "2";
                F1 = 2; F2 = 2; F3 = 2;
            }
            else if (NotEvaluated)
            {
                flg = "0,1";
                F1 = 0; F2 = 0; F3 = 1;
            }
            else if (Nominated)
            {
                flg = "1";
                F1 = 1; F2 = 1; F3 = 1;
            }
            else if (Rerouted)
            {
                flg = "0,1,2";
                F1 = 0; F2 = 1; F3 = 2;
            }

            if (oDirectoryServices.IsSMSAuthorized(1, 2))
            {
                oResponse.NamesFromList = FillUsersList(FromDate, ToDate, S1, S2, S3, S4, S5, S6, F1, F2, F3, ChannelsValue, Rerouted, NamesTo);
            }
            else
            {
                if (Evaluated)
                {
                    oResponse.objSMS1234EvaluatedDetailsObject = EvaluateDetails(FromDate, ToDate, Convert.ToString(oCycleUserInfo.UserID), PageSize, CurrentPageIndex, QuerySelectedIndex);
                }
                if (NotEvaluated)
                {
                    oResponse.objSMS1234NotEvaluatedDetailsObject = NotEvaluatedDetails(FromDate, ToDate, Convert.ToString(oCycleUserInfo.UserID), PageSize, CurrentPageIndex, QuerySelectedIndex);
                }
                if (ClosedSMS)
                {
                    oResponse.objSMS1234ClosedSMSObject = ClosedDetails(FromDate, ToDate, Convert.ToString(oCycleUserInfo.UserID), PageSize, CurrentPageIndex, QuerySelectedIndex);
                }
                if (Nominated)
                {
                    oResponse.objSMS1234NominatedObject = NominatedDetails(FromDate, ToDate, Convert.ToString(oCycleUserInfo.UserID), PageSize, CurrentPageIndex, QuerySelectedIndex);
                }
                if (Rerouted)
                {
                    oResponse.objSMS1234RoutedSMSObject = ReroutedDetails(FromDate, ToDate, Convert.ToString(oCycleUserInfo.UserID), PageSize, CurrentPageIndex, QuerySelectedIndex);
                }

            }
            return oResponse;
        }
        catch (UnicamException ex)
        {
            error.ErrorCode = ex.ErrorCode.ToString();
            error.ErrorMessage = ExceptionHandler.GetErrorDescription(ex.ErrorCode.ToString());
            error.ErrorMsgParams = ex.ErrorMsgParameters;
            error.ErrorType = HttpStatusCode.ExpectationFailed;
            oResponse.ErrorObj = error;
            return oResponse;
        }
        catch (Exception ex)
        {
            error.ErrorCode = "Exception";
            error.ErrorMessage = ex.Message.ToString();
            error.ErrorType = HttpStatusCode.ExpectationFailed;
            oResponse.ErrorObj = error;
            return oResponse;
        }
    }

Мой код ответа:

  public class SMS1234EvaluationSearchResponse
{
    private List<LookupObj> _NamesFromList;

    [DataMember]
    public List<LookupObj> NamesFromList
    {
        get { return _NamesFromList; }
        set { _NamesFromList = value; }
    }

    private SMS12345NominatedSMSObject _objSMS1234NominatedObject;

    [DataMember]
    public SMS12345NominatedSMSObject objSMS1234NominatedObject
    {
        get { return _objSMS1234NominatedObject; }
        set { _objSMS1234NominatedObject = value; }
    }

    private SMS1234ClosedSmsObject _objSMS1234ClosedSMSObject;

    [DataMember]
    public SMS1234ClosedSmsObject objSMS1234ClosedSMSObject
    {
        get { return _objSMS1234ClosedSMSObject; }
        set { _objSMS1234ClosedSMSObject = value; }
    }

    private SMS1234ReroutedSMSObject _objSMS1234RoutedSMSObject;

    [DataMember]
    public SMS1234ReroutedSMSObject objSMS1234RoutedSMSObject
    {
        get { return _objSMS1234RoutedSMSObject; }
        set { _objSMS1234RoutedSMSObject = value; }
    }

    private SMS1234NotEvaluatedDetailsObject _objSMS1234NotEvaluatedDetailsObject;

    [DataMember]
    public SMS1234NotEvaluatedDetailsObject objSMS1234NotEvaluatedDetailsObject
    {
        get { return _objSMS1234NotEvaluatedDetailsObject; }
        set { _objSMS1234NotEvaluatedDetailsObject = value; }
    }

    private SMS1234EvaluateDetailsObject _objSMS1234EvaluatedDetailsObject;

    [DataMember]
    public SMS1234EvaluateDetailsObject objSMS1234EvaluatedDetailsObject
    {
        get { return _objSMS1234EvaluatedDetailsObject; }
        set { _objSMS1234EvaluatedDetailsObject = value; }
    }




}

Код API:

 public SMS1234EvaluationSearchResponse SMS1234EvaluationSearchButton(SMS1234EvaluationSearchRequest oRequest)
        {
            SMS1234EvaluationSearchResponse oResponse = new SMS1234EvaluationSearchResponse();
            ErrorModel oError = new ErrorModel();
            try
            {
                ZainCyclesBusiness.ZainCycleTransactions oZainCycleTransactions = new ZainCyclesBusiness.ZainCycleTransactions();
                oResponse = oZainCycleTransactions.SMS1234EvaluationSearchButton(oRequest.ChannelsValue,oRequest.ClosedSMS,oRequest.Rerouted,oRequest.Evaluated,oRequest.NotEvaluated,oRequest.Nominated, oRequest.FromDate,oRequest.ToDate,oRequest.UserInfo,oRequest.PageSize,oRequest.CurrentPageIndex,oRequest.QuerySelectedIndex,oRequest.NamesTo);
                oResponse.ErrorObj = CheckErrorResons(oResponse.ErrorObj);
            }
            catch (UnicamException ex)
            {
                oError.ErrorCode = ex.ErrorCode.ToString();
                oError.ErrorMessage = ExceptionHandler.GetErrorDescription(ex.ErrorCode.ToString());
                oError.ErrorMsgParams = ex.ErrorMsgParameters;
                oResponse.ErrorObj = oError;
            }
            catch (Exception ex)
            {
                oError.ErrorCode = "Exception";
                oError.ErrorMessage = ex.Message.ToString();
                oResponse.ErrorObj = oError;
            }

            return oResponse;
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...