예제 #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();
        }