public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Email,ClassId")] Teachers teacher) { if (id != teacher.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(teacher); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeachersExists(teacher.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } // ViewData["ClassId"] = new SelectList(_context.Classes, "Id", "Id", teacher.ClassId); ViewData["ClassId"] = new SelectList(await classRepository.GetAllAsync(), "Id", "Id", teacher.ClassId); return(View(teacher)); }
public async Task <IActionResult> Create([Bind("Id,Name,Email,ClassId")] Teachers teacher) { if (ModelState.IsValid) { _context.Add(teacher); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ClassId"] = new SelectList(_context.Classes, "Id", "Id", teacher.ClassId); return(View(teacher)); }
public async Task UpdateQuestionAsync(ViewModel.QuestionInputModel question) { var questionToUpdate = await _dbContext.Question.FindAsync(question.Id); if (questionToUpdate is null) { questionToUpdate = new Infrastructure.Database.Question(); await _dbContext.Question.AddAsync(questionToUpdate); await _dbContext.SaveChangesAsync(); } questionToUpdate.CategoryId = question.CategoryId; questionToUpdate.Content = question.Content; questionToUpdate.Answer = question.Answer; await _dbContext.SaveChangesAsync(); }
public async Task <Teachers> InsertAsync(Teachers item) { context.Add(item); await context.SaveChangesAsync(); return(item); }
public async Task CreateCategoryAsync(string name) { var category = new Infrastructure.Database.Category { Name = name }; await _dbContext.Category.AddAsync(category); await _dbContext.SaveChangesAsync(); }
public async Task DeleteCategoryAsync(int id) { var category = await _dbContext.Category.FindAsync(id); if (category is null) { return; } _dbContext.Category.Remove(category); await _dbContext.SaveChangesAsync(); }
public async Task DeleteQuestionAsync(int id) { var question = await _dbContext.Question.FindAsync(id); if (question is null) { return; } _dbContext.Question.Remove(question); await _dbContext.SaveChangesAsync(); }
public async Task UpdateCategoryAsync(int id, string name) { var category = await _dbContext.Category.FindAsync(id); if (category is null) { throw new NullReferenceException($"Category of id {id} not found"); } category.Name = name; await _dbContext.SaveChangesAsync(); }
public async Task CreateQuestionAsync(ViewModel.QuestionInputModel question) { var questionToAdd = new Infrastructure.Database.Question { CategoryId = question.CategoryId, Content = question.Content, Answer = question.Answer }; await _dbContext.Question.AddAsync(questionToAdd); await _dbContext.SaveChangesAsync(); }
public async Task CreateAnswerAsync(Command command) { var answer = new Infrastructure.Database.Answer { QuestionId = command.QuestionId, UserId = command.UserId, WasAnswerCorrect = command.WasAnswerCorrect, AnsweredAt = DateTime.UtcNow }; await _dbContext.Answer.AddAsync(answer); await _dbContext.SaveChangesAsync(); }