sarpay
7/31/2018 - 9:23 AM

Json Response - v3

public async Task<ActionResult> PlanCoverageNetworkExceptionGetItemData(int id)
{
  var exception = await _productManager.GetPlanCoverageNetworkExceptionFirstOrDefault(id);
  var agency = (from a in _customerManager.GetAllAcente()
               where a.SubeKod == (byte)exception.SubeKod &&
                     a.KaynakKod == (short)exception.KaynakKod &&
                     a.MustKod == exception.MustKod
               select a).First();

  var resultDict = new Dictionary<string, object>();
  if (exception != null) {
    resultDict = new Dictionary<string, object> {
      { "success", true },
      { "data", new Dictionary<string, object>
        {
          { "id", exception.Id },
          { "planCoverageNetworkId", exception.PlanCoverageNetworkId },
          { "subeKod", exception.SubeKod },
          { "kaynakKod", exception.KaynakKod },
          { "mustKod", exception.MustKod },
          { "mustIsim", agency.Isim },
          { "agreedPatientShare", exception.AgreedPatientShare },
          { "doNotPay", exception.DoNotPay }
        }
      }
    };
  }
  else
  {
    resultDict = new Dictionary<string, object> {
      { "success", false },
      { "text", "Obje bulunamadı." }
    };
  }
  return Json(resultDict);
}
public ActionResult GetPolicyInsuredCoverageList(int policyInsuredId)
{
  var policyInsuredCoverageDtoList = _policyAppService.GetPolicyInsuredCoverageListByInsuredId(policyInsuredId);
  var nestedList = PolicyInsuredCoverageViewModel.LoadFrom(policyInsuredCoverageDtoList);

  var gridReadyJson = new JArray();
  foreach (var item in nestedList)
  {
    var jsonChildObj = "";
    var counter = 0;

    if (item.Childs != null)
    {
      foreach (var child in item.Childs)
      {
        counter += 1;
        if (counter > 1) { jsonChildObj += ","; }
        jsonChildObj +=
          "{" +
            "\"data\": " +
            "{" +
              "\" \": \" \"," +
              "\"Teminat\": \"" + child.CoverageName + "\"," +
              "\"Net Prim\": \"" + child.NetPremium + "\"," +
              "\"Prim\": \"" + child.Premium + "\"," +
              "\"Komisyon\": \"" + child.Commission + "\"," +
              "\"Vergi\": \"" + child.TaxAmount + "\"," +
              "\"Brüt Prim\": \"" + child.GrossPremium + "\"" +
            "}, " +
            "\"kids\": []" +
          "}";
      }
    }

    var jsonParentObj = "" +
    "{" +
        "\"data\": " +
        "{" +
          "\"Teminat\": \"" + item.CoverageName + "\"," +
          "\"Net Prim\": \"" + item.NetPremium + "\"," +
          "\"Prim\": \"" + item.Premium + "\"," +
          "\"Komisyon\": \"" + item.Commission + "\"," +
          "\"Vergi\": \"" + item.TaxAmount + "\"," +
          "\"Brüt Prim\": \"" + item.GrossPremium + "\"" +
        "}, " +
        "\"kids\": [" + jsonChildObj + "]" +
    "}";

    var o = JObject.Parse(jsonParentObj);
    gridReadyJson.Add(o);
  }
  return Json(gridReadyJson);
}

/* returns */

/*

[
  {
    "data": {
        "Teminat": "IP - YATARAK TEDAVİ",
        "Net Prim": "370,44",
        "Prim": "567,46",
        "Komisyon": "185,22",
        "Vergi": "0,00",
        "Brüt Prim": "370,44"
    },
    "kids": [
      {
        "data": {
          "Teminat": "OYR - ODA-YEMEK-REFAKATÇİ",
          "Net Prim": "260,00",
          "Prim": "360,00",
          "Komisyon": "100,00",
          "Vergi": "0,00",
          "Brüt Prim": "260,00"
        },
        "kids": []
      },
      {
        "data": {
          "Teminat": "YBK - YOĞUN BAKIM",
          "Net Prim": "60,00",
          "Prim": "100,00",
          "Komisyon": "40,00",
          "Vergi": "0,00",
          "Brüt Prim": "60,00"
        },
        "kids": []
      },
      {
        "data": {
          "Teminat": "KRT - KEMOTERAPİ,RADYOTERA",
          "Net Prim": "50,44",
          "Prim": "107,46",
          "Komisyon": "45,22",
          "Vergi": "0,00",
          "Brüt Prim": "50,44"
        },
        "kids": []
      }
    ]
  }
];

*/