public async Task <IActionResult> IndexPost(SchedulesViewModel model) { List <Schedules> allschedules = new List <Schedules>(); JobApplications jobAppModel = new JobApplications(); Candidate candidateModel = new Candidate(); SchedulesViewModel latestRecord = new SchedulesViewModel(); try { //for getting the job application of candidate in current scenario (we are in schedules so for getting //job Application ID, need to go through candidate) candidateModel = _dbContext.Candidate.Where(x => x.ID == model.candidateId).FirstOrDefault(); jobAppModel = _dbContext.jobApplications.Where(x => x.candidateId == model.candidateId).FirstOrDefault(); //checking for already existing round allschedules = _dbContext.Schedules.Where(x => x.candidateId == model.candidateId).ToList(); foreach (var item in allschedules) { if (item.round == model.round) { TempData["msg"] = model.round; return(RedirectToAction("Details", "JobApplication", new { id = jobAppModel.ID, conflict = TempData["msg"] })); } } //for new schedule Proceed //converting enum values to int model.status = Convert.ToInt32(model.statusvalue); //saving all the interviewers List <string> interviewers = new List <string>(); interviewers = model.Multiinterviewer; //fetch schedule from db for this candidate , getting schedule id for composite key use. latestRecord = await _schedulesPage.AddNewSchedules(model); //insert Composite keys to SchedulesUsers (interviewers to schedules mapping) foreach (var item in interviewers) { SchedulesUsersViewModel newModel = new SchedulesUsersViewModel() { scheduleId = latestRecord.ID, UserId = item }; await _schedulesUsersPage.AddNewSchedulesUsers(newModel); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(RedirectToAction("Details", "JobApplication", new { id = jobAppModel.ID })); }