public DomainModelResponse Add(QuestionnaireAddRequest request)
        {
            Questionnaire Questionnaire = new Questionnaire();
            Questionnaire.QuestionnaireCode = request.QuestionnaireCode;
            Questionnaire.IsATemplate = request.IsATemplate;
            Questionnaire.LastChangedTime = DateTime.UtcNow;
            StringBuilder qIds = new StringBuilder();
            if(request.QuestionIds != null)
            {
                foreach(int i in request.QuestionIds)
                {
                    qIds.Append(i.ToString());
                    qIds.Append(",");
                }
                qIds.Remove(qIds.Length - 1, 1);
            }
            if(request.Questions != null)
            {
                List<QuestionType> questionTypes = _repQuestionType.Get().ToList();
                foreach(var q in request.Questions)
                {
                    EntityModel.Question eQ = new EntityModel.Question()
                    {
                        QuestionText = q.questionText,
                        LastChangedTime = DateTime.UtcNow,
                        QuestionType = questionTypes.Where(x => x.Type.Equals(q.questionType, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(),
                        QuestionTypeId = questionTypes.Where(x => x.Type.Equals(q.questionType, StringComparison.OrdinalIgnoreCase)).FirstOrDefault().QuestionTypeId,

                    };
                    _repQuestion.Add(eQ);
                    _uow.Commit();
                    eQ = _repQuestion.Get(filter: f => f.QuestionText == q.questionText).FirstOrDefault();
                    qIds.Append(eQ.QuestionId.ToString());
                    qIds.Append(",");
                    foreach(var ans in q.answerChoices)
                    {
                        AnswerChoice ac = new AnswerChoice()
                        {
                            Answer = ans,
                            Question = eQ,
                            QuestionId = eQ.QuestionId
                        };
                        _repAnswerChoice.Add(ac);
                    }
                }
                qIds.Remove(qIds.Length - 1, 1);
            }
            Questionnaire.QuestionSet = qIds.ToString();
            _repQuestionnaire.Add(Questionnaire);
            _uow.Commit();
            _questionnaireResponse.addResponse("Add", MessageCodes.InfoCreatedSuccessfully, "questionnaire : " + request.QuestionnaireCode);
            return _questionnaireResponse;
        }
 public async Task<bool> AddQuestionnaire(QuestionnaireAddRequest request)
 {
     try
     {
         HttpResponseMessage httpResp = apiCom.executePostAPI("Questionnaire", JsonConvert.SerializeObject(request));
         if (httpResp.IsSuccessStatusCode)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     catch
     {
         return false;
     }
 }
예제 #3
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);
        }