public ActionResult ProfessorAnswers(Guid id) { String firstName, lastName, fullName; this.GenerateProfessor(); SetData(); Answers = interaction.GetAnswersByQuestionId(id); ownersName = new List <string>(); answerContent = new List <string>(); List <Guid> answerIds = new List <Guid>(); bool inRoom; int bestAnswerPosition = -1; for (int i = 0; i < Answers.Count; i++) { if (Answers[i].FavouriteAnswerFlag == true) { bestAnswerPosition = i; } answerIds.Add(Answers[i].Id); answerContent.Add(Answers[i].Content); if (Answers[i].Type.Equals("professor")) { firstName = people.GetProfesor(Answers[i].OwnerId).FirstName; lastName = people.GetProfesor(Answers[i].OwnerId).LastName; } else { firstName = people.GetStudent(Answers[i].OwnerId).FirstName; lastName = people.GetStudent(Answers[i].OwnerId).LastName; } fullName = firstName + " " + lastName; ownersName.Add(fullName); } String idQuestion = id.ToString(); HttpContext.Session.SetString("questionId", idQuestion); if (HttpContext.Session.GetString("inRoom") == "true") { inRoom = true; } else { inRoom = false; } return(Json(new { type = "null", Authors = ownersName, Answers = answerContent, answersIds = answerIds, NumberOfAnswers = ownersName.Count, QuestionId = id, inRoom = inRoom, bestAnswerPosition = bestAnswerPosition })); }
static void Main(string[] args) { var MyUnitOfWork = new UnitOfWork(); var student1 = new Student("Alex", "Stoica"); var student2 = new Student("Tudor", "Melnic"); var profesor = new Profesor(); var course = new Course("Dotnet", profesor.Id); var course2 = new Course("CLIW", profesor.Id); profesor.Update("Valeriu", "Mardare", course.Id); var room = new Room(course.Id, profesor.Id); var room2 = new Room(course.Id, profesor.Id); course.SetGeneralRoomId(room); var question1 = new Question(student1.Id, room.Id, "student", "Se da cursul asta in sesiune?"); var question2 = new Question(student2.Id, room.Id, "student", "Putem pleca?"); var question3 = new Question(student2.Id, room.Id, "student", "Cum rezolvam?"); var question4 = new Question(student2.Id, room2.Id, "student", "Se face seminarul maine?"); var question5 = new Question(student2.Id, room2.Id, "student", "Are cineva modele de examen?"); var answer1 = new Answer(profesor.Id, question1.Id, "Nu", "professor"); var answer2 = new Answer(profesor.Id, question2.Id, "Nu stiu", "professor"); var answer3 = new Answer(profesor.Id, question2.Id, "Merge", "professor"); MyUnitOfWork.StudentRepository.Add(student1); MyUnitOfWork.StudentRepository.Add(student2); MyUnitOfWork.ProfesorRepository.Add(profesor); MyUnitOfWork.CourseRepository.Add(course); MyUnitOfWork.CourseRepository.Add(course2); MyUnitOfWork.RoomRepository.Add(room); MyUnitOfWork.RoomRepository.Add(room2); MyUnitOfWork.QuestionRepository.Add(question1); MyUnitOfWork.QuestionRepository.Add(question2); MyUnitOfWork.QuestionRepository.Add(question3); MyUnitOfWork.QuestionRepository.Add(question4); MyUnitOfWork.QuestionRepository.Add(question5); MyUnitOfWork.AnswerRepository.Add(answer1); MyUnitOfWork.AnswerRepository.Add(answer2); MyUnitOfWork.AnswerRepository.Add(answer3); var relationship1 = new StudentCourseRelationship(student1.Id, course.Id); var relationship2 = new StudentCourseRelationship(student2.Id, course.Id); var relationship3 = new StudentCourseRelationship(student2.Id, course2.Id); var StudRoomRel1 = new StudentRoomRelationship(student1.Id, room.Id); var StudRoomRel2 = new StudentRoomRelationship(student2.Id, room.Id); var StudRoomRel11 = new StudentRoomRelationship(student1.Id, room.Id); MyUnitOfWork.StudentCourseRelationshipRepository.Add(relationship1); MyUnitOfWork.StudentCourseRelationshipRepository.Add(relationship2); MyUnitOfWork.StudentCourseRelationshipRepository.Add(relationship3); MyUnitOfWork.StudentRoomRelationshipRepository.Add(StudRoomRel1); MyUnitOfWork.StudentRoomRelationshipRepository.Add(StudRoomRel2); MyUnitOfWork.StudentRoomRelationshipRepository.Add(StudRoomRel11); MyUnitOfWork.Commit(); var peopleModel = new PeopleModel(); var coursesModel = new CoursesModel(); var interactionModel = new InteractionModel(); //System.Console.Write(peopleModel.GetStudent(student1.Id).FirstName); //System.Console.Write(peopleModel.GetProfesor(profesor.Id).FirstName); foreach (Student student in coursesModel.GetStudentsByCourse(course.Id)) { System.Console.WriteLine("Student la CourseId " + student.FirstName); } foreach (Answer answer in interactionModel.GetAnswersByQuestionId(question2.Id)) { System.Console.WriteLine(answer.Id); } foreach (Student student in coursesModel.GetStudentsByRoomId(room.Id)) { System.Console.WriteLine("Student la RoomId " + student.FirstName); } System.Console.Read(); }
public ActionResult StudentAnswers(Guid id) { String firstName, lastName, fullName; this.GenerateStudent(); SetData(); Question question = interaction.GetQuestion(id); Answers = interaction.GetAnswersByQuestionId(id); ownersName = new List <string>(); answerContent = new List <string>(); Room room = courses.GetRoom(Guid.Parse(HttpContext.Session.GetString("roomIdStudent"))); bool favoriteAnswerFlag = false; bool timeExpired = false; int favoriteAnswerPosition = 0; for (int i = 0; i < Answers.Count; i++) { if (Answers[i].FavouriteAnswerFlag == true) { favoriteAnswerFlag = true; favoriteAnswerPosition = i; } answerContent.Add(Answers[i].Content); if (Answers[i].Type.Equals("professor")) { firstName = people.GetProfesor(Answers[i].OwnerId).FirstName; lastName = people.GetProfesor(Answers[i].OwnerId).LastName; } else { firstName = people.GetStudent(Answers[i].OwnerId).FirstName; lastName = people.GetStudent(Answers[i].OwnerId).LastName; } fullName = firstName + " " + lastName; ownersName.Add(fullName); } String idQuestion = id.ToString(); HttpContext.Session.SetString("questionIdStudent", idQuestion); if (question.Start <= DateTime.Now && question.Stop >= DateTime.Now) { timeExpired = false; } else { timeExpired = true; } return(Json(new { type = "null", Authors = ownersName, Answers = answerContent, NumberOfAnswers = ownersName.Count, QuestionId = id, isInRoom = HttpContext.Session.GetString("IsInRoom"), roomOpen = room.Open, favoriteAnswerFlag = favoriteAnswerFlag, favoriteAnswerPosition = favoriteAnswerPosition, timeExpired = timeExpired, endDate = question.Stop.ToString() })); }