Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a table Program.

it contains 3 columns
a).ID, b).AGENCY_NAME C) Marks

Now i want to add the marks of the column if "AGENCY_NAME" is similar, and then calculate the avg.
AGENCY_NAME CAN BE OF DIFFERENT TYPES


So mvc controller Code.


public ActionResult TrainingInstitute(String agenda_no = "")
      {
          DisplayLndRep dn = new DisplayLndRep();
          DbAccess da = new DbAccess();
          dn.FeedbackDetailList5=new List<lnd_prgm>();
          dn.FeedbackDetailList5 = da.FindInstiStdCount(agenda_no);
          dn.app_count = dn.FeedbackDetailList5.Count;
          if(dn.app_count>0)
          {
           dn.ListArcGrid = new List<ReportLndFeedback>();
           dn.FeedbackDetailList4 = da.FindInstiPgmTypCount(agenda_no);
           dn.pg1_count = dn.FeedbackDetailList4.Count();
           dn.pg2_count = dn.app_count - dn.pg1_count;
           dn.score = da.FindTotalScore(agenda_no);
          //    dn.ListArcGrid = new List<ReportLndFeedback>();
        //   dn.ListTReports = da.FindTReports();

          //dn.AgendaDetailList = new List<AgendaDetails>();
          dn.PageSize = 10;
          }

          else
          {
              TempData["notice"] = "There is no such record for Training Institute." + agenda_no;
              return RedirectToAction("ReportModule", "Home");
          }

          return View(dn);
      }




PROBLEM I AM FACING IS HOW TO DEFINE THE FOLLOWING FUNCTION SO
DEFINIFTION FOR
FindTotalScore
. I Am not able to develop this logic to calcute the total marks.


public List<lnd_prgm> FindTotalScore(string searchField)
{
    context.Configuration.AutoDetectChangesEnabled = false;
    context.Configuration.LazyLoadingEnabled = false;
    List<lnd_prgm> rLst = new List<lnd_prgm>();
    searchField = searchField.ToLower();
    int i;

    rLst = (from c in context.lnd_prgm.Where(x => x.agency_name == searchField) orderby c.prgm_id select c).ToList();

    for (int i = 0; i < rLst.Count; i++)
    {
        i = i + rLst[i].pgm_avg;
    }
    return rLst;
}


What I have tried:

not able to code the function to calculate and then display.
Posted
Updated 17-Jun-19 1:44am

1 solution

You're using exact match:
C#
rLst = (from c in context.lnd_prgm.Where(x => x.agency_name == searchField) orderby c.prgm_id select c).ToList();

But, if i understand you well, you want to get agencies with similar names (usage of SQL Like "%whatever%" operator):
C#
rLst = (from c in context.lnd_prgm.Where(x => x.agency_name.Contains(searchField)) orderby c.prgm_id select c).ToList();
//lambda version:
//rLst = context.lnd_prgm
//        .Where(x => x.agency_name.Contains(searchField))
//        .OrderBy(x=>x.prgm_id)
//        .ToList()


For further details, please see: Enumerable.Contains Method (System.Linq) | Microsoft Docs[^]
 
Share this answer
 

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