示例#1
0
        public async Task PasswordChange(string New, int Id)
        {
            User user = FindUserById(Id);

            _context.Attach(user);
            user.Password = Encryptor.Encrypt(New);
            await _context.SaveChangesAsync();
        }
示例#2
0
        public async Task RegisterAnswer(int questionID, string answer)
        {
            if (string.IsNullOrEmpty(answer))
            {
                throw new ArgumentException("answer cannot be empty");
            }

            Question question = await FindQuestionById(questionID);

            _context.Attach(question);
            question.Status = 1;
            question.Answer = answer;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException exc)
            {
                if (!QuestionExists(questionID))
                {
                    Console.WriteLine("Error happened while saving answer. Question does not exist in a database");
                    Console.WriteLine(exc.Message);
                }
                else
                {
                    throw;
                }
            }
        }
示例#3
0
        private void AddPoints(int questionID, int value)
        {
            Question question = manager.FindQuestionById(questionID);

            context.Attach(question);
            question.Points = value;
            context.SaveChanges();
        }