Search code examples
c#csvfilesortingcredit-card

How do i sort data in a csv file to a standardized output, While reading headers to sort data


INPUT
INPUT

OUTPUT
OUTPUT

I need to know how can i read different people's details and arrange, as Rahul and Ritu are in the same column so I will need to allot the following transactions after ritu's name to ritu how can I do this? Simmilar for International and Domestic transactions.


Solution

  • OK, first of all you need to create two models:

    class Person
    {
      public string Name {get; set;}
      public List<Transaction> Transactions { get; set; }
    }
    
    enum TransactionType
    {
      Domestic,
      International
    }
    
    class Transaction
    {
      public Person Owner { get; set; }
      public DateTimeOffset Date { get; set; }
      public string TransactionDescription { get; set; }
      public TransactionType TransactionType { get; set; }
    
      //and so on
    }
    

    But the problem is that input file is not standard csv nor json file. So you will have to parse it by yourself to such domain as I proposed.

    Next you can have a list of such transactions and order it by date using Linq:

    //using System.Linq;
    
    List<Transaction> transactions = GetTransactionsSomehow();
    transactions.OrderBy(x => x.Date);
    

    And that's really it.