public async Task <IActionResult> AddSubject(SubjectScoreViewModel model) { ModelState.Clear(); await model.InitAsync(_dbContext); return(View(model)); }
public async Task <IActionResult> EditSubject(SubjectScoreViewModel model) { var subject = _dbContext.SubjectScores .Include(x => x.Subject) .Include(x => x.EducationalDirection) .FirstOrDefault(x => x.Id == model.Id); if (subject == null) { return(NotFound("EditSubject", model.Id)); } await model.InitAsync(subject, _dbContext); return(View("AddSubject", model)); }
public async Task <IActionResult> AddOrUpdateSubject(SubjectScoreViewModel model) { if (!ModelState.IsValid) { return(View("AddSubject", model)); } SubjectScore subject; if (model.Id > 0) { subject = await _dbContext.SubjectScores.FindAsync(model.Id); if (subject == null) { return(NotFound("AddOrUpdateSubject")); } subject.ModifiedDateTime = DateTime.Now; } else { subject = new SubjectScore(); subject.ModifiedDateTime = subject.CreateDateTime = DateTime.Now; subject.EducationalDirectionId = model.DirectionId; _dbContext.Add(subject); } subject.SubjectId = model.Subject.Id; subject.MinimumScore = model.MinScore; try { await _dbContext.SaveChangesAsync(); } catch (Exception ex) { return(Error("AddOrUpdateSubject", ex)); } return(RedirectToAction("Edit", new { id = subject.EducationalDirectionId })); }