public async Task <int> CreateQuizQuestion(Library.Models.QuizQuestion quizQuestion) { if (quizQuestion is null) { throw new ArgumentNullException(nameof(quizQuestion)); } _logger.LogInformation("Adding quizquestion"); Entities.QuizQuestion entity = Mapper.Map(quizQuestion); _dbContext.Add(entity); await _dbContext.SaveChangesAsync(); return(quizQuestion.QuizQuestionId); }
/// <summary> /// Adds a new User into the database and updates the log /// </summary> /// <param name="user">The Library model of the User to be added</param> public async Task <int> AddUser(Library.Models.User user) { if (user is null) { throw new ArgumentNullException(nameof(user)); } _logger.LogInformation($"Adding user {user.UserName}"); DataAccess.Entities.User entity = Mapper.Map(user); _dbContext.Add(entity); await _dbContext.SaveChangesAsync(); return(user.UserId); }
public async Task <int> CreateChoice(Library.Models.Choice choice) { if (choice is null) { throw new ArgumentNullException(nameof(choice)); } _logger.LogInformation($"Adding choice"); Entities.Choice entity = Mapper.Map(choice); _dbContext.Add(entity); await _dbContext.SaveChangesAsync(); return(choice.ChoiceId); }
/// <summary> /// Add a quiz, including any associated objects. Updates log. /// </summary> /// <param name="quiz">The quiz</param> public async Task <int> CreateQuiz(Library.Models.Quiz quiz) { if (quiz is null) { throw new ArgumentNullException(nameof(quiz)); } _logger.LogInformation($"Adding quiz"); Entities.Quiz entity = Mapper.Map(quiz); entity.Time = DateTime.Now; _dbContext.Add(entity); await _dbContext.SaveChangesAsync(); //update user completed quizzes Entities.User userEntity = _dbContext.User.Where(u => u.UserId == entity.UserId).First(); if (userEntity != null) { userEntity.CompletedQuizzes += 1; await _dbContext.SaveChangesAsync(); } return(quiz.QuizId); }