public async Task <ActionResult <ScoreDto> > CreateScore([FromBody] ScoreAddDto scoreAddDto) { if (!await _studentRepository.StudentExistAsync(scoreAddDto.StudentId)) { return(NotFound()); } if (!await _teach_CourseRepository.RelationExistAsync(scoreAddDto.TeacherId, scoreAddDto.CourseId)) { return(NotFound()); } //ApiController在遇到scoreAddDto为空时可以自动返回400错误 var score = _mapper.Map <Score>(scoreAddDto); score.StudentId = scoreAddDto.StudentId; score.Student = await _studentRepository.GetStudentAsync(scoreAddDto.StudentId); score.TeacherId = scoreAddDto.TeacherId; score.CourseId = scoreAddDto.CourseId; score.Teach_Course = await _teach_CourseRepository.GetRelationAsync(scoreAddDto.TeacherId, scoreAddDto.CourseId); _scoreRepository.AddScore(score);//只是被添加到DbContext里 await _scoreRepository.SaveAsync(); var scoreDto = _mapper.Map <ScoreDto>(score); return(CreatedAtRoute(nameof(GetScore), new { studentId = score.StudentId, teacherId = score.TeacherId, courseId = score.CourseId }, scoreDto)); }
public int CreateScore([FromBody] Score score) { _scoreRepository.AddScore(score); _scoreRepository.Save(); return(score.Points); }
public IActionResult CreateScore([FromBody] Score score) { _scoreRepository.AddScore(score); _scoreRepository.Save(); return(Ok()); }
public async Task <IActionResult> PostScore([FromBody] ScoreDto scoreDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // map dto to entity var score = _mapper.Map <Score>(scoreDto); var user = _userRepository.GetByUsername(scoreDto.Username); score.User = user; await _scoreRepository.AddScore(score); await _hubContext.Clients.All.SendAsync("scoresUpdate", scoreDto); return(Ok(score)); }
private void btnUpdateScore_Click(object sender, EventArgs e) { var student = (Student)this.lstBoxStudentOntbPageNote.SelectedItem; var selectedLesson = (Lesson)this.cmbLessonsOntbPageScore.SelectedItem; var lessonScore = scoreRepository.GetAll().FirstOrDefault(s => s.Lesson.Id == selectedLesson.Id && s.Student.Id == student.Id); if (lessonScore != null) { lessonScore.TotalScore = Convert.ToInt32(txtBoxPuan.Text); lessonScore.FinalScore = Convert.ToInt32(cmbBoxFinal.SelectedValue); lessonScore.VizeScore = Convert.ToInt32(cmbBoxVize.SelectedValue); lessonScore.FinalRate = Convert.ToInt32(txtBoxFinalRateOntbPageNote.Text); lessonScore.VizeRate = Convert.ToInt32(txtBoxVizeRateOntbPageNote.Text); scoreRepository.UpdateScore(lessonScore); } else { var newLessonScore = new Score(); newLessonScore.Student = student; newLessonScore.Lesson = selectedLesson; newLessonScore.TotalScore = Convert.ToInt32(txtBoxPuan.Text); newLessonScore.FinalScore = Convert.ToInt32(cmbBoxFinal.SelectedValue); newLessonScore.VizeScore = Convert.ToInt32(cmbBoxVize.SelectedValue); newLessonScore.FinalRate = Convert.ToInt32(txtBoxFinalRateOntbPageNote.Text); newLessonScore.VizeRate = Convert.ToInt32(txtBoxVizeRateOntbPageNote.Text); scoreRepository.AddScore(newLessonScore); } student.VizeScore = (int)this.cmbBoxVize.SelectedValue; student.FinalScore = (int)this.cmbBoxFinal.SelectedValue; student.VizeRate = Convert.ToInt32(this.txtBoxVizeRateOntbPageNote.Text); student.FinalRate = Convert.ToInt32(this.txtBoxFinalRateOntbPageNote.Text); student.TotalScore = Convert.ToInt32(this.txtBoxPuan.Text); MessageBox.Show("Öğrenci notu güncellendi"); }
public async Task <IActionResult> Score([FromBody] ScoreAddResource scoreAddResource) { if (scoreAddResource == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new MyUnprocessableEntityObjectResult(ModelState)); } var newScore = _mapper.Map <ScoreAddResource, Score>(scoreAddResource); newScore.LastModified = DateTime.Now; _scoreRepository.AddScore(newScore); if (!await _unitOfWork.SaveAsync()) { throw new Exception("Save Failed!"); } return(Ok()); }
public IActionResult Post(L_Score score) { _scoreRepository.AddScore(score); return(CreatedAtAction(nameof(GetById), new { id = score.ScoreId }, score)); }
public IActionResult AddScore(Scores score) { _scoreRepository.AddScore(score); return(RedirectToAction("ScoreManagement")); }