Ejemplo n.º 1
0
        public async Task <ServiceResponse <object> > GetParentChildAttendance()
        {
            var Parent   = _context.Users.Where(m => m.Id == _LoggedIn_UserID).FirstOrDefault();
            var Students = await(from u in _context.Users
                                 join csU in _context.ClassSectionUsers
                                 on u.Id equals csU.UserId

                                 join cs in _context.ClassSections
                                 on csU.ClassSectionId equals cs.Id

                                 where u.ParentContactNumber == Parent.ParentContactNumber &&
                                 u.ParentEmail == Parent.ParentEmail &&
                                 u.Role == Enumm.UserType.Student.ToString()
                                 select new ParentChildAttendanceForListDto
            {
                Id             = u.Id,
                FullName       = u.FullName,
                TeacherName    = _context.ClassSectionUsers.FirstOrDefault(m => m.ClassSectionId == cs.Id && m.UserTypeId == (int)Enumm.UserType.Teacher).User.FullName,
                ClassSectionId = cs.Id,
                ClassSection   = cs.Class.Name + " " + cs.Section.SectionName,
                Photos         = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).Select(x => new PhotoDto
                {
                    Id   = x.Id,
                    Name = x.Name,
                    Url  = _File.AppendImagePath(x.Name)
                }).ToList(),
            }).ToListAsync();

            foreach (var item in Students)
            {
                string[] Months = new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
                foreach (var month in Months)
                {
                    var StartDateByMonth        = new DateTime(DateTime.UtcNow.Year, Array.IndexOf(Months, month) + 1, 1);
                    var LastDateByMonth         = StartDateByMonth.AddMonths(1).AddDays(-1);
                    var DaysCountByMonth        = GenericFunctions.BusinessDaysUntil(StartDateByMonth, LastDateByMonth);
                    var UserPresentCountByMonth = (from u in _context.Users
                                                   join att in _context.Attendances
                                                   on u.Id equals att.UserId
                                                   where u.Id == item.Id &&
                                                   att.Present == true &&
                                                   att.CreatedDatetime.Date >= StartDateByMonth.Date && att.CreatedDatetime.Date <= LastDateByMonth.Date
                                                   select att).ToList().Count();
                    item.AttendancePercentage.Add(new ThisMonthAttendancePercentageDto
                    {
                        MonthName  = month,
                        Month      = (Array.IndexOf(Months, month) + 1),
                        Percentage = GenericFunctions.CalculatePercentage(UserPresentCountByMonth, DaysCountByMonth)
                    });
                }
            }

            _serviceResponse.Data    = new { Students, StudentCount = Students.Count(), };
            _serviceResponse.Success = true;
            return(_serviceResponse);
        }
Ejemplo n.º 2
0
        public async Task <ServiceResponse <object> > GetLoggedUserAttendancePercentage()
        {
            var userDetails = _context.Users.Where(m => m.Id == _LoggedIn_UserID).FirstOrDefault();

            if (userDetails != null)
            {
                var StartDate = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1);
                var LastDate  = DateTime.UtcNow.Date;
                var DaysCount = GenericFunctions.BusinessDaysUntil(StartDate, LastDate);

                var UserPresentCount = (from u in _context.Users
                                        join att in _context.Attendances
                                        on u.Id equals att.UserId
                                        where u.UserTypeId == userDetails.UserTypeId &&
                                        u.Id == _LoggedIn_UserID &&
                                        att.Present == true &&
                                        att.CreatedDatetime.Date >= StartDate.Date && att.CreatedDatetime.Date <= LastDate.Date
                                        select att).ToList().Count();
                var CurrentMonthLoggedUserPercentage = GenericFunctions.CalculatePercentage(UserPresentCount, DaysCount);

                var      LoggedUserAttendanceByMonthPercentage = new List <ThisMonthAttendancePercentageDto>();
                string[] Months = new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
                for (int i = 0; i < Months.Length; i++)
                {
                    string month                   = Months[i];
                    var    StartDateByMonth        = new DateTime(DateTime.UtcNow.Year, (Array.IndexOf(Months, month) + 1), 1);
                    var    LastDateByMonth         = StartDateByMonth.AddMonths(1).AddDays(-1);
                    var    DaysCountByMonth        = GenericFunctions.BusinessDaysUntil(StartDateByMonth, LastDateByMonth);
                    var    UserPresentCountByMonth = (from u in _context.Users
                                                      join att in _context.Attendances
                                                      on u.Id equals att.UserId
                                                      where u.UserTypeId == userDetails.UserTypeId &&
                                                      u.Id == _LoggedIn_UserID &&
                                                      att.Present == true &&
                                                      att.CreatedDatetime.Date >= StartDateByMonth.Date && att.CreatedDatetime.Date <= LastDateByMonth.Date
                                                      select att).ToList().Count();
                    LoggedUserAttendanceByMonthPercentage.Add(new ThisMonthAttendancePercentageDto
                    {
                        MonthName  = month,
                        Month      = Array.IndexOf(Months, month) + 1,
                        Percentage = GenericFunctions.CalculatePercentage(UserPresentCountByMonth, DaysCountByMonth)
                    });
                }
                _serviceResponse.Data    = new { CurrentMonthLoggedUserPercentage, LoggedUserAttendanceByMonthPercentage };
                _serviceResponse.Success = true;
            }
            else
            {
                _serviceResponse.Success = false;
                _serviceResponse.Message = CustomMessage.UserNotLoggedIn;
            }
            return(_serviceResponse);
        }
Ejemplo n.º 3
0
        public async Task <ServiceResponse <object> > GetThisMonthAttendanceOfSemesterStudent()
        {
            if (_LoggedIn_UserID != 0)
            {
                var StartDate        = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1);
                var LastDate         = DateTime.Today.Date;
                var DaysCount        = GenericFunctions.BusinessDaysUntil(StartDate, LastDate);
                var UserPresentCount = (from u in _context.Users
                                        join att in _context.Attendances
                                        on u.Id equals att.UserId
                                        where u.UserTypeId == (int)Enumm.UserType.Student &&
                                        u.Id == _LoggedIn_UserID &&
                                        att.Present == true &&
                                        att.CreatedDatetime.Date >= StartDate.Date && att.CreatedDatetime.Date <= LastDate.Date
                                        select att).ToList().Count();
                var CurrentMonthLoggedUserPercentage = GenericFunctions.CalculatePercentage(UserPresentCount, DaysCount);

                var studentSemesters = (from csU in _context.ClassSectionUsers
                                        join cs in _context.ClassSections
                                        on csU.ClassSectionId equals cs.Id

                                        join sem in _context.Semesters
                                        on cs.SemesterId equals sem.Id
                                        where csU.UserId == _LoggedIn_UserID
                                        select new
                {
                    cs.SemesterId,
                    cs.SemesterObj.Name,
                    sem.StartDate,
                    sem.EndDate
                }).ToList();

                var SemesterDetails = $"{studentSemesters[0].Name} From {studentSemesters[0].StartDate.ToShortDateString()} To {studentSemesters[0].EndDate.ToShortDateString()}";
                var studentSubjects = await(from sa in _context.SubjectAssignments
                                            where studentSemesters.Select(m => m.SemesterId).Contains(sa.SemesterId)
                                            select new
                {
                    sa.SubjectId,
                    sa.Subject.Name,
                    //l.StartDate,
                    //l.EndDate
                }).Distinct().ToListAsync();

                var LoggedUserAttendanceByMonthPercentage = new List <ThisMonthAttendanceOfSemesterStdDto>();
                var Start = studentSemesters[0].StartDate;
                var End   = studentSemesters[0].EndDate;
                End = new DateTime(End.Year, End.Month, DateTime.DaysInMonth(End.Year, End.Month));

                var     Months             = Enumerable.Range(0, Int32.MaxValue).Select(e => Start.AddMonths(e)).TakeWhile(e => e <= End).Select(e => e.Month).ToArray();
                decimal allMonthPercentage = 0;

                for (int i = 0; i < studentSubjects.Count(); i++)
                {
                    var item = studentSubjects[i];

                    for (int j = 0; j < Months.Length; j++)
                    {
                        var month            = Months[j];
                        var StartDateByMonth = new DateTime(DateTime.UtcNow.Year, month, 1);
                        var LastDateByMonth  = StartDateByMonth.AddMonths(1).AddDays(-1);
                        var DaysCountByMonth = GenericFunctions.BusinessDaysUntil(StartDateByMonth, LastDateByMonth);

                        var UserPresentCountByMonth = (from u in _context.Users
                                                       join att in _context.Attendances
                                                       on u.Id equals att.UserId
                                                       where u.UserTypeId == (int)Enumm.UserType.Student &&
                                                       att.Id == _LoggedIn_UserID &&
                                                       att.Present == true &&
                                                       att.CreatedDatetime.Date >= StartDateByMonth.Date && att.CreatedDatetime.Date <= LastDateByMonth.Date &&
                                                       att.SubjectId == item.SubjectId
                                                       select att).ToList().Count();

                        allMonthPercentage += GenericFunctions.CalculatePercentage(UserPresentCountByMonth, DaysCountByMonth);
                    }

                    LoggedUserAttendanceByMonthPercentage.Add(new ThisMonthAttendanceOfSemesterStdDto
                    {
                        SubjectName = item.Name,
                        Percentage  = allMonthPercentage / Months.Length,
                    });
                }
                _serviceResponse.Data    = new { CurrentMonthLoggedUserPercentage, LoggedUserAttendanceByMonthPercentage, SemesterDetails };
                _serviceResponse.Success = true;
            }
            else
            {
                _serviceResponse.Success = false;
                _serviceResponse.Message = CustomMessage.UserNotLoggedIn;
            }
            return(_serviceResponse);
        }
Ejemplo n.º 4
0
        public async Task <ServiceResponse <object> > GetParentChildResult()
        {
            var Parent   = _context.Users.Where(m => m.Id == _LoggedIn_UserID).FirstOrDefault();
            var Students = await(from u in _context.Users
                                 join csU in _context.ClassSectionUsers
                                 on u.Id equals csU.UserId

                                 join cs in _context.ClassSections
                                 on csU.ClassSectionId equals cs.Id

                                 where u.ParentContactNumber == Parent.ParentContactNumber &&
                                 u.ParentEmail == Parent.ParentEmail &&
                                 u.Role == Enumm.UserType.Student.ToString()
                                 select new ParentChildResultForListDto
            {
                Id             = u.Id,
                FullName       = u.FullName,
                TeacherName    = _context.ClassSectionUsers.FirstOrDefault(m => m.ClassSectionId == cs.Id && m.UserTypeId == (int)Enumm.UserType.Teacher).User.FullName,
                ClassSectionId = cs.Id,
                ClassSection   = cs.Class.Name + " " + cs.Section.SectionName,
                Photos         = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).Select(x => new PhotoDto
                {
                    Id   = x.Id,
                    Name = x.Name,
                    Url  = _File.AppendImagePath(x.Name)
                }).ToList(),
            }).ToListAsync();

            foreach (var item in Students)
            {
                item.Result = await(from r in _context.Results
                                    join s in _context.Subjects
                                    on r.SubjectId equals s.Id

                                    join ass in _context.ClassSectionAssignment
                                    on r.ReferenceId equals ass.Id

                                    join sub in _context.ClassSectionAssigmentSubmissions
                                    on ass.Id equals sub.ClassSectionAssignmentId

                                    where r.StudentId == item.Id &&
                                    sub.StudentId == item.Id
                                    select new ResultForListDto
                {
                    StudentId     = r.StudentId,
                    SubjectId     = r.SubjectId,
                    Subject       = s.Name,
                    ReferenceId   = r.ReferenceId.Value,
                    Reference     = ass.AssignmentName,
                    ObtainedMarks = r.ObtainedMarks,
                    TotalMarks    = r.TotalMarks,
                    Percentage    = GenericFunctions.CalculatePercentage(r.ObtainedMarks, r.TotalMarks)
                }).ToListAsync();

                item.TotalObtained   = item.Result.Select(m => m.ObtainedMarks).Sum();
                item.Total           = item.Result.Select(m => m.TotalMarks).Sum();
                item.TotalPercentage = item.Result.Count() > 0 ? GenericFunctions.CalculatePercentage(item.Result.Select(m => m.ObtainedMarks).Sum(), item.Result.Select(m => m.TotalMarks).Sum()) : 0;
            }

            _serviceResponse.Data    = new { Students, StudentCount = Students.Count(), };
            _serviceResponse.Success = true;
            return(_serviceResponse);
        }
Ejemplo n.º 5
0
        public async Task <ServiceResponse <object> > GetStudentResult(int id)
        {
            if (id > 0)
            {
                var Result = await(from u in _context.Users
                                   join sub in _context.ClassSectionAssigmentSubmissions
                                   on u.Id equals sub.StudentId

                                   join ass in _context.ClassSectionAssignment
                                   on sub.ClassSectionAssignmentId equals ass.Id

                                   where u.Id == id
                                   select new AllStdExamResultListDto
                {
                    ExamId   = sub.ClassSectionAssignmentId,
                    ExamName = ass.AssignmentName,
                }).ToListAsync();
                for (int i = 0; i < Result.Count; i++)
                {
                    var item = Result[i];
                    item.Result = await(from r in _context.Results
                                        join s in _context.Subjects
                                        on r.SubjectId equals s.Id

                                        where r.ReferenceId == item.ExamId &&
                                        r.StudentId == id
                                        select new ResultForListDto
                    {
                        StudentId     = r.StudentId,
                        SubjectId     = r.SubjectId,
                        Subject       = s.Name,
                        ReferenceId   = r.ReferenceId.Value,
                        Reference     = item.ExamName,
                        ObtainedMarks = r.ObtainedMarks,
                        TotalMarks    = r.TotalMarks,
                        Percentage    = GenericFunctions.CalculatePercentage(r.ObtainedMarks, r.TotalMarks)
                    }).ToListAsync();

                    item.TotalObtained   = item.Result.Select(m => m.ObtainedMarks).Sum();
                    item.Total           = item.Result.Select(m => m.TotalMarks).Sum();
                    item.TotalPercentage = GenericFunctions.CalculatePercentage(item.Result.Select(m => m.ObtainedMarks).Sum(), item.Result.Select(m => m.TotalMarks).Sum());

                    item.HighestMarks = await(from r in _context.Results
                                              join s in _context.Subjects
                                              on r.SubjectId equals s.Id

                                              where r.ReferenceId == item.ExamId
                                              select r).MaxAsync(m => m.ObtainedMarks);

                    item.LowestMarks = await(from r in _context.Results
                                             join s in _context.Subjects
                                             on r.SubjectId equals s.Id

                                             where r.ReferenceId == item.ExamId
                                             select r).MinAsync(m => m.ObtainedMarks);

                    var sumOfMarks = await(from r in _context.Results
                                           join s in _context.Subjects
                                           on r.SubjectId equals s.Id

                                           where r.ReferenceId == item.ExamId
                                           select r).SumAsync(m => m.ObtainedMarks);
                    var countOfMarks = (from r in _context.Results
                                        join s in _context.Subjects
                                        on r.SubjectId equals s.Id

                                        where r.ReferenceId == item.ExamId
                                        select r).Count();
                    item.AverageMarks = sumOfMarks / countOfMarks;
                }


                _serviceResponse.Data = new { Result };
            }
            _serviceResponse.Success = true;
            return(_serviceResponse);
        }