public IEnumerable <StudentQuestionVM> GetQuestionsByIds(List <int> ids) { var questions = new List <StudentQuestionVM>(); foreach (var id in ids) { var question = _questionRepo.GetAll().SingleOrDefault(q => q.Id == id); var userData = GetStudent(question.UserId); List <StudentQuestionVM> questionsList = new List <StudentQuestionVM>(); var studentData = GetStudent(question.UserId); if (studentData != null) { StudentQuestionVM studentQuestion = new StudentQuestionVM() { Id = question.Id, Dislikes = question.Dislikes, Likes = question.Likes, QuestionHead = question.QuestionHead, Username = question.User.Name, Image = studentData.Image, UserId = question.UserId, Title = studentData.Title, Date = question.Date, Gender = studentData.User.Gender }; //List<QuestionAnswerVM> questionAnswersList = new List<QuestionAnswerVM>(); //foreach (var answer in question.Answers) //{ // var answerdStudentData = GetStudent(question.UserId); // QuestionAnswerVM Answer = new QuestionAnswerVM() // { // QuestionAnswer = answer.QuestionAnswer, // Id = answer.Id, // UserId = answer.UserId, // Username = answer.User.Name, // UserImage = answerdStudentData.Image, // Title = answerdStudentData.Title, // Date = answer.Date, // Gender = answerdStudentData.User.Gender // }; // questionAnswersList.Add(Answer); //}//End Answers ForLoop //studentQuestion.Answers = questionAnswersList; questionsList.Add(studentQuestion); } //End Student Questions return(questionsList); } return(questions); }
public IEnumerable <StudentQuestionVM> FollowingQuestions(string userId) { //Get All Following UserId var Friends = _friendRepo.GetAll().Include(u => u.FriendTwo).ToList().Select(u => u.FriendTwo.Id).ToList(); //Get Questions With Answers Of These Users var allFollowingQuestions = _questionRepo.GetAll().Include(a => a.Answers).Include(u => u.User) .ThenInclude(u => u.Student).Where(q => Friends.Contains(q.UserId)); List <StudentQuestionVM> questionsList = new List <StudentQuestionVM>(); foreach (var question in allFollowingQuestions) { var studentData = GetStudent(question.UserId); StudentQuestionVM studentQuestion = new StudentQuestionVM() { Id = question.Id, Dislikes = question.Dislikes, Likes = question.Likes, QuestionHead = question.QuestionHead, Username = question.User.Name, Image = studentData.Image, UserId = question.UserId, Title = studentData.Title, Gender = studentData.User.Gender, Date = Convert.ToDateTime(question.Date.ToString("yyyy-MM-dd")) }; List <QuestionAnswerVM> questionAnswersList = new List <QuestionAnswerVM>(); foreach (var answer in question.Answers) { var answeredStudentData = GetStudent(answer.UserId); QuestionAnswerVM Answer = new QuestionAnswerVM() { QuestionAnswer = answer.QuestionAnswer, Id = answer.Id, UserId = answer.UserId, Username = answer.User.Name, UserImage = answeredStudentData.Image, Title = studentData.Title, Date = Convert.ToDateTime(question.Date.ToString("yyyy-MM-dd")), Gender = answer.User.Gender }; questionAnswersList.Add(Answer); }//End Answers ForLoop studentQuestion.Answers = questionAnswersList; questionsList.Add(studentQuestion); }//End Questions ForLoop return(questionsList); }
public IEnumerable <StudentQuestionVM> FollowingQuestions(string userId) { //Get All Following UserId var Friends = _friendRepo.GetAll().Include(u => u.FriendTwo).ToList().Select(u => u.FriendTwo.Id).ToList(); //Get Questions With Answers Of These Users var allFollowingQuestions = _questionRepo.GetAll().Include(a => a.Answers).Include(u => u.User).ThenInclude(u => u.Student).Where(q => Friends.Contains(q.UserId)); List <StudentQuestionVM> questionsList = new List <StudentQuestionVM>(); foreach (var question in allFollowingQuestions) { StudentQuestionVM studentQuestion = new StudentQuestionVM() { Id = question.Id, Dislikes = question.Dislikes, Likes = question.Likes, QuestionHead = question.QuestionHead, Username = question.User.Name, //Image = question.User.Student.Image, UserId = question.UserId }; List <QuestionAnswerVM> questionAnswersList = new List <QuestionAnswerVM>(); foreach (var answer in question.Answers) { QuestionAnswerVM Answer = new QuestionAnswerVM() { Answer = answer.QuestionAnswer, Id = answer.Id, UserId = answer.UserId, Username = answer.User.Name, //UserImage = answer.User.Student.Image }; questionAnswersList.Add(Answer); }//End Answers ForLoop studentQuestion.Answers = questionAnswersList; questionsList.Add(studentQuestion); }//End Questions ForLoop return(questionsList); }
StudentProfileVM GetStudentFullProfile(string userId) { //Student Info var studentInfo = _repoStud.GetAll().Include(u => u.User).SingleOrDefault(u => u.ApplicationUserId == userId); StudentProfileVM studentProfile = new StudentProfileVM() { ProfileId = studentInfo.Id, BirthDate = studentInfo.User.BirthDate, Email = studentInfo.User.Email, FirstVisit = studentInfo.FirstVisit, Info = studentInfo.Info, Username = studentInfo.User.Name, Gender = studentInfo.User.Gender, Image = studentInfo.Image, University = studentInfo.Universty, UniverstyYearFrom = studentInfo.UniverstyYearFrom, UniverstyYearTo = studentInfo.UniverstyYearTo, SchholYearFrom = studentInfo.SchholYearFrom, SchholYearTo = studentInfo.SchholYearTo, UserId = studentInfo.ApplicationUserId, School = studentInfo.School, Title = studentInfo.Title }; //Student Skills var allSkills = GetStudentSkills(userId); List <StudentSkillVM> skillsList = new List <StudentSkillVM>(); foreach (var skill in allSkills) { StudentSkillVM studentSkill = new StudentSkillVM() { Id = skill.Id, SkillName = skill.Skill.Name }; skillsList.Add(studentSkill); } studentProfile.Skills = skillsList; //End Student Skills //Student Exams var allExams = GetStudentExams(userId); List <StudentExamVM> examsList = new List <StudentExamVM>(); foreach (var exam in allExams) { StudentExamVM studentExam = new StudentExamVM() { ExamName = exam.Exam.Title, StudentDegree = exam.Degree }; examsList.Add(studentExam); } studentProfile.Exams = examsList; //End Student Exams //Student Courses var allCourses = GetStudentCourses(userId); List <StudentCourseVM> coursesList = new List <StudentCourseVM>(); foreach (var course in allCourses) { StudentCourseVM studentCourse = new StudentCourseVM() { CourseName = course.Course.Name, Info = course.Course.Info }; coursesList.Add(studentCourse); } studentProfile.Courses = coursesList; //End Student Courses //Student Firneds var allFriends = GetStudentFriends(userId); List <StudentFollowingVM> finedsList = new List <StudentFollowingVM>(); foreach (var frined in allFriends) { var friendData = GetStudent(frined.FriendTwoId); if (friendData != null) { StudentFollowingVM studentFriend = new StudentFollowingVM() { Id = frined.Id, Name = frined.FriendTwo.Name, FriendId = frined.FriendTwo.Id, Title = friendData.Title, FriendImage = friendData.Image, Gender = friendData.User.Gender }; finedsList.Add(studentFriend); } } studentProfile.Friends = finedsList; //End Student Firneds //Student Questions var allQuestions = GetStudentQuestions(userId); List <StudentQuestionVM> questionsList = new List <StudentQuestionVM>(); foreach (var question in allQuestions) { var studentData = GetStudent(question.UserId); if (studentData != null) { StudentQuestionVM studentQuestion = new StudentQuestionVM() { Id = question.Id, Dislikes = question.Dislikes, Likes = question.Likes, QuestionHead = question.QuestionHead, Username = question.User.Name, Image = studentData.Image, UserId = question.UserId }; List <QuestionAnswerVM> questionAnswersList = new List <QuestionAnswerVM>(); foreach (var answer in question.Answers) { QuestionAnswerVM Answer = new QuestionAnswerVM() { Answer = answer.QuestionAnswer, Id = answer.Id, UserId = answer.UserId, Username = answer.User.Name, //UserImage = answer.User.Student.Image }; questionAnswersList.Add(Answer); }//End Answers ForLoop studentQuestion.Answers = questionAnswersList; questionsList.Add(studentQuestion); } }//End Questions ForLoop studentProfile.Questions = questionsList; //End Student Questions return(studentProfile); }//End Get Profile