Ejemplo n.º 1
0
        public async Task<ActionResult> Create(CreateCourseModel model)
        {
            if (ModelState.IsValid)
            {
                CourseAddRequest car = new CourseAddRequest()
                {
                    CourseCode = model.CourseCode,
                    CourseName = model.CourseName,
                    DesiredSkillSets = model.DesiredSkillSets,
                    GroupSize = model.GroupSize,
                    CourseDescription = model.CourseDescription,
                    PreferSimiliarSkillSet = model.PreferSimiliarSkillSet,
                    userList = new List<CourseNewUser>()
                };
                switch(model.GroupType)
                {
                    case "Study Group":
                        car.GroupType = "Study";
                        break;
                    case "Project Group (Open Projects)":
                        car.GroupType = "OpenProject";
                        break;
                    case "Project Group (Closed Projects)":
                        car.GroupType = "ClosedProject";
                        break;
                }

                if(model.Users != null && model.Users.Count > 0)
                {
                    foreach(var user in model.Users)
                    {
                        car.userList.Add(new CourseNewUser()
                        {
                            emailId = user.emailId,
                            roleCode = user.role.ToString()
                        });
                    }
                }
                
                bool result = _courseCom.AddCourse(car).Result;
                if (result) //Course is added, now generate intelligent question set and add questionnaire
                {
                    QuestionnaireAddRequest qar = new QuestionnaireAddRequest()
                    {
                         IsATemplate = false,
                         QuestionnaireCode = DateTime.UtcNow.ToString("MMddyyHmmss"),
                         Questions = new List<DomainDto.Question>()
                    };
                    List<string> timeZones = TimeZoneInfo.GetSystemTimeZones().Select(x => x.DisplayName).ToList();
                    qar.Questions.Add(new DomainDto.Question()
                    {
                         questionText = "In what timezone are you mostly available?",
                         questionType = "MultipleChoice",
                         answerChoices = timeZones
                    });
                    List<string> timeSlots = new List<string>()
                    {
                        "6:00 AM - 9:00 AM",
                        "9:00 AM - 12:00 PM",
                        "12:00 PM - 3:00 PM",
                        "3:00 PM - 6:00 PM",
                        "6:00 PM - 9:00 PM",
                        "9:00 PM - 12:00 AM",
                        "Anytime",
                        "I am not available"

                    };
                    qar.Questions.Add(new DomainDto.Question()
                    {
                        questionText = "During weekday, what time are you available for group calls?",
                        questionType = "MultipleChoice",
                        answerChoices = timeSlots
                    });
                    qar.Questions.Add(new DomainDto.Question()
                    {
                        questionText = "During weekends, what time are you available for group calls?",
                        questionType = "MultipleChoice",
                        answerChoices = timeSlots
                    });

                    if(model.GenerateIntelligentQuestionnaire)
                    {
                        if(model.DesiredSkillSets != null)
                        {
                            foreach(var skl in model.DesiredSkillSets.Split(','))
                            {
                                qar.Questions.Add(new DomainDto.Question()
                                    {
                                        questionText = "What is your expertise in " + skl,
                                        questionType = "MultipleChoice",
                                        answerChoices = new List<string>() { "Beginner", "Intermediate", "Expert"}
                                    });
                            }
                        }
                    }

                    if(model.Questions != null && model.Questions.Count > 0)
                    {
                        foreach(var q in model.Questions)
                        {
                            qar.Questions.Add(new DomainDto.Question()
                                {
                                    questionType = q.QuestionType,
                                    questionText  = q.QuestionText,
                                    answerChoices = q.AnswerChoices.Split(',').ToList()
                                });
                        }
                    }
                    bool res = _questionnaireCom.AddQuestionnaire(qar).Result;
                    if(res)//Questionnaire is added, update course with questionnaire
                    {
                        CourseUpdateRequest cur = new CourseUpdateRequest()
                        {
                            CourseCode = model.CourseCode,
                            QuestionnaireCode = qar.QuestionnaireCode
                        };
                        bool resp = _courseCom.UpdateCourse(cur).Result;
                        if(!resp)
                        {
                            ModelState.AddModelError("", "Oops! Course was added, but someting wrong happened while adding questionnaire to course");
                            return View(model);
                        }
                    }
                    MvcApplication.courses.Add(model.CourseCode, model.CourseName);
                    MvcApplication.courseDescription.Add(model.CourseCode, model.CourseDescription);
                    return RedirectToAction("Teacher", "Course");
                }
            }
            ModelState.AddModelError("", "Oops! Something wrong happened! Please try again.");
            return View(model);
        }
Ejemplo n.º 2
0
 public ActionResult Create()
 {
     ViewBag.User = MvcApplication.userName;
     CreateCourseModel ccm = new CreateCourseModel();
     ccm.Users = new List<Models.CourseUser>() { new Models.CourseUser() { emailId = MvcApplication.userEmail, role = Models.Role.Teacher } };
     //ccm.DesiredSkillSets = new List<Skill>();
     ccm.Questions = new List<Models.Question>();
     return View(ccm);
 }