Wednesday, August 19, 2020

JSON convert FIle::

Reference:: using Newtonsoft.Json; 




public ActionResult DownloadExcelJson(string spName, string date, string txtBranchCode = "")

        {


             

            try

            {


                var FileName = "gBankerData";


                List<MRA_Contract_DetailsViewModel> ListContractDetails = new List<MRA_Contract_DetailsViewModel>();


                var ContractDetailsParam = new { OrgID = LoggedInOrganizationID, OfficeID = LoginUserOfficeID };

                var ContractDetails = accReportService.GetAccDataForReport(ContractDetailsParam, "Proc_Get_ContractDetails");


                ListContractDetails = ContractDetails.Tables[0].AsEnumerable()

                .Select(row => new MRA_Contract_DetailsViewModel

                {


                    MFICODE = row.Field<string>("MFICODE"),

                    ACCOUNTINGDATE = row.Field<DateTime?>("ACCOUNTINGDATE"),

                    PRODUCTIONDATE = row.Field<DateTime?>("PRODUCTIONDATE"),

                    BRANCH_CODE = row.Field<string>("BRANCH_CODE"),

                    MEMBERID = row.Field<string>("MEMBERID"),

                    LOAN_CODE = row.Field<string>("LOAN_CODE"),

                    LOAN_TYPE = row.Field<string>("LOAN_TYPE"),

                    LOAN_DISBURSEMENT_DATE = row.Field<string>("LOAN_DISBURSEMENT_DATE"),

                    END_DATE_CONTRACT = row.Field<string>("END_DATE_CONTRACT"),

                    LAST_INSTALLMENT_PAID_DATE = row.Field<string>("LAST_INSTALLMENT_PAID_DATE"),

                    DISBURSED_AMOUNT = row.Field<decimal>("DISBURSED_AMOUNT"),

                    TOTAL_OUTSTANDING_AMT = row.Field<decimal?>("TOTAL_OUTSTANDING_AMT"),

                    PERIODICITY_PAYMENT = row.Field<string>("PERIODICITY_PAYMENT"),

                    TOTAL_NUM_INSTALLMENT = row.Field<int>("TOTAL_NUM_INSTALLMENT"),

                    INSTALLMENT_AMT = row.Field<decimal?>("INSTALLMENT_AMT"),

                    NUM_REMAINING_INSTALLMENT = row.Field<int?>("NUM_REMAINING_INSTALLMENT"),

                    NUM_OVERDUE_INSTALLMENT = row.Field<decimal?>("NUM_OVERDUE_INSTALLMENT"),

                    OVERDUE_AMT = row.Field<decimal?>("OVERDUE_AMT"),

                    LOAN_STATUS = row.Field<string>("LOAN_STATUS"),

                    RESCHEDULE_NO = row.Field<int>("RESCHEDULE_NO"),

                    LAST_RESCHEDULE_DATE = row.Field<int?>("LAST_RESCHEDULE_DATE"),

                    WRITE_OFF_AMT = row.Field<decimal>("WRITE_OFF_AMT"),

                    WRITE_OFF_DATE = row.Field<string>("WRITE_OFF_DATE"),

                    CONTRACT_PHASE = row.Field<string>("CONTRACT_PHASE"),

                    LOAN_DURATION = row.Field<int>("LOAN_DURATION"),

                    ACTUAL_END_DATE_CONTRACT = row.Field<string>("ACTUAL_END_DATE_CONTRACT"),

                    ECONOMIC_PURPOSE_CODE = row.Field<string>("ECONOMIC_PURPOSE_CODE"),

                    COMPULSORY_SAVING_AMT = row.Field<decimal>("COMPULSORY_SAVING_AMT"),

                    VOLUNTARY_SAVING_AMT = row.Field<decimal>("VOLUNTARY_SAVING_AMT"),

                    TERM_SAVING_AMT = row.Field<decimal>("TERM_SAVING_AMT"),

                    SUBSIDIZED_CREDIT_FLAG = row.Field<string>("SUBSIDIZED_CREDIT_FLAG"),

                    SERVICE_CHARGE_RATE = row.Field<decimal?>("SERVICE_CHARGE_RATE"),

                    PAYMENT_MODE = row.Field<string>("PAYMENT_MODE"),

                    ADVANCE_PAYMENT_AMT = row.Field<decimal?>("ADVANCE_PAYMENT_AMT"),

                    LAW_SUIT = row.Field<string>("LAW_SUIT"),

                    ME = row.Field<string>("ME"),

                    MEMBER_WELFARE_FUND = row.Field<string>("MEMBER_WELFARE_FUND"),

                    INSURENCE_COVERAGE = row.Field<string>("INSURENCE_COVERAGE"),


                }).ToList();


                var MFICode = ListContractDetails.Select(l => l.MFICODE).FirstOrDefault();


                var Contract_Details = new

                {

                    header = new { DataType = "H", MfiCode = MFICode, AccountingDate = DateTime.Now, ProductionDate = DateTime.Now },

                    Details = new { DataType = "C", values = ListContractDetails },

                    footer = new { DataType = "F", ListContractDetails.Count },

                };



                List<MRA_Subject_DetailsViewModel> ListSubjectDetails = new List<MRA_Subject_DetailsViewModel>();


                var SubjectDetailsParam = new { OrgID = LoggedInOrganizationID, OfficeID = LoginUserOfficeID };

                var SubjectDetails = accReportService.GetAccDataForReport(SubjectDetailsParam, "Proc_Get_SubjectDetails");


                ListSubjectDetails = SubjectDetails.Tables[0].AsEnumerable()

                .Select(row => new MRA_Subject_DetailsViewModel

                {


                    MFICODE = row.Field<string>("MFICODE"),

                    ACCOUNTINGDATE = row.Field<DateTime?>("ACCOUNTINGDATE"),

                    PRODUCTIONDATE = row.Field<DateTime?>("PRODUCTIONDATE"),

                    BRANCH_CODE = row.Field<string>("BRANCH_CODE"),

                    MEMBERID = row.Field<string>("MEMBERID"),

                    Name = row.Field<string>("Name"),

                    Occupation = row.Field<int>("Occupation"),

                    FATHERS_NAME = row.Field<string>("FATHERS_NAME"),

                    MOTHERS_NAME = row.Field<string>("MOTHERS_NAME"),

                    MARITAL_STATUS = row.Field<int>("MARITAL_STATUS"),

                    SPOUSE_NAME = row.Field<string>("SPOUSE_NAME"),

                    Gender = row.Field<string>("Gender"),

                    DOB = row.Field<string>("DOB"),

                    NID = row.Field<string>("NID"),

                    SMARTCARD_NO = row.Field<string>("SMARTCARD_NO"),

                    BIRTH_CERTIFICATE_NO = row.Field<string>("BIRTH_CERTIFICATE_NO"),

                    TIN = row.Field<string>("TIN"),

                    Other_ID_Type = row.Field<int>("Other_ID_Type"),

                    OTHER_ID_NO = row.Field<string>("OTHER_ID_NO"),

                    EXPIRY_DATE = row.Field<string>("EXPIRY_DATE"),

                    ISSUE_COUNTRY = row.Field<string>("ISSUE_COUNTRY"),

                    ContactNo = row.Field<string>("ContactNo"),

                    P_ADDRESS = row.Field<string>("P_ADDRESS"),

                    P_THANA = row.Field<string>("P_THANA"),

                    P_DISTRICT = row.Field<string>("P_DISTRICT"),

                    P_COUNTRY = row.Field<string>("P_COUNTRY"),

                    PR_ADDRESS = row.Field<string>("PR_ADDRESS"),

                    PR_THANA = row.Field<string>("PR_THANA"),


                    PR_DISTRICT = row.Field<string>("PR_DISTRICT"),

                    PR_COUNTRY = row.Field<string>("PR_COUNTRY"),

                    ACADEMIC_QUALIFICATION = row.Field<int>("ACADEMIC_QUALIFICATION"),


                }).ToList();


                 


                var Subject = new

                {

                    header = new { DataType = "H", MfiCode = MFICode, AccountingDate = DateTime.Now, ProductionDate = DateTime.Now },

                    Details = new { DataType = "C", values = ListSubjectDetails },

                    footer = new { DataType = "F", ListSubjectDetails.Count },

                };

                 

                var mraCIBData = new { Contract_Details, Subject };

                var jsonString = JsonConvert.SerializeObject(mraCIBData);


                byte[] fileBytes = Encoding.ASCII.GetBytes(jsonString);

                

                string fileName = FileName + ".json";


                //string fileName = "filename.json";

                return File(fileBytes, "application/json", fileName);


            }

            catch (Exception ex)

            {

                return Json(new { Result = "ERROR", Message = ex.Message });

            }


        }

Screen Record

 Windows Screen Record WindowsKey+ Alt + R Recording Starts.