示例#1
0
        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));
        }
示例#2
0
        public int CreateScore([FromBody] Score score)
        {
            _scoreRepository.AddScore(score);
            _scoreRepository.Save();

            return(score.Points);
        }
示例#3
0
        public IActionResult CreateScore([FromBody] Score score)
        {
            _scoreRepository.AddScore(score);
            _scoreRepository.Save();

            return(Ok());
        }
示例#4
0
        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));
        }
示例#5
0
        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");
        }
示例#6
0
        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());
        }
示例#7
0
 public IActionResult Post(L_Score score)
 {
     _scoreRepository.AddScore(score);
     return(CreatedAtAction(nameof(GetById), new { id = score.ScoreId }, score));
 }
示例#8
0
 public IActionResult AddScore(Scores score)
 {
     _scoreRepository.AddScore(score);
     return(RedirectToAction("ScoreManagement"));
 }