Exemple #1
0
        public async Task <ServiceResponse <object> > SearchTutor(SearchTutorDto model)
        {
            var subjectDetails = await _context.TutorSubjects.FirstOrDefaultAsync(m => m.Id == model.SubjectId);

            var users = await(from user in _context.Users
                              join pr in _context.TutorProfiles
                              on user.Id equals pr.CreatedById

                              join subject in _context.TutorSubjects
                              on user.Id equals subject.CreatedById

                              where pr.GradeLevels.Contains(model.Class) &&
                              pr.CityId == model.CityId &&
                              subject.Name == subjectDetails.Name &&
                              user.Active == true &&
                              user.UserTypeId == (int)Enumm.UserType.Tutor
                              //&& user.Gender.ToLower() == model.Gender.ToLower()
                              select new TutorProfileForListDto
            {
                Id                     = user.Id,
                FullName               = user.FullName,
                Email                  = user.Email,
                Gender                 = user.Gender,
                CityId                 = pr.CityId,
                CityName               = _context.Cities.FirstOrDefault(m => m.Id == pr.CityId).Name,
                Subjects               = string.Join(',', _context.TutorSubjects.Where(m => m.CreatedById == user.Id).Select(m => m.Name)),
                About                  = pr.About,
                AreasToTeach           = pr.AreasToTeach,
                CommunicationSkillRate = pr.CommunicationSkillRate,
                Education              = pr.Education,
                GradeLevels            = pr.GradeLevels,
                LanguageFluencyRate    = pr.LanguageFluencyRate,
                WorkExperience         = pr.WorkExperience,
                WorkHistory            = pr.WorkHistory,
                Photos                 = _context.Photos.Where(m => m.UserId == user.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto
                {
                    Id        = x.Id,
                    Name      = x.Name,
                    IsPrimary = x.IsPrimary,
                    Url       = _File.AppendImagePath(x.Name)
                }).ToList(),
            }).ToListAsync();


            _serviceResponse.Data    = users;
            _serviceResponse.Success = true;
            return(_serviceResponse);
        }
Exemple #2
0
        public async Task <ServiceResponse <object> > GetAllStudents()
        {
            if (!string.IsNullOrEmpty(_LoggedIn_UserRole))
            {
                if (_LoggedIn_UserRole == Enumm.UserType.Teacher.ToString() && _LoggedIn_SchoolExamType == Enumm.ExamTypes.Annual.ToString())
                {
                    var CSIds = await(from csUser in _context.ClassSectionUsers
                                      where csUser.UserId == _LoggedIn_UserID
                                      select csUser.ClassSectionId).ToListAsync();

                    var Students = await(from u in _context.Users
                                         join csUser in _context.ClassSectionUsers
                                         on u.Id equals csUser.UserId
                                         where u.Role == Enumm.UserType.Student.ToString() &&
                                         CSIds.Contains(csUser.ClassSectionId) &&
                                         u.Active == true
                                         select u).Select(s => new
                    {
                        Id       = s.Id,
                        FullName = s.FullName,
                        RollNo   = s.RollNumber,
                        Photos   = _context.Photos.Where(m => m.UserId == s.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new
                        {
                            x.Name,
                            Url = _File.AppendImagePath(x.Name)
                        }).ToList()
                    }).ToListAsync();
                    _serviceResponse.Success = true;
                    _serviceResponse.Data    = new { Students, StudentCount = Students.Count() };
                }
                else if (_LoggedIn_UserRole == Enumm.UserType.Teacher.ToString() && _LoggedIn_SchoolExamType == Enumm.ExamTypes.Semester.ToString())
                {
                    var CSIds = await(from cla in _context.ClassLectureAssignment
                                      join cs in _context.ClassSections
                                      on cla.ClassSectionId equals cs.Id
                                      where cla.TeacherId == _LoggedIn_UserID
                                      select cs.Id).Distinct().ToListAsync();


                    var Students = (from csId in CSIds
                                    join csUser in _context.ClassSectionUsers
                                    on csId equals csUser.ClassSectionId
                                    join u in _context.Users
                                    on csUser.UserId equals u.Id
                                    where u.Role == Enumm.UserType.Student.ToString()
                                    //&& CSIds.Contains(csUser.ClassSectionId)
                                    && u.Active == true
                                    select u).Select(s => new
                    {
                        Id       = s.Id,
                        FullName = s.FullName,
                        RollNo   = s.RollNumber,
                        Photos   = _context.Photos.Where(m => m.UserId == s.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new
                        {
                            x.Name,
                            Url = _File.AppendImagePath(x.Name)
                        }).ToList()
                    }).ToList();

                    _serviceResponse.Success = true;
                    _serviceResponse.Data    = new { Students, StudentCount = Students.Count() };
                }
            }
            else
            {
                _serviceResponse.Success = false;
                _serviceResponse.Message = CustomMessage.UserNotLoggedIn;
            }
            return(_serviceResponse);
        }
Exemple #3
0
        public async Task <ServiceResponse <object> > GetStudentsForFee()
        {
            string CurrentMonth = DateTime.UtcNow.ToString("MMMM") + " " + DateTime.UtcNow.Year;
            var    PaidStudents = await(from fee in _context.StudentFees
                                        join u in _context.Users
                                        on fee.StudentId equals u.Id

                                        join csU in _context.ClassSectionUsers
                                        on u.Id equals csU.UserId

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

                                        where fee.Month == CurrentMonth &&
                                        fee.SchoolBranchId == _LoggedIn_BranchID
                                        select new StudentForFeeListDto
            {
                Id             = u.Id,
                FullName       = u.FullName,
                DateofBirth    = u.DateofBirth != null ? DateFormat.ToDate(u.DateofBirth.ToString()) : "",
                Email          = u.Email,
                Gender         = u.Gender,
                CountryId      = u.CountryId,
                StateId        = u.StateId,
                CityId         = u.CityId,
                CountryName    = u.Country.Name,
                StateName      = u.State.Name,
                OtherState     = u.OtherState,
                RollNumber     = u.RollNumber,
                ClassSectionId = cs.Id,
                ClassSection   = cs.Class.Name + " " + cs.Section.SectionName,
                Paid           = fee.Paid,
                FeeId          = fee.Id,
                Photos         = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).Select(x => new PhotoDto
                {
                    Id        = x.Id,
                    Name      = x.Name,
                    IsPrimary = x.IsPrimary,
                    Url       = _fileRepo.AppendImagePath(x.Name)
                }).ToList(),
            }).ToListAsync();

            var UnPaidStudents = 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.Role == Enumm.UserType.Student.ToString() &&
                                       u.SchoolBranchId == _LoggedIn_BranchID &&
                                       !PaidStudents.Select(m => m.Id).Contains(u.Id)
                                       select new StudentForFeeListDto
            {
                Id             = u.Id,
                FullName       = u.FullName,
                DateofBirth    = u.DateofBirth != null ? DateFormat.ToDate(u.DateofBirth.ToString()) : "",
                Email          = u.Email,
                Gender         = u.Gender,
                CountryId      = u.CountryId,
                StateId        = u.StateId,
                CityId         = u.CityId,
                CountryName    = u.Country.Name,
                StateName      = u.State.Name,
                OtherState     = u.OtherState,
                RollNumber     = u.RollNumber,
                ClassSectionId = cs.Id,
                ClassSection   = cs.Class.Name + " " + cs.Section.SectionName,
                Paid           = false,
                Photos         = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).Select(x => new PhotoDto
                {
                    Id        = x.Id,
                    Name      = x.Name,
                    IsPrimary = x.IsPrimary,
                    Url       = _fileRepo.AppendImagePath(x.Name)
                }).ToList(),
            }).ToListAsync();

            _serviceResponse.Data    = new { UnPaidStudents, UnPaidStudentCount = UnPaidStudents.Count(), PaidStudents, PaidStudentCount = PaidStudents.Count() };
            _serviceResponse.Success = true;
            return(_serviceResponse);
        }
Exemple #4
0
        public async Task <ServiceResponse <object> > GetUsersForChat()
        {
            List <ChatUserForListDto> Users = new List <ChatUserForListDto>();

            if (!string.IsNullOrEmpty(_LoggedIn_UserRole))
            {
                if (_LoggedIn_UserRole == Enumm.UserType.Admin.ToString())
                {
                    Users = (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.UserTypeId == (int)Enumm.UserType.Teacher &&
                             u.SchoolBranchId == _LoggedIn_BranchID

                             select new ChatUserForListDto
                    {
                        UserIds = new List <int>()
                        {
                            u.Id
                        },
                        Names = u.FullName,
                        UserName = u.Username,
                        IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(),
                        Description = cs.Class.Name + " " + cs.Section.SectionName,
                        Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto
                        {
                            Id = x.Id,
                            Name = x.Name,
                            Url = _fileRepo.AppendImagePath(x.Name)
                        }).ToList(),
                    }).Distinct().ToList();

                    Users.AddRange((from u in _context.Users
                                    where u.UserTypeId == (int)Enumm.UserType.Admin &&
                                    u.SchoolBranchId == _LoggedIn_BranchID &&
                                    u.Id != _LoggedIn_UserID
                                    select new ChatUserForListDto
                    {
                        UserIds = new List <int>()
                        {
                            u.Id
                        },
                        Names = u.FullName,
                        UserName = u.Username,
                        IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(),
                        Description = "",
                        Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto
                        {
                            Id = x.Id,
                            Name = x.Name,
                            Url = _fileRepo.AppendImagePath(x.Name)
                        }).ToList(),
                    }).Distinct().ToList());
                }
                else if (_LoggedIn_UserRole == Enumm.UserType.Teacher.ToString())
                {
                    var ClassSections = await(from csU in _context.ClassSectionUsers
                                              join cs in _context.ClassSections
                                              on csU.ClassSectionId equals cs.Id

                                              join u in _context.Users
                                              on csU.UserId equals u.Id

                                              where csU.UserId == _LoggedIn_UserID &&
                                              u.Role == Enumm.UserType.Teacher.ToString()
                                              select new ClassSectionForResultListDto
                    {
                        ClassSectionId = cs.Id,
                        Classs         = cs.Class.Name,
                        Section        = cs.Section.SectionName
                    }).Distinct().ToListAsync();
                    //var ClassSections = await (from cla in _context.ClassLectureAssignment
                    //                           join cs in _context.ClassSections
                    //                           on cla.ClassSectionId equals cs.Id
                    //                           where cla.TeacherId == _LoggedIn_UserID
                    //                           select new ClassSectionForResultListDto
                    //                           {
                    //                               ClassSectionId = cs.Id,
                    //                               Classs = cs.Class.Name,
                    //                               Section = cs.Section.SectionName
                    //                           }).Distinct().ToListAsync();
                    Users = 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

                                  let c1 = ClassSections.Select(m => m.ClassSectionId).Contains(csU.ClassSectionId)
                                           where u.UserTypeId == (int)Enumm.UserType.Student &&
                                           c1
                                           select new ChatUserForListDto
                    {
                        UserIds = new List <int>()
                        {
                            u.Id
                        },
                        Names       = u.FullName,
                        UserName    = u.Username,
                        IsOnline    = ConnectionMapping <string> .GetConnections(u.Username).Any(),
                        Description = cs.Class.Name + " " + cs.Section.SectionName,
                        Photos      = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto
                        {
                            Id   = x.Id,
                            Name = x.Name,
                            Url  = _fileRepo.AppendImagePath(x.Name)
                        }).ToList(),
                    }).Distinct().ToListAsync();

                    Users.AddRange((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

                                    let c1 = ClassSections.Select(m => m.ClassSectionId).Contains(csU.ClassSectionId)
                                             where u.UserTypeId == (int)Enumm.UserType.Teacher &&
                                             u.SchoolBranchId == _LoggedIn_BranchID &&
                                             c1 &&
                                             u.Id != _LoggedIn_UserID
                                             select new ChatUserForListDto
                    {
                        UserIds = new List <int>()
                        {
                            u.Id
                        },
                        Names = u.FullName,
                        UserName = u.Username,
                        IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(),
                        Description = cs.Class.Name + " " + cs.Section.SectionName,
                        Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto
                        {
                            Id = x.Id,
                            Name = x.Name,
                            Url = _fileRepo.AppendImagePath(x.Name)
                        }).ToList(),
                    }).Distinct().ToList());

                    Users.AddRange((from u in _context.Users
                                    where u.UserTypeId == (int)Enumm.UserType.Admin &&
                                    u.SchoolBranchId == _LoggedIn_BranchID
                                    select new ChatUserForListDto
                    {
                        UserIds = new List <int>()
                        {
                            u.Id
                        },
                        Names = u.FullName,
                        UserName = u.Username,
                        IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(),
                        Description = "",
                        Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto
                        {
                            Id = x.Id,
                            Name = x.Name,
                            Url = _fileRepo.AppendImagePath(x.Name)
                        }).ToList(),
                    }).Distinct().ToList());
                }
                else if (_LoggedIn_UserRole == Enumm.UserType.Student.ToString())
                {
                    var ClassSections = 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 csU.UserId == _LoggedIn_UserID
                                              select new ClassSectionForResultListDto
                    {
                        ClassSectionId = cs.Id,
                        Classs         = cs.Class.Name,
                        Section        = cs.Section.SectionName
                    }).Distinct().ToListAsync();

                    Users = (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

                             let c1 = ClassSections.Select(m => m.ClassSectionId).Contains(csU.ClassSectionId)
                                      where u.UserTypeId == (int)Enumm.UserType.Teacher &&
                                      u.SchoolBranchId == _LoggedIn_BranchID &&
                                      c1
                                      select new ChatUserForListDto
                    {
                        UserIds = new List <int>()
                        {
                            u.Id
                        },
                        Names = u.FullName,
                        UserName = u.Username,
                        IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(),
                        Description = cs.Class.Name + " " + cs.Section.SectionName,
                        Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto
                        {
                            Id = x.Id,
                            Name = x.Name,
                            Url = _fileRepo.AppendImagePath(x.Name)
                        }).ToList(),
                    }).Distinct().ToList();

                    Users.AddRange((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

                                    let c1 = ClassSections.Select(m => m.ClassSectionId).Contains(csU.ClassSectionId)
                                             where u.UserTypeId == (int)Enumm.UserType.Student &&
                                             u.SchoolBranchId == _LoggedIn_BranchID &&
                                             u.Id != _LoggedIn_UserID &&
                                             c1
                                             select new ChatUserForListDto
                    {
                        UserIds = new List <int>()
                        {
                            u.Id
                        },
                        UserName = u.Username,
                        IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(),
                        Names = u.FullName,
                        Description = cs.Class.Name + " " + cs.Section.SectionName,
                        Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto
                        {
                            Id = x.Id,
                            Name = x.Name,
                            Url = _fileRepo.AppendImagePath(x.Name)
                        }).ToList(),
                    }).Distinct().ToList());
                    //Users = (from u in _context.Users
                    //         join cla in _context.ClassLectureAssignment
                    //         on u.Id equals cla.TeacherId

                    //         join cs in _context.ClassSections
                    //         on cla.ClassSectionId equals cs.Id

                    //         where u.UserTypeId == (int)Enumm.UserType.Teacher
                    //         && ClassSections.Select(m => m.ClassSectionId).Contains(cla.ClassSectionId)
                    //         && u.SchoolBranchId == _LoggedIn_BranchID
                    //         select new ChatUserForListDto
                    //         {
                    //             UserIds = new List<int>() { u.Id },
                    //             Names = u.FullName,
                    //             UserName = u.Username,
                    //             IsOnline = ConnectionMapping<string>.GetConnections(u.Username).Any(),
                    //             Description = cs.Class.Name + " " + cs.Section.SectionName,
                    //             Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto
                    //             {
                    //                 Id = x.Id,
                    //                 Name = x.Name,
                    //                 Url = _fileRepo.AppendImagePath(x.Name)
                    //             }).ToList(),
                    //         }).Distinct().ToList();

                    //Users.AddRange((from u in _context.Users
                    //                join cla in _context.ClassLectureAssignment
                    //                on u.Id equals cla.TeacherId

                    //                join cs in _context.ClassSections
                    //                on cla.ClassSectionId equals cs.Id

                    //                where u.UserTypeId == (int)Enumm.UserType.Student
                    //                && ClassSections.Select(m => m.ClassSectionId).Contains(cla.ClassSectionId)
                    //                && u.SchoolBranchId == _LoggedIn_BranchID
                    //                && u.Id != _LoggedIn_UserID
                    //                select new ChatUserForListDto
                    //                {
                    //                    UserIds = new List<int>() { u.Id },
                    //                    UserName = u.Username,
                    //                    IsOnline = ConnectionMapping<string>.GetConnections(u.Username).Any(),
                    //                    Names = u.FullName,
                    //                    Description = cs.Class.Name + " " + cs.Section.SectionName,
                    //                    Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto
                    //                    {
                    //                        Id = x.Id,
                    //                        Name = x.Name,
                    //                        Url = _fileRepo.AppendImagePath(x.Name)
                    //                    }).ToList(),
                    //                }).Distinct().ToList());
                }
            }
            else
            {
                _serviceResponse.Success = false;
                _serviceResponse.Message = CustomMessage.UserNotLoggedIn;
                return(_serviceResponse);
            }
            _serviceResponse.Success = true;
            _serviceResponse.Data    = Users;
            return(_serviceResponse);
        }