public async Task <QuestionValue> GetQuestionValueById(int id) { string sp = StoreProcedures["GetQuestionValueById"]; DynamicParameters parameters = new DynamicParameters(); try { parameters.Add("fid", id, DbType.Int32); var result_query = await _connection.QueryAsync(sp, parameters, commandType : CommandType.StoredProcedure); QuestionValue result = null; if (result_query != null && result_query.Any()) { result = Mapper.QuestionValue.Map(result_query.FirstOrDefault()); } return(result); } catch (Npgsql.PostgresException ex) { throw new Npgsql.NpgsqlException($"Error with database code: {ex.SqlState} msg: {ex.MessageText}"); } catch (System.Net.Sockets.SocketException ex) { throw; } catch (Exception ex) { throw; } }
public async Task <ActionResult <int> > PutQuestionValue([FromBody] QuestionValue questionValue) { try { if (questionValue == null || questionValue.ID <= 0 || string.IsNullOrEmpty(questionValue.Name)) { return(BadRequest()); } var result = await _consultingService.UpdateQuestionValue(questionValue); if (result <= 0) { return(NotFound()); } return(Ok(result)); } catch (Npgsql.PostgresException ex) { return(StatusCode((int)HttpStatusCode.ServiceUnavailable, $"Error with database code: {ex.SqlState}")); } catch (System.Net.Sockets.SocketException ex) { return(StatusCode((int)HttpStatusCode.ServiceUnavailable, $"Error with database. {ex.Message}")); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
private void SetValue(QuestionValue questionValue, string name, ZValue value) { switch (name.ToLower()) { //case "response": case "choice": // $$pb modif le 03/05/2017 //((QuestionValueResponse)questionValue).Response = (string)value; ((QuestionValueResponse)questionValue).Response = ((string)value).Trim(); break; default: throw new PBFileException($"unknow value \"{name}\" = {value} line {_lineNumber} file \"{_filename}\"", _file, _lineNumber); } }
public async Task <int> UpdateQuestionValue(QuestionValue questionValue) { string sp = StoreProcedures["UpdateQuestionValue"]; DynamicParameters parameters = new DynamicParameters(); try { parameters.Add("fid", questionValue.ID, DbType.Int32); parameters.Add("fquestionid", questionValue.QuestionID, DbType.Int32); parameters.Add("fname", questionValue.Name, DbType.String); parameters.Add("fdescription", questionValue.Description, DbType.String); parameters.Add("fvalue", questionValue.Value, DbType.Int32); var result_query = await _connection.QueryAsync(sp, parameters, commandType : CommandType.StoredProcedure); int result = 0; if (result_query != null && result_query.Any()) { result = Mapper.Primitive <int> .Map(result_query.FirstOrDefault()); } return(result); } catch (Npgsql.PostgresException ex) { throw new Npgsql.NpgsqlException($"Error with database code: {ex.SqlState} msg: {ex.MessageText}"); } catch (System.Net.Sockets.SocketException ex) { throw; } catch (Exception ex) { throw; } }
private QuestionValue GetQuestionValue(NamedValues <ZValue> namedValues) { if (namedValues.Count == 0) { throw new PBFileException($"wrong question value line {_lineNumber} file \"{_filename}\"", _file, _lineNumber); } //KeyValuePair<string, ZValue> firstValue = namedValues.First(); //QuestionValue questionValue = GetValue(firstValue.Key, firstValue.Value); QuestionValue questionValue = null; foreach (KeyValuePair <string, ZValue> namedValue in namedValues) { if (questionValue == null) { questionValue = GetValue(namedValue.Key, namedValue.Value); } else { SetValue(questionValue, namedValue.Key, namedValue.Value); } } return(questionValue); }
public IEnumerable <Question> Read(IEnumerable <string> files, string baseDirectory = null) { //Trace.WriteLine("read questions files"); if (_maxLinesPerQuestion == -1) { throw new PBException("undefined MaxLinesPerQuestion"); } if (_maxLinesPerChoice == -1) { throw new PBException("undefined MaxLinesPerResponse"); } _baseDirectory = baseDirectory; foreach (string file in files) { _file = file; _filename = zPath.GetFileName(_file); //_year = null; //_questionType = QuestionType.None; _lastValueType = QuestionValueType.None; _question = null; _lineNumber = 0; int emptyLineCount = 0; _endOfPage = false; if (_trace) { Trace.WriteLine($"read question file \"{file}\""); } foreach (string line in zFile.ReadLines(file)) { _lineNumber++; string line2 = line.Trim(); if (line2 == "") { //if (_lastValueType == QuestionValueType.Response) if (_lastValueType == QuestionValueType.Response || (_associationQuestion != null && _associationQuestion.Complete && _lastValueType == QuestionValueType.Question)) { if (_question != null) { //if (!_newVersion) // yield return new Question { Year = _question.Year, Type = _question.Type, Number = _question.Number, QuestionText = _question.QuestionText, Choices = _question.Choices.ToArray(), // SourceFile = _question.SourceFile, SourceLine = _question.SourceLine }; //else yield return(GetQuestion()); _question = null; } else if (_associationQuestion != null) { _associationQuestion.Complete = true; } _lastValueType = QuestionValueType.None; } if (++emptyLineCount == _maxEmptyLine) { _endOfPage = true; } continue; } emptyLineCount = 0; //FindText_v2 findText = _regexList.Find(line2); FindText_v2 findText = _regexList.Find(line); if (findText.Success) { bool newQuestion = false; QuestionTmp question = null; QuestionValue value = GetQuestionValue(findText.GetValues()); if (_trace) { Trace.WriteLine($" line {_lineNumber} - {value}"); } switch (value.Type) { case QuestionValueType.Year: newQuestion = true; _year = ((QuestionValueYear)value).Year; _associationQuestion = null; break; case QuestionValueType.QuestionType: newQuestion = true; _questionType = ((QuestionValueQuestionType)value).QuestionType; _associationQuestion = null; break; case QuestionValueType.QuestionNumber: newQuestion = true; if (_year == null) { throw new PBFileException($"unknow year, line {_lineNumber} file \"{_filename}\"", _file, _lineNumber); } //string sourceFile = _file; //if (baseDirectory != null && sourceFile.StartsWith(baseDirectory)) //{ // int l = baseDirectory.Length; // if (sourceFile[l] == '\\') // l++; // sourceFile = sourceFile.Substring(l); //} question = new QuestionTmp { Year = (int)_year, Type = _questionType, Number = ((QuestionValueQuestionNumber)value).QuestionNumber, QuestionLineCount = 0, SourceFile = GetSubPath(_file), SourceLine = _lineNumber }; if (_associationQuestion != null) { _associationQuestion.Complete = true; } break; case QuestionValueType.Response: //if (_question == null) // throw new PBFileException($"unknow question, line {_lineNumber} file \"{_filename}\"", _file, _lineNumber); //AddResponse(_question, (QuestionValueResponse)value); AddResponse((QuestionValueResponse)value); break; case QuestionValueType.None: _TraceUnknowValue(line2); break; default: throw new PBFileException($"wrong value \"{line2}\" line {_lineNumber} file \"{_filename}\"", _file, _lineNumber); } if (newQuestion) { if (_question != null) { //yield return new Question { Year = _question.Year, Type = _question.Type, Number = _question.Number, QuestionText = _question.QuestionText, Responses = _question.Responses.ToArray() }; yield return(GetQuestion()); } _question = question; } _lastValueType = value.Type; } else { if (_trace) { Trace.WriteLine($" line {_lineNumber} - text - {line2}"); } switch (_lastValueType) { case QuestionValueType.QuestionNumber: _question.QuestionText = line2; _question.QuestionLineCount++; _lastValueType = QuestionValueType.Question; break; case QuestionValueType.Question: //if (_question.QuestionLineCount > _maxLinesPerQuestion - 1) // throw new PBFileException($"to many lines for question \"{line2}\" line {_lineNumber} file \"{_filename}\"", _file, _lineNumber); //_question.QuestionText += " " + line2; //_question.QuestionLineCount++; AddQuestion(line2); break; case QuestionValueType.Response: //if (_question.ResponseLineCount > 1) // throw new PBFileException($"to many lines for response \"{line2}\" line {_lineNumber} file \"{_filename}\"", _file, _lineNumber); //int i = _question.Responses.Count - 1; //_question.Responses[i] += " " + line2; //_question.ResponseLineCount++; AddResponse(line2); break; case QuestionValueType.None: _TraceUnknowValue(line2); break; default: if (_lastValueType == QuestionValueType.QuestionType && _questionType == QuestionType.Association && _manageAssociationQuestion) { _associationQuestion = new QuestionAssociationTmp { Type = QuestionType.Association, QuestionText = line2, QuestionLineCount = 1, Complete = false }; _lastValueType = QuestionValueType.Question; } //else if (_year != null) // throw new PBFileException($"wrong value \"{line2}\" line {_lineNumber} file \"{_filename}\"", _file, _lineNumber); else { _TraceUnknowValue(line2); } break; } } } if (_question != null) { //yield return new Question { Year = _question.Year, Type = _question.Type, Number = _question.Number, QuestionText = _question.QuestionText, Responses = _question.Responses.ToArray() }; yield return(GetQuestion()); } } }
public async Task <int> InsertQuestionValue(QuestionValue questionValue) { return(await _consultingRepository.InsertQuestionValue(questionValue)); }
public async Task <int> UpdateQuestionValue(QuestionValue questionValue) { return(await _consultingRepository.UpdateQuestionValue(questionValue)); }
public IQuestionValue GenerateQuestion(CodingType codingType, EncoderType encodingType) { IQuestionValue value = new QuestionValue(); int countNumber = _random.Next(6, 10); StringBuilder question = new StringBuilder(); List <int> primes = new List <int>(); switch (encodingType) { case EncoderType.Caesar: value.Description = RandomGenerator.NextENGMessage(5); break; case EncoderType.Vigenere: value.Description = RandomGenerator.NextENGMessage(5); break; case EncoderType.DiffiHelman: value = new DiffiHelmanQuestion(); IDiffiHelmanQuestion diffiHelman = (IDiffiHelmanQuestion)value; primes = GetPrimes(203); diffiHelman.N = primes[_random.Next(0, primes.Count)]; diffiHelman.Q = _random.Next(2, diffiHelman.N - 1); diffiHelman.X = _random.Next(11, 100); diffiHelman.Y = _random.Next(11, 100); value = diffiHelman; break; case EncoderType.RSA: value = new DiffiHelmanQuestion(); IDiffiHelmanQuestion diffiHelman1 = (IDiffiHelmanQuestion)value; primes = GetPrimes(40); diffiHelman1.N = primes[_random.Next(2, primes.Count)]; diffiHelman1.Q = _random.Next(2, diffiHelman1.N - 1); diffiHelman1.X = _random.Next(11, 40); value = diffiHelman1; break; case EncoderType.Elgamal: primes = GetPrimes(203); value = new ElgamalQuestion(); IElgamalQuestion elgmal = (IElgamalQuestion)value; elgmal.P = primes[_random.Next(2, primes.Count)]; elgmal.A = _random.Next(3, elgmal.P - 1); elgmal.B = _random.Next(1, elgmal.P - 2); elgmal.R = _random.Next(1, elgmal.P - 1); switch (codingType) { case CodingType.Encoding: elgmal.Description = $"{_random.Next(2, 20)},{_random.Next(2, 200)}"; break; case CodingType.Decoding: elgmal.Description = $"{_random.Next(2, 20)}"; break; } break; } return(value); }
// PUT: api/QuestionValues/5 public void Put(int id, [FromBody] QuestionValue value) { }