public QuestionsSurvey StartSurvey(int userId, int surveyId, JoiningPlatform platform) { // Get the user survey record if exists. var userSurvey = _surveyRepository.GetUserSurvey(userId, surveyId); if (userSurvey == null) { userSurvey = new UserSurvey { UserId = userId, SurveyId = surveyId, StartedOn = DateTime.UtcNow, PageCompleted = 0, JoiningPlatform = (int)platform }; _surveyRepository.AddUserSurvey(userSurvey); _unitOfWork.Commit(); } var data = new QuestionsSurvey(); data.PageNum = userSurvey.PageCompleted + 1; data.Questions = _surveyQuestionRepository.GetSurveyQuestions(surveyId, userId); return(data); }
public ActionResult StartSurvey() { User loggedInUser = _securityService.GetAuthenticatedUser(); var survey = _surveyService.GetDefaultSurvey(); if (survey == null) { throw new NotFoundException(); } JoiningPlatform platform = Request.Headers["User-Agent"].Contains("Mobile") ? JoiningPlatform.Mobile : JoiningPlatform.Desktop; QuestionsSurvey surveyData = _surveyService.StartSurvey(loggedInUser.Id, survey.Id, platform); GetSurveyDTO surveyDTO = _mapper.Map <GetSurveyDTO>(surveyData); return(Ok(surveyDTO)); }