Displaying data under selected table row

45 views Asked by At

The issue I am facing using ASP.NET Core I have manager class, dto, cshtml, and enum

This is my dto class

     public class InvestmentDetailDto
     {
     public InvestmentDetailDto()
     {
     AmountType = new List<PickList>();
     SectionCode = new List<PickList>();
      public int Id { get; set; }

    public string EmployeeId { get; set; }

    public string Name { get; set; }
    public string PolicyNumber { get; set; }

    public decimal Amount { get; set; }
    public decimal AMTAmount { get; set; }
    public DateTime InvestmentStartDate { get; set; }
    public DateTime InvestmentEndDate { get; set; }
    public bool IsDeleted { get; set; }
    public List<PickList> AmountType { get; set; }
    public List<PickList> SectionCode { get; set; }
    public int AmountTypeId { get; set; }
    public int SectionCodeId { get; set; }
    public string PolicyNo { get; set; }
    public bool IsActive { get; set; }
     
    }`

here is my loop in the manager class for mapping

                        foreach (var invest in 
                        investment.EmployeeInvestmentDetails.Where(x =>!x.IsDeleted && 
                         x.IsActive == true ))
                        {
                            var invertDetail = new InvestmentDetailDto();
                         
                            invertDetail.Name = invest.Name.ToString(); 
                            invertDetail.AMTAmount = invest.AMTAmount ?? 0;
                            invertDetail.Amount = invest.Amount ?? 0;

                            empSalaryDetail.EmployeeInvestmentDetails.Add(invertDetail);
                            




                        }

here is the cshtml

    @foreach (var sectionName in new[] { "80C", "80CCC", "80CCD" })
{
    var matchingInvestments = Model.EmployeeInvestmentDetails.Where(x => x.SectionCode.Any(p => p.Value == sectionName)).ToList();

    if (matchingInvestments.Any())
    {
        <tr>
            <td class="mainLine" style="padding-left: 2%;">@sectionName</td>
            <td class="INRLine"></td>
            <td class="INRLine"></td>
            <td class="INRLine"></td>
        </tr>

        foreach (var item in matchingInvestments)
        {
            <tr>
                <td class="mainLine" style="padding-left: 2%;">@item.Name</td>
                <td class="INRLine"><b>@item.Amount</b></td>
                <td class="INRLine"><b>@item.Amount</b></td>
                <td class="INRLine"><b>@item.AMTAmount</b></td>
            </tr>
        }
    }
}

here is the enum created

   public enum SectionCodeEnum
 {
  [Display(Name = "80C")]
  Eighty_C = 1,
  [Display(Name = "80CCC")]
  Eighty_CCC = 2,
  [Display(Name = "80CCD")]
  Eighty_CCD = 3,

section is a pick up list which is shown below

   public class PickList
  {
   public int Id { get; set; }
   public string Value { get; set; }
  }

i have to show like this in my form

Whenever I insert investment name under any section that should be visible like this (like 80C and names of investment under it same with 80CCC and 80CCD)

Instead I am not getting anything

1

There are 1 answers

0
Lakhwinder Singh On

InvestmentDetailDto: This class appears to be a DTO (Data Transfer Object) used to transfer investment-related data. It contains properties for various investment details. You're also using lists of PickList for AmountType and SectionCode.

foreach Loop: You're using a foreach loop to iterate over a collection of investments and populate an InvestmentDetailDto for each investment. The code inside the loop sets the properties of the InvestmentDetailDto based on the values of the investment.

SectionCodeEnum: This is an enum that defines section codes like "80C," "80CCC," and "80CCD." It also uses the [Display] attribute to provide human-readable names for the enum values.

PickList: This is a class representing items with an ID and a value, which is a common pattern used for defining options or items within various contexts.