Пример #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 DeleteSubject(int teacherID, string subjectTitle)
        {
            int subjectID = await _context.Subject.Where(s => s.Title.Equals(subjectTitle)).Select(s => s.Subjectid).FirstOrDefaultAsync();

            Teaching teaching = await _context.Teaching.Where(t => t.Userid == teacherID && t.Subjectid == subjectID).FirstOrDefaultAsync();

            _context.Remove(teaching);
            await _context.SaveChangesAsync();
        }
Пример #3
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;
                }
            }
        }
Пример #4
0
 //deletes request if it is denied
 public async Task DenyNewSubjectRequest(int requestID)
 {
     _context.Remove(await GetSubjectRequestByID(requestID));
     await _context.SaveChangesAsync();
 }