public async Task <IActionResult> Edit(int id, [Bind("Id,CourseId,ExamName,Description")] CourseExamModel courseExam) { if (id != courseExam.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _context.Update(courseExam); } catch (DbUpdateConcurrencyException) { if (!CourseExamExists(courseExam.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CourseId"] = new SelectList(_courseService.Get(), "Id", "Name", courseExam.CourseId); return(View(courseExam)); }
public async Task <IActionResult> Create([Bind("Id,CourseId,ExamName,Description")] CourseExamModel courseExam) { if (ModelState.IsValid) { await _context.Add(courseExam); return(RedirectToAction(nameof(Index))); } ViewData["CourseId"] = new SelectList(_courseService.Get(), "Id", "Name", courseExam.CourseId); return(View(courseExam)); }
public async Task <CourseExamModel> Add(CourseExamModel model) { try { var entity = _mapper.Map <CourseExam>(model); await _repository.Insert(entity); return(model); } catch (Exception) { throw; } }
public async Task <CourseExamModel> Update(CourseExamModel model) { try { var entity = await _repository.Find(model.Id); if (entity == null) { throw new Exception("CourseExam not found"); } _mapper.Map(model, entity); await _repository.Update(entity); return(model); } catch (Exception) { throw; } }