Ejemplo n.º 1
0
      public async Task <IActionResult> AttendanceScript(StdntAttndncVm st)
      {
          var ClassName = await _context.Class.AsNoTracking().Where(s => s.ClassId == st.clsidVM).FirstOrDefaultAsync();

          ViewBag.ClassName = ClassName.ClassName;
          var SectionName = await _context.Section.AsNoTracking().Where(s => s.SectionId == st.SecId).FirstOrDefaultAsync();

          ViewBag.SectionName = SectionName.SectionName;
          var SubjectName = await _context.Subject.AsNoTracking().Where(s => s.SubjectId == st.sbjctidVM).FirstOrDefaultAsync();

          ViewBag.SubjectName = SubjectName.SubjectTitle;
          var attedence = await _context.StudentAttendance.AsNoTracking().Where(s => s.Student.ClassId == st.clsidVM && s.Student.SectionId == st.SecId && s.SubjectId == st.sbjctidVM).ToListAsync();

          var count = (from a in attedence
                       where a.SubjectId == st.sbjctidVM
                       group a by(a.StudentId) into s
                       select new
            {
                StudentId = s.Key,
                Total = s.Distinct().Count(),
                Present = s.Sum(a => a.Status)
            }).ToList();

          var stu = _context.Student.AsNoTracking().Where(s => s.ClassId == st.clsidVM && s.SectionId == st.SecId).ToList();

          var query = from s in stu
                      join c in count on s.StudentId equals c.StudentId
                      select new
          {
              Name    = s.StudentName,
              ID      = s.StudentId,
              Total   = c.Total,
              Present = c.Present
          };

          List <StdntAttndncVm> send = new List <StdntAttndncVm>();
          var cn = 1;

          foreach (var item in query)
          {
              StdntAttndncVm s = new StdntAttndncVm()
              {
                  Name      = item.Name,
                  stdntidVM = item.ID,
                  Total     = item.Total,
                  Present   = item.Present,
              };
              s.stdntattserialnoVM = cn;
              cn++;
              send.Add(s);
          }
          return(View(send));
      }
Ejemplo n.º 2
0
      public async Task <IActionResult> Attendance(StdntAttndncVm st)
      {
          var ClassName = await _context.Class.AsNoTracking().Where(s => s.ClassId == st.clsidVM).FirstOrDefaultAsync();

          ViewBag.ClassName = ClassName.ClassName;
          var SectionName = await _context.Section.AsNoTracking().Where(s => s.SectionId == st.SecId).FirstOrDefaultAsync();

          ViewBag.SectionName = SectionName.SectionName;


          var stu = await _context.Student.AsNoTracking().Where(s => s.ClassId == st.clsidVM && s.SectionId == st.SecId).ToListAsync();

          var i = 1;

          var at = new List <StdntAttndncVm>();

          foreach (var item in stu)
          {
              StdntAttndncVm s = new StdntAttndncVm()
              {
                  Name               = item.StudentName,
                  stdntidVM          = item.StudentId,
                  stdntattremarkVM   = "",
                  Status             = 1,
                  stdntattserialnoVM = i,
                  SecId              = item.SectionId,
                  sbjctidVM          = st.sbjctidVM,
                  clsidVM            = st.clsidVM
              };
              i++;
              at.Add(s);
          }


          return(View(at));
      }