예제 #1
0
        protected void Button_Add_Interview_Click(object sender, EventArgs e)
        {
            try
            {
                using (ModelContext db = new ModelContext())
                {
                    int      submissionSlno, consultantID;
                    DateTime date;

                    submissionSlno = Convert.ToInt32(HiddenField_Submission_SLNO.Value);
                    consultantID   = db.Consultants.FirstOrDefault(c => c.LastName.Equals(TextBox_Intvw_Constultant.Text)).Id;


                    Dictionary <string, string> interviewValues = LoadInterviewFieldValues();

                    FieldValidator.CheckInterviewFields(interviewValues);

                    date = DateTime.Parse(interviewValues["Date"]);
                    var newInterview = new Models.Interviews
                    {
                        SubmissionSlno = submissionSlno,
                        ConsultantId   = consultantID,
                        Type           = interviewValues["Type"],
                        Method         = interviewValues["Method"],
                        Interviewer    = interviewValues["Interviewer"],
                        SkillsRequired = interviewValues["Skills"],
                        Status         = interviewValues["Status"],
                        Feedback       = interviewValues["Feedback"],
                        Remarks        = interviewValues["Remarks"],
                        DateScheduled  = date
                    };
                    db.Interviews.Add(newInterview);
                    db.SaveChanges();
                    LoggingUtility.LogMessage($"New Interview #{newInterview.Id} successfully added.");
                }
            }
            catch (Exception ex) { handleException(ex, sender.ToString()); }
            Response.Redirect($"~/Pages/ViewAllSubmissions.aspx?Id={ConsultantId.Value}");
        }
예제 #2
0
        public async Task <ResponseModel <long> > ScheduleInterviewAsync(long userId, Models.Interviews interviewModel)
        {
            var respose = new ResponseModel <long>();

            if (interviewModel.Applicant == null || interviewModel.Applicant?.ApplicantId == 0)
            {
                throw new BadRequestCustomException("Debe indicar la persona ser entrevistada", "");
            }

            if (interviewModel.Date == DateTime.MinValue || interviewModel.Date < DateTime.Now)
            {
                throw new BadRequestCustomException("Debe indicar una fecha valida, debe ser una fecha futura", "");
            }

            if (interviewModel.InterviewTypeId == 0)
            {
                throw new BadRequestCustomException("Debe indicar el tipo de entrevista", "");
            }

            var interviewType = await Repositories.InterviewTypesRepository.GetSingleByIdAsync(interviewModel.InterviewTypeId);

            if (interviewType == null)
            {
                throw new NotFoundCustomException($"No se encontro el tipo de entrevista {interviewModel.InterviewTypeId}", "");
            }

            if (interviewModel.RecruiterProcessId == 0)
            {
                throw new BadRequestCustomException("Debe indicar el tipo de entrevista", "");
            }

            var recruiterProcess = await Repositories.RecruiterProcessesRepository.GetSingleAsync(r => r.RecruiterProcessId == interviewModel.RecruiterProcessId &&
                                                                                                  r.UserId == userId);

            if (recruiterProcess == null)
            {
                throw new NotFoundCustomException($"No se encontro el proceso de contratación {interviewModel.RecruiterProcessId}", "");
            }

            var interviews = await Repositories.InterviewsRepository.ListAsync(i => i.Date == interviewModel.Date ||
                                                                               i.Date.AddHours(1) > interviewModel.Date);

            if (interviews.ToList().Count > 0)
            {
                throw new BadRequestCustomException("Fecha de entrevista no valida", "La fecha debe tener una difrencia de por lo menos 1 hora con otras entrevista");
            }

            var applicant = await Repositories.ApplicantsRepository.GetSingleByIdAsync(interviewModel.Applicant.ApplicantId);

            if (applicant == null)
            {
                applicant = Mapper.Map <Data.Entities.Applicants>(interviewModel.Applicant);
                // Create an applicant if not exist
                Repositories.ApplicantsRepository.Save(applicant);
            }

            var interview = Mapper.Map <Data.Entities.Interviews>(interviewModel);

            interview.Applicant = applicant;
            interview.State     = true;
            Repositories.InterviewsRepository.Save(interview);
            await UnitOfWork.CommitAsync();

            respose.Success = true;
            respose.Data    = interview.InterviewId;
            return(respose);
        }