Basit Nisar

Basit Nisar

  • 1.3k
  • 84
  • 11k

How to declare the array of objects

Apr 27 2023 10:21 AM

Here I have the requested Payload :

{
contractInvoicePerDayID : '1061, 1135',
invoiceObj : ['2023-04-24T04:37:45', '2023-04-24T04:37:45]
}

How can i declare it in my c#code as a List :

int? BaseStateProvinceID = null;
List<int> ContractInvoicePerDayIDs = staffCIPDApprovedViewModel.ContractInvoicePerDayIDs.Split(',').Select(int.Parse).ToList();
if (ContractInvoicePerDayIDs.Count == 1)
{
    BaseStateProvinceID = staffCIPDApprovedViewModel.BaseStateProvinceID;
}
CIPDPushReqMod timeCardPushRequest = new CIPDPushReqMod();
using (SqlConnection connection = new SqlConnection(db.Database.Connection.ConnectionString))
{
    try
    {
        using (SqlCommand command = new SqlCommand("spGetCIPDForPushToLawson", connection))
        {
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@ContractInvoicePerDayIDs", SqlDbType.NVarChar).Value = staffCIPDApprovedViewModel.ContractInvoicePerDayIDs as object ?? DBNull.Value;
            if (connection.State != ConnectionState.Closed)
            {
                connection.Close();
            }
            connection.Open();
            using (var reader = command.ExecuteReader())
            {
                timeCardPushRequest.TimeCardLst = ((IObjectContextAdapter)db).ObjectContext.Translate<CIPDPushReqObj>(reader).ToList();
                reader.NextResult();
                timeCardPushRequest.AdditionalComponents = ((IObjectContextAdapter)db).ObjectContext.Translate<CIPDPushReqObj_AdditionalComponent>(reader).ToList();
            }
        }
    }
    catch (Exception)
    {
    }
    finally
    {
        if (connection.State != ConnectionState.Closed)
        {
            connection.Close();
        }
    }
}

 


Answers (2)