Пример #1
0
        /// <summary>
        /// Convert to Csv Format
        /// </summary>
        static string ConvertToCsv(List <CensusTableVm> lstCensusTable)
        {
            var oRet = new StringBuilder(string.Empty);

            // Get Header Row
            oRet.AppendLine(CensusTableVm.getCsvTitleRow());

            // Put Child Rows
            foreach (var item in lstCensusTable)
            {
                oRet.AppendLine(item.ToString());
            }

            return(oRet.ToString());
        }
Пример #2
0
        /// <summary>
        /// Parser Json Fields
        /// </summary>
        static FormVM ParseJsonFields(string jsonInput)
        {
            JObject jsonObj = JObject.Parse(jsonInput);

            var oRet = new FormVM();

            oRet.ContactPerson   = jsonObj.TraverseJObject("ContactPerson", "field")?.Value <string>("value") ?? "";
            oRet.BusinessName    = jsonObj.TraverseJObject("BusinessName", "field")?.Value <string>("value") ?? "";
            oRet.BusinessAddress = jsonObj.TraverseJObject("BusinessAddress", "field")?.Value <string>("value") ?? "";
            oRet.BusinessType    = jsonObj.TraverseJObject("BusinessType", "field")?.Value <string>("value") ?? "";
            oRet.Phone           = jsonObj.TraverseJObject("Phone", "field")?.Value <string>("value") ?? "";
            oRet.Email           = jsonObj.TraverseJObject("Email", "field")?.Value <string>("value") ?? "";

            var censusTable = jsonObj.TraverseJObject("CencusTable", "table");

            if (censusTable != null)
            {
                var rows = censusTable["rows"];

                if (rows != null && rows.Count() > 1)
                {
                    for (int i = 1; i < rows.Count(); i++)
                    {
                        var oCensus = new CensusTableVm();

                        // Parser individual data
                        oCensus.SrNo                  = rows.ElementAt(i).ElementAt(0).ElementAt(0).Value <string>("value");
                        oCensus.DOB                   = rows.ElementAt(i).ElementAt(1).ElementAt(0).Value <string>("value");
                        oCensus.Gender                = rows.ElementAt(i).ElementAt(2).ElementAt(0).Value <string>("value");
                        oCensus.Occupation            = rows.ElementAt(i).ElementAt(3).ElementAt(0).Value <string>("value");
                        oCensus.Salary                = rows.ElementAt(i).ElementAt(4).ElementAt(0).Value <string>("value");
                        oCensus.IsShortTermDisability = rows.ElementAt(i).ElementAt(5).ElementAt(0).Value <string>("value");
                        oCensus.IsLongTernDisability  = rows.ElementAt(i).ElementAt(6).ElementAt(0).Value <string>("value");
                        oCensus.LifeInsuCoverAmt      = rows.ElementAt(i).ElementAt(7).ElementAt(0).Value <string>("value");

                        oRet.lstCensusTable.Add(oCensus);
                    }
                }
            }

            return(oRet);
        }
        /// <summary>
        /// Parser Json Fields
        /// </summary>
        public static FormVM ParseJsonFields(string jsonInput)
        {
            JObject jsonObj = JObject.Parse(jsonInput);

            var oRet = new FormVM();

            oRet.ContactPerson   = Convert.ToString(jsonObj["fields"]["contactPerson"]["value"]);
            oRet.BusinessName    = Convert.ToString(jsonObj["fields"]["businessName"]["value"]);
            oRet.BusinessAddress = Convert.ToString(jsonObj["fields"]["businessAddress"]["value"]);
            oRet.BusinessType    = Convert.ToString(jsonObj["fields"]["businessType"]["value"]);
            oRet.Phone           = Convert.ToString(jsonObj["fields"]["phone"]["value"]);
            oRet.Email           = Convert.ToString(jsonObj["fields"]["email"]["value"]);

            var censusTable = jsonObj["tables"].Where(x => x.Value <string>("name") == "CencusTable");

            if (censusTable != null)
            {
                var rows = censusTable.Values("rows").First();

                if (rows != null && rows.Count() > 1)
                {
                    for (int i = 1; i < rows.Count(); i++)
                    {
                        var oCensus = new CensusTableVm();

                        // Parser individual data
                        oCensus.SrNo                  = rows.ElementAt(i).ElementAt(0).ElementAt(0).Value <string>("value");
                        oCensus.DOB                   = rows.ElementAt(i).ElementAt(1).ElementAt(0).Value <string>("value");
                        oCensus.Gender                = rows.ElementAt(i).ElementAt(2).ElementAt(0).Value <string>("value");
                        oCensus.Occupation            = rows.ElementAt(i).ElementAt(3).ElementAt(0).Value <string>("value");
                        oCensus.Salary                = rows.ElementAt(i).ElementAt(4).ElementAt(0).Value <string>("value");
                        oCensus.IsShortTermDisability = rows.ElementAt(i).ElementAt(5).ElementAt(0).Value <string>("value");
                        oCensus.IsLongTernDisability  = rows.ElementAt(i).ElementAt(6).ElementAt(0).Value <string>("value");
                        oCensus.LifeInsuCoverAmt      = rows.ElementAt(i).ElementAt(7).ElementAt(0).Value <string>("value");

                        oRet.lstCensusTable.Add(oCensus);
                    }
                }
            }

            return(oRet);
        }