Beispiel #1
0
        public async Task <IActionResult> GetAttendanceToDisplay(AttendanceDtoForDisplay model)
        {
            ServiceResponse <IEnumerable <UserByTypeListDto> > responseUsers = await _userRepository.GetUsersByType(model.TypeId, model.ClassSectionId);

            _response = await _repo.GetAttendances(responseUsers.Data, model);

            return(Ok(_response));
        }
        public async Task <ServiceResponse <object> > GetAttendances(IEnumerable <UserByTypeListDto> list, AttendanceDtoForDisplay model)
        {
            OnInIt();
            DateTime DTdate   = DateTime.ParseExact(model.Date, "MM/dd/yyyy", null);
            var      ToReturn = (from user in list
                                 join attendance in _context.Attendances
                                 on user.UserId equals attendance.UserId

                                 where attendance.CreatedDatetime.Date == DTdate.Date
                                 select new AttendanceDtoForList
            {
                Id = attendance.Id,
                UserId = attendance.UserId,
                ClassSectionId = Convert.ToInt32(attendance.ClassSectionId),
                SubjectId = Convert.ToInt32(attendance.SubjectId),
                FullName = user.FullName,
                CreatedDatetime = DateFormat.ToDate(attendance.CreatedDatetime.ToString()),
                Present = attendance.Present,
                Absent = attendance.Absent,
                Late = attendance.Late,
                Comments = attendance.Comments,
                Leave = attendance.Leave,
                LeaveComments = attendance.LeaveDescription,
                LeaveCount = user.LeaveCount,     // _context.Leaves.Where(m => m.UserId == user.UserId).Count(),
                AbsentCount = user.AbsentCount,   //_context.Attendances.Where(m => m.UserId == user.UserId && m.Absent == true).Count(),
                LateCount = user.LateCount,       //_context.Attendances.Where(m => m.UserId == user.UserId && m.Late == true).Count(),
                PresentCount = user.PresentCount, // _context.Attendances.Where(m => m.UserId == user.UserId && m.Present == true).Count(),
                Photos = user.Photos
                                                  //LeaveFrom = _context.Leaves.Where(m => m.UserId == UserId).FirstOrDefault()?.FromDate,
                                                  //LeaveTo = _context.Leaves.Where(m => m.UserId == UserId).FirstOrDefault()?.ToDate,
                                                  //LeavePurpose = _context.Leaves.Where(m => m.UserId == UserId).FirstOrDefault()?.Details,
                                                  //LeaveType = _context.LeaveTypes.Where(m => m.Id == _context.Leaves.Where(m => m.UserId == UserId).FirstOrDefault().LeaveTypeId).FirstOrDefault()?.Type
            }).ToList();

            ToReturn.AddRange(list.Where(m => !ToReturn.Select(m => m.UserId).Contains(m.UserId)).Select(o => new AttendanceDtoForList
            {
                UserId          = o.UserId,
                ClassSectionId  = o.ClassSectionId,
                SubjectId       = o.SubjectId,
                FullName        = o.FullName,
                CreatedDatetime = "",
                Present         = false,
                Absent          = false,
                Late            = false,
                Leave           = false,
                Comments        = "",
                LeaveComments   = "",
                LeaveCount      = o.LeaveCount,
                AbsentCount     = o.AbsentCount,
                LateCount       = o.LateCount,
                PresentCount    = o.PresentCount,
                Photos          = o.Photos
            }).ToList());
            //ToReturn.AddRange(ToReturn.Where(m => !list.Select(m => m.UserId).Contains(m.UserId)));
            //var attendances = await _context.Attendances.Where(m => m.SchoolBranchId == _LoggedIn_BranchID).ToListAsync();
            //var ToReturn = attendances.Select(o => new AttendanceDtoForList
            //{
            //    UserId = o.UserId,
            //    Present = o.Present,
            //    Absent = o.Absent,
            //    Late = o.Late,
            //    Comments = o.Comments,
            //    //LeaveCount = _context.Leaves.Where(m => m.UserId == o.UserId).Count(),
            //    //AbsentCount = _context.Attendances.Where(m => m.UserId == o.UserId && m.Absent == true).Count(),
            //    //LateCount = _context.Attendances.Where(m => m.UserId == o.UserId && m.Late == true).Count(),
            //    //PresentCount = _context.Attendances.Where(m => m.UserId == o.UserId && m.Present == true).Count(),
            //    ////LeaveFrom = _context.Leaves.Where(m => m.UserId == o.UserId).FirstOrDefault()?.FromDate,
            //    ////LeaveTo = _context.Leaves.Where(m => m.UserId == o.UserId).FirstOrDefault()?.ToDate,
            //    ////LeavePurpose = _context.Leaves.Where(m => m.UserId == o.UserId).FirstOrDefault()?.Details,
            //    ////LeaveType = _context.LeaveTypes.Where(m => m.Id == _context.Leaves.Where(m => m.UserId == o.UserId).FirstOrDefault().LeaveTypeId).FirstOrDefault()?.Type
            //}).ToList();
            _serviceResponse.Data    = ToReturn;
            _serviceResponse.Success = true;
            return(_serviceResponse);
        }