Esempio n. 1
0
        public async Task <IActionResult> AnonymousLogin(string surveyCode)
        {
            if (!IsSurveyAnonymous(surveyCode))
            {
                return(Unauthorized());
            }
            var identifier = HashIdentifier(Guid.NewGuid().ToString());
            var survey     = await this._unitOfWork.Surveys.GetSurveyByCodeAsync(surveyCode);

            if (survey == null)
            {
                return(new NotFoundResult());
            }
            Shortcode shortcode = new Shortcode()
            {
                Survey      = survey,
                Code        = identifier,
                IsTest      = false,
                CreatedDate = DateTime.UtcNow
            };

            await this._unitOfWork.Shortcodes.AddAsync(shortcode);

            await this._unitOfWork.SaveChangesAsync();

            return(Redirect($"/survey/{surveyCode}/start/{HttpUtility.UrlEncode(shortcode.Code)}"));
        }
Esempio n. 2
0
 CreateSurveyUser(Survey survey, Shortcode shortcode, ClaimsPrincipal currentUser)
 {
     var user = new UserViewModel {
         UserName = Guid.NewGuid().ToString("D")
     };
     SurveyUser appUser = Mapper.Map <SurveyUser> (user);
     var        result  = await _accountManager.CreateSurveyUserAsync(appUser, shortcode, null,
                                                                      new (string claimName, string claimValue) [] {
Esempio n. 3
0
        /// <summary>
        /// Replaces the shortcodes of the specified <paramref name="formula"/> with the values
        /// of the specified root <paramref name="instance"/>
        /// </summary>
        /// <param name="formula">The formula</param>
        /// <param name="instance">The root instance</param>
        /// <returns></returns>
        public string ReplaceFormula(string formula, object instance)
        {
            // Get the shortcodes
            var shortcodes = PropertyShortcodes.Value;

            // Set the instance
            shortcodes.ForEach(x => x.Instance = instance);

            formula = Shortcode.ReplaceShortcodes(formula, shortcodes);

            // Clear the instance
            shortcodes.ForEach(x => x.Instance = null);

            // Return the formula
            return(formula);
        }
Esempio n. 4
0
        /// <summary>
        /// Generates a batch of short codes for a survey
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="survey"></param>
        public void GenerateShortCodesBatch(CodeGeneration parameters, Survey survey)
        {
            List <string> newCodes = GenerateUniqueCodes(parameters, survey);

            for (int i = 0; i < parameters.NumberOfCodes; i++)
            {
                Shortcode newCode = new Shortcode()
                {
                    Survey      = survey,
                    Code        = newCodes[i],
                    IsTest      = parameters.IsTest,
                    CreatedDate = DateTime.UtcNow
                };
                _unitOfWork.Shortcodes.Add(newCode);
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Login(string surveyCode)
        {
            var    headers     = Request.HttpContext.Request.Headers;
            var    identifiers = headers[this.AuthenticationAttribute];
            string identifier  = "";

            if (identifiers.Count == 0 || string.IsNullOrEmpty(identifiers[0].Trim()) || IsSurveyAnonymous(surveyCode))
            {
                identifier = Guid.NewGuid().ToString();
            }
            else
            {
                identifier = identifiers[0];
            }
            identifier = HashIdentifier(identifier);

            var survey = await this._unitOfWork.Surveys.GetSurveyByCodeAsync(surveyCode);

            if (survey == null)
            {
                return(new NotFoundResult());
            }
            Shortcode shortcode = await this._unitOfWork.Shortcodes.GetShortcodeForSurveyAsync(survey, identifier);

            if (shortcode == null)
            {
                shortcode = new Shortcode()
                {
                    Survey      = survey,
                    Code        = identifier,
                    IsTest      = false,
                    CreatedDate = DateTime.UtcNow
                };

                await this._unitOfWork.Shortcodes.AddAsync(shortcode);

                await this._unitOfWork.SaveChangesAsync();
            }

            return(Redirect($"/survey/{surveyCode}/start/{HttpUtility.UrlEncode(shortcode.Code)}"));
        }
Esempio n. 6
0
        /// <summary>
        /// Generates single code for a survey
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="survey"></param>
        public async Task <Shortcode> GenerateShortCode(CodeGeneration parameters, Survey survey)
        {
            string codeString;

            if (parameters.UsePattern)
            {
                codeString = GenerateCodeByPattern(parameters.SurveyId, parameters.Pattern);
            }
            else
            {
                codeString = GenerateCodeByLength(parameters.SurveyId, parameters.CodeLength);
            }

            Shortcode newCode = new Shortcode()
            {
                Survey      = survey,
                Code        = codeString,
                IsTest      = parameters.IsTest,
                CreatedDate = DateTime.UtcNow
            };
            await _unitOfWork.Shortcodes.AddAsync(newCode);

            return(newCode);
        }
Esempio n. 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="user"></param>
 /// <param name="shortcodeRef"></param>
 /// <param name="shortcode"></param>
 /// <param name="claimName"></param>
 /// <param name="claimValue"></param>
 /// <returns></returns>
 public async Task <Tuple <bool, string[], SurveyUser> > CreateSurveyUserAsync(SurveyUser user,
                                                                               Shortcode shortcodeRef,
                                                                               string shortcodes, (string claimName, string claimValue)[] claims)