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 }));
        }
Beispiel #2
0
        public async Task <IActionResult> UpdateScheduleOfJobApplicationPost(SchedulesViewModel model)
        {
            List <SchedulesUsers> collection     = new List <SchedulesUsers>();
            List <string>         interviewers   = new List <string>();
            JobApplications       jobApplication = new JobApplications();

            try
            {
                //converting enum values to int
                model.status = Convert.ToInt32(model.statusvalue);

                //saving all the interviewers
                interviewers = model.Multiinterviewer;

                //all data of ScheduleUser composite table
                collection = _dbContext.SchedulesUsers.Where(x => x.scheduleId == model.ID).ToList();

                //removing the existing pairs of old schedules interviewers
                _dbContext.SchedulesUsers.RemoveRange(collection);
                _dbContext.SaveChanges();

                //adding new records of composite key into schedule users for new userschedule pairs
                foreach (var item in interviewers)
                {
                    SchedulesUsersViewModel newModel = new SchedulesUsersViewModel()
                    {
                        scheduleId = model.ID,
                        UserId     = item
                    };
                    await _schedulesUsersPage.AddNewSchedulesUsers(newModel);
                }

                await _schedulesPage.UpdateSchedule(model);

                //redirecting to details of job Application
                jobApplication = _dbContext.jobApplications.Where(x => x.candidateId == model.candidateId).FirstOrDefault();
            }catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(RedirectToAction("Details", "JobApplication", new { id = jobApplication.ID }));
        }