/// <summary> /// Edit interview interview process /// </summary> /// <param name="process">interview process</param> /// <param name="listRound">list interview round in process</param> /// <returns> /// Success: Interview process /// Error: null / exception /// </returns> public InterviewProcess Edit(InterviewProcess process, List <RoundProcess> listRound) { log.Info(String.Format("Function: Edit - process: {0} - listRound: {1}", process, listRound)); //update interview process InterviewProcess updateProcessResult = _interviewProcessRepository.Update(process); if (updateProcessResult == null) { log.Info(String.Format("Process: {0} - Message: Update interview process failed", process)); } else { //set round order int roundOrder = 1; for (int roundIndex = 0; roundIndex < listRound.Count; roundIndex++) { listRound[roundIndex].RoundOrder = roundIndex + 1; } //find roundProcess that do not in process anymore, then delete it List <RoundProcess> listRoundProcess = _roundProcessRepository.GetByProcessId(process.ID).ToList(); RoundProcess roundProcessFindResult = new RoundProcess(); foreach (RoundProcess roundProcess in listRoundProcess.ToList()) { roundProcessFindResult = listRound.FirstOrDefault(r => r.InterviewRoundID == roundProcess.InterviewRoundID); if (roundProcessFindResult == null) { //relationship not exist in listRound, remove it from database _roundProcessRepository.Delete(roundProcess); } else { //if relationship is exist in list, edit RoundOrder of it and remove it from list round to do not be duplicate when save list roundProcess.RoundOrder = roundProcessFindResult.RoundOrder; _roundProcessRepository.Update(roundProcess); listRound.Remove(roundProcessFindResult); } } //add relationship between round and process foreach (RoundProcess round in listRound) { _roundProcessRepository.Add(round); } try { Save(); } catch (Exception exc) { throw new Exception(exc.Message); } } return(updateProcessResult); }
/// <summary> /// Add interivew process /// </summary> /// <param name="process">interview process</param> /// <param name="listRound">list interview round in process</param> /// <returns> /// Success: interview process id /// Error: bad id (0), exception /// </returns> public int AddProcess(InterviewProcess process, List <RoundProcess> listRound) { log.Info(String.Format("Function: AddProcess - process: {0} - listRound: {1}", process, listRound)); //Add interview process InterviewProcess processAddResult = _interviewProcessRepository.Add(process); if (processAddResult == null) { log.Info(String.Format("Process: {0} - Message: Add interview process failed!", process)); return(intBadId); } else { //add interview round to process RoundProcess addRoundProcessResult = new RoundProcess(); int roundOrder = 1; foreach (RoundProcess roundProcess in listRound) { roundProcess.InterviewProcessID = processAddResult.ID; roundProcess.RoundOrder = roundOrder; addRoundProcessResult = _roundProcessRepository.Add(roundProcess); if (addRoundProcessResult == null) { log.Info(String.Format("Process: {0} - ListRound: {1} - Message: Add interview process failed", process, listRound)); return(intBadId); } roundOrder = roundOrder + 1; } //save work try { Save(); } catch (Exception exc) { throw new Exception(exc.Message); } return(processAddResult.ID); } }