Пример #1
0
        /// <summary>
        /// 32个字符组成一组随机数组
        /// </summary>
        public string generateToken()
        {
            //用三组字符串进行md5加密

            string randchar = RandomStringBuilder.Create(32);


            return(randchar);
        }
Пример #2
0
        public async Task <IActionResult> Post(string id, [FromBody] JsonElement value)
        {
            string       str          = JsonSerializer.Serialize(value);
            JsonResponse jsonResponse = null;

            try
            {
                jsonResponse = JsonSerializer.Deserialize <JsonResponse>(str);
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
            if (jsonResponse == null)
            {
                return(BadRequest());
            }
            else if (id != jsonResponse.id)
            {
                return(NotFound());
            }
            var survey = await _context.Survey.FindAsync(id);

            if (survey == null)
            {
                return(NotFound());
            }

            Response response = new Response();
            int      index    = 0;

            response.ResponseID  = RandomStringBuilder.Create();
            response.IMEI        = jsonResponse.IMEI;
            response.Latitude    = jsonResponse.Latitude;
            response.Longitude   = jsonResponse.Longitude;
            response.RefSurveyID = jsonResponse.id;
            response.Survey      = survey;
            response.TimeStamp   = jsonResponse.time;
            foreach (string answerStr in jsonResponse.answers)
            {
                Answer answer = new Answer();
                answer.Response      = response;
                answer.RefResponseID = response.ResponseID;
                answer.QuestionNum   = index;
                answer.Content       = answerStr;
                answer.AnswerKey     = RandomStringBuilder.Create();
                _context.Add(answer);
                ++index;
            }

            _context.Add(response);
            await _context.SaveChangesAsync();

            return(Ok());
        }
        // GET: Questions/Create
        public IActionResult Create(string id)
        {
            var result = _context.Question.Include(q => q.Survey).Where(m => m.RefSurveyID == id);

            if (result == null)
            {
                return(View());
            }
            int max = 0;

            foreach (Question question in result)
            {
                if (question.QuestionNum > max)
                {
                    max = question.QuestionNum;
                }
            }

            ViewData["QuestionNum"] = max + 1;
            ViewData["QuestionKey"] = RandomStringBuilder.Create();
            ViewData["RefSurveyID"] = id;
            return(View());
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("AppId,AppName,UserNameID,AlgorithmRefId,APIKey,CreateTime,LastCallTime,MonthCallCount,State,AIFunction")] App app)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(app.AppName))
                {
                    return(NotFound());
                }
                if (app.Algorithm != null || !string.IsNullOrEmpty(app.AlgorithmRefId))
                {
                    app.AIFunction = AIFunction.Custom;
                }
                string userID = _context.Users.First(u => u.UserName == User.Identity.Name).Id;
                app.UserNameID     = userID;
                app.CreateTime     = DateTime.Now;
                app.LastCallTime   = DateTime.Now;
                app.MonthCallCount = 0;
                app.State          = true;
                string rand;
                for (rand = RandomStringBuilder.Create(36); _context.App.Any(a => a.APIKey == RandomStringBuilder.Create(36));)
                {
                    rand = RandomStringBuilder.Create(36);
                }
                app.APIKey = rand;
                _context.Add(app);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AlgorithmId"] = app.AlgorithmRefId;
            var algorithm = await _context.Algorithm
                            .FirstOrDefaultAsync(m => m.AlgorithmId == app.AlgorithmRefId);

            ViewData["AlgorithmName"]  = algorithm.AlgorithmName;
            ViewData["AlgorithmRefId"] = new SelectList(_context.Algorithm.Where(a => a.AlgorithmId == algorithm.AlgorithmId), "AlgorithmId", "AlgorithmId");
            return(View(app));
        }
Пример #5
0
        /// <summary>
        /// 生成 ASE的密钥 16位
        /// </summary>
        private void GenerateAESKey()
        {
            string randomStr = RandomStringBuilder.Create(16).ToLower();

            outFileConfig.tsAESKey = Encoding.UTF8.GetBytes(randomStr);
        }
        // GET: Surveys/Create
        public IActionResult Create()
        {
            ViewData["SurveyID"] = RandomStringBuilder.Create();

            return(View());
        }