Click here to Skip to main content
15,844,904 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this code, which has multiple accounts on different conditions. For example, if the account is AH, then all data of AH accounts based on customer id will be saved in an XML file on button click. How to create an XML file for it. I am new to XML. I have tried XML serialize. But it didn't work even for manually added data. I need to know which steps I should take.

What I have tried:

C#
  1  public ActionResult ReportWrongCompare(VM_ReportComparison model)
  2  {
  3      if (model.AccountType == (int)AccountTypes.AccountHistory)
  4      {
  5          if (model.CustomerAccountId.HasValue 
  6              && model.CustomerAccountId.Value > 0)
  7          {
  8              if (model.AccountTypedAccountId.HasValue 
  9                  && model.AccountTypedAccountId.Value > 0)
 10              {
 11                  VM_CustomerAccount customerAccount = 
 12                  new VM_CustomerAccount().FindDetailsById
 13                         (model.CustomerAccountId.Value);
 14                  model.CustomerAccount = customerAccount;
 15              }
 16          }
 17  
 18          if (model.C_CustomerAccountId.HasValue 
 19              && model.C_CustomerAccountId.Value > 0)
 20          {
 21              if(model.C_AccountTypedAccountId.HasValue 
 22                 && model.C_AccountTypedAccountId.Value > 0)
 23              {
 24                  VM_CustomerAccount customerAccount = 
 25                  new VM_CustomerAccount().FindDetailsById
 26                  (model.C_CustomerAccountId.Value);
 27                  model.CustomerAccount = customerAccount;
 28              }
 29          }
 30      }
 31      else if(model.AccountType == (int)AccountTypes.PublicRecord)
 32      {
 33          if (model.CustomerAccountId.HasValue 
 34              && model.CustomerAccountId.Value > 0)
 35          {
 36              if(model.AccountTypedAccountId.HasValue 
 37                 && model.AccountTypedAccountId.Value > 0)
 38              {
 39                  VM_CustomerAccount customerAccount = 
 40                  new VM_CustomerAccount().FindDetailsById
 41                      (model.CustomerAccountId.Value);
 42                  model.CustomerAccount = customerAccount;
 43              }
 44          }
 45  
 46          if (model.C_CustomerAccountId.HasValue 
 47              && model.C_CustomerAccountId.Value > 0)
 48          {
 49              if (model.C_AccountTypedAccountId.HasValue 
 50                  && model.C_AccountTypedAccountId.Value > 0)
 51              {
 52                  VM_CustomerAccount customerAccount = 
 53                  new VM_CustomerAccount().FindDetailsById
 54                         (model.C_CustomerAccountId.Value);
 55                  model.CustomerAccount = customerAccount;
 56              }
 57          }
 58      }
 59      else if (model.AccountType == (int)AccountTypes.CreditInquiry)
 60      {
 61          if (model.CustomerAccountId.HasValue 
 62              && model.CustomerAccountId.Value > 0)
 63          {
 64              if (model.AccountTypedAccountId.HasValue 
 65                  && model.AccountTypedAccountId.Value > 0)
 66              {
 67                  VM_CustomerAccount customerAccount = 
 68                  new VM_CustomerAccount().FindDetailsById
 69                         (model.CustomerAccountId.Value);
 70                  model.CustomerAccount = customerAccount;
 71              }
 72          }
 73  
 74          if (model.C_CustomerAccountId.HasValue 
 75              && model.C_CustomerAccountId.Value > 0)
 76          {
 77              if (model.C_AccountTypedAccountId.HasValue 
 78                  && model.C_AccountTypedAccountId.Value > 0)
 79              {
 80                  VM_CustomerAccount customerAccount = 
 81                  new VM_CustomerAccount().FindDetailsById
 82                                 (model.C_CustomerAccountId.Value);
 83                  model.CustomerAccount = customerAccount;
 84              }
 85          }
 86      }
 87      else if (model.AccountType == (int)AccountTypes.TechData)
 88      {
 89          if (model.CustomerAccountId.HasValue 
 90              && model.CustomerAccountId.Value > 0)
 91          {
 92              if (model.AccountTypedAccountId.HasValue 
 93                  && model.AccountTypedAccountId.Value > 0)
 94              {
 95                  VM_CustomerAccount customerAccount = 
 96                  new VM_CustomerAccount().FindDetailsById
 97                      (model.CustomerAccountId.Value);
 98                  model.CustomerAccount = customerAccount;
 99              }
100          }
101  
102          if (model.C_CustomerAccountId.HasValue 
103              && model.C_CustomerAccountId.Value > 0)
104          {
105              if (model.C_AccountTypedAccountId.HasValue 
106                  && model.C_AccountTypedAccountId.Value > 0)
107              {
108                  VM_CustomerAccount customerAccount = 
109                  new VM_CustomerAccount().FindDetailsById
110                      (model.C_CustomerAccountId.Value);
111                  model.CustomerAccount = customerAccount;
112              }
113          }
114      }
115  
116      return View("_ReportWrongCompare", 
117                   _AutoDisputeEnterPriseLayout, model);
118  }
Posted
Updated 12-Sep-23 13:03pm
v3
Comments
Member 15627495 11-Sep-23 1:23am    
look at Xdocument Class. load() and save() function will make reading and writing through Xml.

https://learn.microsoft.com/en-us/dotnet/standard/linq/xdocument-class-overview

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900