public async Task <ActionResult <BaseResponse> > PostScoreExam(ScoreExam scoreExam) { var datas = _context.ScoreExams.Where(x => x.EXAM_ID.Equals(Convert.ToInt32(scoreExam.EXAM_ID))).Where(y => y.MAJOR_ID.Equals(Convert.ToInt32(scoreExam.MAJOR_ID))).ToList(); if (Convert.ToInt32(scoreExam.MAJOR_ID) == 0 || Convert.ToInt32(scoreExam.EXAM_ID) == 0 || Convert.ToInt32(scoreExam.ScorePass) == 0 || Convert.ToInt32(scoreExam.SumScore) == 0) { return(new BaseResponse { ErrorCode = 0, Messege = "Not be emty!!" }); } else if (datas.Count != 0) { return(new BaseResponse { ErrorCode = 2, Messege = "Score Exam already exist!!" }); } else { _context.ScoreExams.Add(scoreExam); await _context.SaveChangesAsync(); return(new BaseResponse { ErrorCode = 1, Messege = "Thêm mới thành công!!", Data = CreatedAtAction("GetScoreExam", new { id = scoreExam.Id }, scoreExam) }); } }
public async Task <ActionResult <BaseResponse> > PostScoreExam(ScoreExam scoreExam) { _context.ScoreExams.Add(scoreExam); await _context.SaveChangesAsync(); return(new BaseResponse { ErrorCode = 1, Messege = "Thêm mới thành công!!", Data = CreatedAtAction("GetScoreExam", new { id = scoreExam.Id }, scoreExam) }); }
public async Task <IActionResult> PutScoreExam(int id, ScoreExam scoreExam_update) { var Score = await _context.ScoreExams.FindAsync(id); if (Score == null) { return(NotFound()); } Score.EXAM_ID = scoreExam_update.EXAM_ID; Score.MAJOR_ID = scoreExam_update.MAJOR_ID; Score.SumScore = scoreExam_update.SumScore; Score.ScorePass = scoreExam_update.ScorePass; _context.ScoreExams.Update(Score); await _context.SaveChangesAsync(); return(Ok(Score)); }
public async Task <ActionResult <BaseResponse> > PutScoreExam(int id, ScoreExam scoreExam_update) { var datas = _context.ScoreExams.Where(x => x.EXAM_ID.Equals(Convert.ToInt32(scoreExam_update.EXAM_ID))).Where(y => y.MAJOR_ID.Equals(Convert.ToInt32(scoreExam_update.MAJOR_ID))).ToList(); var Score = await _context.ScoreExams.FindAsync(id); if (Score == null) { return(NotFound()); } else if (Convert.ToInt32(scoreExam_update.MAJOR_ID) == 0 || Convert.ToInt32(scoreExam_update.EXAM_ID) == 0 || Convert.ToInt32(scoreExam_update.ScorePass) == 0 || Convert.ToInt32(scoreExam_update.SumScore) == 0) { return(new BaseResponse { ErrorCode = 0, Messege = "Not be emty!!" }); } else if (datas.Count != 0) { return(new BaseResponse { ErrorCode = 2, Messege = "Score Exam already exist!!" }); } else { Score.EXAM_ID = scoreExam_update.EXAM_ID; Score.MAJOR_ID = scoreExam_update.MAJOR_ID; Score.SumScore = scoreExam_update.SumScore; Score.ScorePass = scoreExam_update.ScorePass; _context.ScoreExams.Update(Score); await _context.SaveChangesAsync(); return(new BaseResponse { ErrorCode = 1, Messege = "Update thành công!!" }); } }