public async Task PasswordChange(string New, int Id) { User user = FindUserById(Id); _context.Attach(user); user.Password = Encryptor.Encrypt(New); await _context.SaveChangesAsync(); }
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; } } }
private void AddPoints(int questionID, int value) { Question question = manager.FindQuestionById(questionID); context.Attach(question); question.Points = value; context.SaveChanges(); }