Exemplo n.º 1
0
        // GET: Course
        public ActionResult JoinACourse(string courseCode)
        {
            CourseGetResponse cgr = _courseCom.GetCourse(courseCode).Result;
            DisplayCourseModel dcm = new DisplayCourseModel();
            if (cgr != null)
            {
                dcm.CourseCode = cgr.CourseCode;
                dcm.CourseDescription = cgr.CourseDescription;
                dcm.CourseName = cgr.CourseName;
                dcm.DesiredSkillSets = cgr.DesiredSkillSets;
                dcm.GroupSize = (int)cgr.GroupSize;
                dcm.GroupType = cgr.GroupType;
                dcm.PreferSimiliarSkillSet = (bool)cgr.PreferSimiliarSkillSet;
                dcm.Users = new List<Models.DisplayCourseUser>();
                dcm.Questions = new List<Models.DsiplayQuestion>();
            }
            foreach (var user in cgr.UserList)
            {
                dcm.Users.Add(new DisplayCourseUser()
                {
                    emailId = user.EmailID,
                    name = user.Name,
                    role = user.RoleCode
                });
            }

            QuestionnaireGetResponse qgr = _questionnaireCom.GetQuestionnaire(cgr.QuestionnaireCode).Result;

            if (qgr != null)
            {
                foreach (var q in qgr.Questions)
                {
                    dcm.Questions.Add(new Models.DsiplayQuestion()
                    {
                        QuestionText = q.questionText,
                        QuestionType = q.questionType,
                        AnswerChoices = q.answerChoices
                    });
                }
            }
            return View(dcm);
        }
Exemplo n.º 2
0
 public async Task<ActionResult> JoinACourse(DisplayCourseModel Model)
 {
     if(ModelState.IsValid)
     {
         StringBuilder answerSet = new StringBuilder();
         foreach(var question in Model.Questions)
         {
             if(!string.IsNullOrWhiteSpace(question.selectedAnswer))
             {
                 answerSet.Append(question.selectedAnswer + ",");
             } 
         }
         answerSet.Remove(answerSet.Length - 1, 1);
         CourseUserUpdateRequest cuur = new CourseUserUpdateRequest()
         {
             email = MvcApplication.userEmail,
             courseCode = Model.CourseCode,
             RoleCode = "Student",
             answerSet = answerSet.ToString()
         };
         bool result = _courseUserCom.UpdateCourseUser(cuur).Result;
         if(result)
         {
             MvcApplication.courses.Add(Model.CourseCode, Model.CourseName);
             MvcApplication.courseDescription.Add(Model.CourseCode, Model.CourseDescription);
             return RedirectToAction("Student", "Course");
         }
         else
         {
             ModelState.AddModelError("", "Oops! Something wrong happened! Please try again.");
             return View(Model);
         }
     }
     ModelState.AddModelError("", "Oops! Something wrong happened! Please try again.");
     return View(Model);
 }