public EnrollmentSubjectTestDTO AddSubjectTest(EnrollmentSubjectTestDTO value, string token) { var enrollmentSubjecExist = _unitOfWork.GetReadOnlyRepository <EnrollmentSubject>().Single(x => x.EnrollmentSubjectGUID == value.EnrollmentSubjectGUID); if (enrollmentSubjecExist != null) { var enrollmentSubjectTest = _masterService.GetOne <EnrollmentSubjectTest>(x => x.TestID == value.TestID); if (enrollmentSubjectTest == null) { var newvalue = Mapper.Map <EnrollmentSubjectTest>(value); newvalue.EnrollmentSubjectTestGUID = Guid.NewGuid(); //ensbjtest.CreatedBy = _appUserService.GetUserId(token); var repo = _unitOfWork.GetRepository <EnrollmentSubjectTest>(); repo.Add(newvalue); repo.SaveChanges(); return(Mapper.Map <EnrollmentSubjectTestDTO>(_masterService.GetOne <EnrollmentSubjectTest>(x => x.EnrollmentSubjectTestGUID == newvalue.EnrollmentSubjectTestGUID))); } throw new Exception("This Test Is Exist"); } throw new Exception("Enrollment Subject Is Not Exist"); }
public IActionResult AddSubjectTest([FromBody] EnrollmentSubjectTestDTO subjecttest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { //var idToken = HttpContext.GetTokenAsync(JwtBearerDefaults.AuthenticationScheme, "access_token"); //var token = idToken.Result; var enrollmentSubjectTest = _enrollmentService.AddSubjectTest(subjecttest, ""); if (enrollmentSubjectTest != null) { return(Ok(enrollmentSubjectTest)); } return(BadRequest(new { message = "Cannot Add Test" })); } catch (Exception e) { return(BadRequest(e)); } }