public async Task <IActionResult> PutApplicantTheoryExam(int id, [FromForm] ApplicantTheoryExam applicantTheoryExam) { if (id != applicantTheoryExam.applicant_id) { return(BadRequest()); } applicantTheoryExam.updated_at = DateTime.Now; _context.Entry(applicantTheoryExam).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApplicantTheoryExamExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <TheoryExam> > CorrectionTheoryExam([FromForm] Correction correction) { var identity = User.Identity as System.Security.Claims.ClaimsIdentity; IEnumerable <System.Security.Claims.Claim> claims = identity.Claims; var national_code = claims.Where(p => p.Type == "national_code").FirstOrDefault()?.Value; var applicant = _context.applicants.Where(q => q.national_code == national_code).FirstOrDefault(); if (applicant == null) { return(Unauthorized()); } var questions = _context.questions.Where(q => q.theory_exam_id == correction.theory_exam_id).Select(q => new Question { id = q.id, correct_answer = q.correct_answer }); var wrong = 0; foreach (Question question in questions) { if (correction.answers[question.id] != question.correct_answer) { wrong++; } } ; var status = "قبول"; if (wrong != 0 && questions.Count() / wrong < 2) { status = "رد"; } var applicantTheoryExam = new ApplicantTheoryExam { status = status, applicant_id = applicant.id, theory_exam_id = correction.theory_exam_id, point = questions.Count() - wrong }; _context.applicant_theory_exams.Add(applicantTheoryExam); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTheoryExam", new { id = applicantTheoryExam.id }, applicantTheoryExam)); }
public async Task <ActionResult <ApplicantTheoryExam> > PostApplicantTheoryExam([FromForm] int exam_id) { var identity = User.Identity as System.Security.Claims.ClaimsIdentity; IEnumerable <System.Security.Claims.Claim> claims = identity.Claims; var national_code = claims.Where(p => p.Type == "national_code").FirstOrDefault()?.Value; var applicant = _context.applicants.Where(q => q.national_code == national_code).FirstOrDefault(); if (applicant == null) { return(Unauthorized()); } var applicantTheoryExam = new ApplicantTheoryExam { applicant_id = applicant.id, theory_exam_id = exam_id }; _context.applicant_theory_exams.Add(applicantTheoryExam); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (ApplicantTheoryExamExists(applicantTheoryExam.applicant_id)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetApplicantTheoryExam", new { id = applicantTheoryExam.applicant_id }, applicantTheoryExam)); }