public ActionResult AddApplicant(TMSApplicantViewModel datamodel)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            List <TMSApplicantCommentViewModel>  listComment  = new List <TMSApplicantCommentViewModel>();
            List <TMSApplicantDocumentViewModel> listDocument = new List <TMSApplicantDocumentViewModel>();

            bool save = _AdminTMSMethod.SaveApplicantData(datamodel, listComment, listDocument, SessionProxy.UserId);


            if (save)
            {
                HRTool.Models.MailModel mail = new HRTool.Models.MailModel();
                mail.From    = datamodel.Email;
                mail.To      = datamodel.Email;
                mail.Subject = "Application";
                string inputFormat     = "ddd, dd MMM yyyy";
                string dateTimeEndorse = DateTime.Now.ToString("ddd, dd MMM yyyy");
                mail.Body = "Thank You";
                string mailFromReceive = Common.sendMail(mail);
                return(Json("True", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }
        }
        public bool SaveApplicantData(TMSApplicantViewModel datamodel, List <TMSApplicantCommentViewModel> listComment, List <TMSApplicantDocumentViewModel> listDocument, int UserId)
        {
            var data = _db.TMS_Applicant.Where(x => x.Email == datamodel.Email && x.Id != datamodel.Id && x.VacancyID != datamodel.VacancyID && x.Archived == false).ToList();
            List <TMS_Applicant_Documents> tmsDoc = new List <TMS_Applicant_Documents> ();

            if (data.Count < 0)
            {
                return(false);
            }
            else
            {
                DateTime StDate = new DateTime();
                if (datamodel.DateOfBirth != "" && datamodel.DateOfBirth != null)
                {
                    var startDateToString = DateTime.ParseExact(datamodel.DateOfBirth, inputFormat, CultureInfo.InvariantCulture);
                    StDate = Convert.ToDateTime(startDateToString.ToString(outputFormat));
                }
                if (datamodel.Id == 0)
                {
                    TMS_Applicant save = new TMS_Applicant();
                    save.VacancyID                         = datamodel.VacancyID;
                    save.FirstName                         = datamodel.FirstName;
                    save.LastName                          = datamodel.LastName;
                    save.Email                             = datamodel.Email;
                    save.GenderID                          = datamodel.GenderID;
                    save.DateOfBirth                       = StDate;
                    save.PostalCode                        = datamodel.PostalCode;
                    save.Address                           = datamodel.Address;
                    save.OtherContactDetails               = datamodel.OtherContactDetails;
                    save.StatusID                          = datamodel.StatusID;
                    save.CoverLetterPath                   = datamodel.CoverLetterPath;
                    save.CoverLetterPathOriginal           = datamodel.CoverLetterPathOriginal;
                    save.DownloadApplicationFormLink       = datamodel.DownloadApplicationFormLink;
                    save.UploadApplicationFormPathOriginal = datamodel.UploadApplicationFormPathOriginal;
                    save.UploadApplicationFormPath         = datamodel.UploadApplicationFormPath;
                    save.ResumePathOriginal                = datamodel.ResumePathOriginal;
                    save.ResumePath                        = datamodel.ResumePath;
                    save.Question1Answer                   = datamodel.Question1Answer;
                    save.Question2Answer                   = datamodel.Question2Answer;
                    save.Question3Answer                   = datamodel.Question3Answer;
                    save.Question4Answer                   = datamodel.Question4Answer;
                    save.Question5Answer                   = datamodel.Question5Answer;
                    save.SourceID                          = datamodel.SourceID;
                    save.CompatencyJSV                     = datamodel.CompatencyJSV;
                    save.CommentJSV                        = datamodel.CommentJSV;
                    save.DocumentJSV                       = datamodel.DocumentJSV;
                    save.GeneralSkillsJSV                  = datamodel.GeneralSkillsJSV;
                    save.TechnicalSkillsJSV                = datamodel.TechnicalSkillsJSV;
                    save.Cost                 = datamodel.Cost;
                    save.CreatedDate          = DateTime.Now;
                    save.Archived             = false;
                    save.UserIDCreatedBy      = UserId;
                    save.UserIDLastModifiedBy = UserId;
                    save.LastModified         = DateTime.Now;
                    save.IsReadHiringLead     = false;
                    if (datamodel.RejectReasonId != 0 && datamodel.RejectReasonId != null)
                    {
                        save.RejectReasonId      = datamodel.RejectReasonId;
                        save.RejectReasonComment = datamodel.RejectReasonComment;
                    }
                    _db.TMS_Applicant.Add(save);
                    _db.SaveChanges();

                    foreach (var item in _db.TMS_Applicant_Comments.Where(x => x.ApplicantID == save.Id).ToList())
                    {
                        _db.TMS_Applicant_Comments.Remove(item);
                        _db.SaveChanges();
                    }
                    foreach (var item in listComment)
                    {
                        TMS_Applicant_Comments mm = new TMS_Applicant_Comments();
                        mm.ApplicantID          = save.Id;
                        mm.Description          = item.comment;
                        mm.CreatedName          = item.commentBy;
                        mm.CreatedDateTime      = item.commentTime;
                        mm.Archived             = false;
                        mm.UserIDCreatedBy      = UserId;
                        mm.CreatedDate          = DateTime.Now;
                        mm.UserIDLastModifiedBy = UserId;
                        mm.LastModified         = DateTime.Now;
                        _db.TMS_Applicant_Comments.Add(mm);
                        _db.SaveChanges();
                    }
                    foreach (var item in _db.TMS_Applicant_Documents.Where(x => x.ApplicantID == save.Id).ToList())
                    {
                        _db.TMS_Applicant_Documents.Remove(item);
                        _db.SaveChanges();
                    }
                    foreach (var item in listDocument)
                    {
                        TMS_Applicant_Documents Document = new TMS_Applicant_Documents();
                        Document.ApplicantID          = save.Id;
                        Document.NewName              = item.newName;
                        Document.OriginalName         = item.originalName;
                        Document.Description          = item.description;
                        Document.Archived             = false;
                        Document.UserIDCreatedBy      = UserId;
                        Document.CreatedDate          = DateTime.Now;
                        Document.UserIDLastModifiedBy = UserId;
                        Document.LastModified         = DateTime.Now;
                        _db.TMS_Applicant_Documents.Add(Document);
                        _db.SaveChanges();
                    }
                    return(true);
                }
                else
                {
                    TMS_Applicant update = new TMS_Applicant();
                    update                             = _db.TMS_Applicant.Where(x => x.Id == datamodel.Id).FirstOrDefault();
                    update.VacancyID                   = datamodel.VacancyID;
                    update.FirstName                   = datamodel.FirstName;
                    update.LastName                    = datamodel.LastName;
                    update.Email                       = datamodel.Email;
                    update.GenderID                    = datamodel.GenderID;
                    update.DateOfBirth                 = StDate;
                    update.PostalCode                  = datamodel.PostalCode;
                    update.Address                     = datamodel.Address;
                    update.OtherContactDetails         = datamodel.OtherContactDetails;
                    update.StatusID                    = datamodel.StatusID;
                    update.CoverLetterPath             = datamodel.CoverLetterPath;
                    update.DownloadApplicationFormLink = datamodel.DownloadApplicationFormLink;
                    update.UploadApplicationFormPath   = datamodel.UploadApplicationFormPath;
                    update.ResumePath                  = datamodel.ResumePath;
                    update.Question1Answer             = datamodel.Question1Answer;
                    update.Question2Answer             = datamodel.Question2Answer;
                    update.Question3Answer             = datamodel.Question3Answer;
                    update.Question4Answer             = datamodel.Question4Answer;
                    update.Question5Answer             = datamodel.Question5Answer;
                    update.SourceID                    = datamodel.SourceID;
                    update.CompatencyJSV               = datamodel.CompatencyJSV;
                    update.CommentJSV                  = datamodel.CommentJSV;
                    update.DocumentJSV                 = datamodel.DocumentJSV;
                    update.GeneralSkillsJSV            = datamodel.GeneralSkillsJSV;
                    update.TechnicalSkillsJSV          = datamodel.TechnicalSkillsJSV;
                    update.Cost                        = datamodel.Cost;
                    update.UserIDLastModifiedBy        = UserId;
                    update.IsReadHiringLead            = false;
                    update.LastModified                = DateTime.Now;
                    _db.SaveChanges();

                    foreach (var item in listComment)
                    {
                        var tmsCommnts = _db.TMS_Applicant_Comments.Where(x => x.ApplicantID == update.Id).ToList();

                        TMS_Applicant_Comments mm = new TMS_Applicant_Comments();
                        mm.ApplicantID          = update.Id;
                        mm.Description          = item.comment;
                        mm.CreatedName          = item.commentBy;
                        mm.CreatedDateTime      = item.commentTime;
                        mm.Archived             = false;
                        mm.UserIDCreatedBy      = UserId;
                        mm.CreatedDate          = DateTime.Now;
                        mm.UserIDLastModifiedBy = UserId;
                        mm.LastModified         = DateTime.Now;
                        _db.TMS_Applicant_Comments.Add(mm);
                        _db.SaveChanges();
                    }
                    if (listDocument.Count == 0)
                    {
                        var ddata = _db.TMS_Applicant_Documents.Where(x => x.ApplicantID == update.Id).ToList();
                        if (ddata != null)
                        {
                            foreach (var item in ddata)
                            {
                                TMS_Applicant_Documents Document = new TMS_Applicant_Documents();
                                Document.ApplicantID          = update.Id;
                                Document.Archived             = true;
                                Document.UserIDCreatedBy      = UserId;
                                Document.CreatedDate          = DateTime.Now;
                                Document.UserIDLastModifiedBy = UserId;
                                Document.LastModified         = DateTime.Now;
                                tmsDoc.Add(Document);
                            }
                            _db.SaveChanges();
                        }
                    }
                    else
                    {
                        foreach (var item in listDocument)
                        {
                            var ddata = _db.TMS_Applicant_Documents.Where(x => x.ApplicantID == update.Id).ToList();
                            //foreach (var docitem in _db.TMS_Applicant_Documents.Where(x => x.ApplicantID == update.Id).ToList())
                            //{
                            //    _db.TMS_Applicant_Documents.Remove(docitem);
                            //    _db.SaveChanges();
                            //}
                            //foreach (var dd in ddata)
                            //{
                            //    TMS_Applicant_Documents Document = new TMS_Applicant_Documents();
                            //    if (item.Id==dd.Id)
                            //    {
                            //        Document.ApplicantID = update.Id;
                            //        Document.NewName = item.newName;
                            //        Document.OriginalName = item.originalName;
                            //        Document.Description = item.description;
                            //        Document.Archived = false;
                            //        Document.UserIDCreatedBy = UserId;
                            //        Document.CreatedDate = DateTime.Now;
                            //        Document.UserIDLastModifiedBy = UserId;
                            //        Document.LastModified = DateTime.Now;
                            //        tmsDoc.Add(Document);
                            //        //_db.TMS_Applicant_Documents.Add(Document);
                            //    }
                            //    else
                            //    {
                            //        Document.ApplicantID = update.Id;
                            //        Document.NewName = item.newName;
                            //        Document.OriginalName = item.originalName;
                            //        Document.Description = item.description;
                            //        Document.Archived = true;
                            //        Document.UserIDCreatedBy = UserId;
                            //        Document.CreatedDate = DateTime.Now;
                            //        Document.UserIDLastModifiedBy = UserId;
                            //        Document.LastModified = DateTime.Now;
                            //        tmsDoc.Add(Document);
                            //    }
                            //    _db.SaveChanges();
                            //}
                        }
                    }
                    return(true);
                }
            }
        }
        public TMSApplicantViewModel returnApplicantList(int Id, int VacancyId)
        {
            TMSApplicantViewModel datamodel = new TMSApplicantViewModel();

            foreach (var item in _otherSettingMethod.getAllSystemValueListByKeyName("Gender List"))
            {
                datamodel.GenderList.Add(new SelectListItem()
                {
                    Text = item.Value, Value = item.Id.ToString()
                });
            }
            foreach (var item in _otherSettingMethod.getAllSystemValueListByKeyName("Vacancy Source List"))
            {
                datamodel.SourceList.Add(new SelectListItem()
                {
                    Text = item.Value, Value = item.Id.ToString()
                });
            }
            var data = _AdminTMSMethod.getVacancyDetailsById(VacancyId);

            datamodel.GenderName = datamodel.GenderList[0].Value;
            datamodel.DownloadApplicationFormLink = data.ApplicationFormPath;
            TMSVacancyViewModel vacancyDetailsModel = new TMSVacancyViewModel();

            vacancyDetailsModel.Id = data.Id;
            vacancyDetailsModel.MustUploadCoverLetter       = data.MustUploadCoverLetter;
            vacancyDetailsModel.MustUploadResumeCV          = data.MustUploadResumeCV;
            vacancyDetailsModel.ApplicationFormPathOriginal = data.ApplicationFormPathOriginal;
            vacancyDetailsModel.ApplicationFormPath         = data.ApplicationFormPath;
            vacancyDetailsModel.Question1On   = data.Question1On;
            vacancyDetailsModel.Question1Text = data.Question1Text;
            vacancyDetailsModel.Question2On   = data.Question2On;
            vacancyDetailsModel.Question2Text = data.Question2Text;
            vacancyDetailsModel.Question3On   = data.Question3On;
            vacancyDetailsModel.Question3Text = data.Question3Text;
            vacancyDetailsModel.Question4On   = data.Question4On;
            vacancyDetailsModel.Question4Text = data.Question4Text;
            vacancyDetailsModel.Question5On   = data.Question5On;
            vacancyDetailsModel.Question5Text = data.Question5Text;
            datamodel.VacancyDetails          = vacancyDetailsModel;
            if (data.RecruitmentProcessID != 0)
            {
                var res = _TMSSettingsMethod.getTMSSettingListById(data.RecruitmentProcessID);
                if (res.StepCSV != "1")
                {
                    var steps = JsonConvert.DeserializeObject <List <TMSSettingStepDetails> >(res.StepCSV);
                    if (steps != null)
                    {
                        foreach (var s in steps)
                        {
                            TMSSettingStepDetails ss = new TMSSettingStepDetails();
                            ss.Id        = s.Id;
                            ss.StepName  = s.StepName;
                            ss.ColorCode = s.ColorCode;
                            datamodel.StatusList.Add(ss);
                            if (s.StepName == "New Applicants")
                            {
                                datamodel.StatusID = s.Id;
                            }
                        }
                    }
                }
            }
            //DateTime today = DateTime.Now;
            //datamodel.DateOfBirth = String.Format("{0:dd-MM-yyyy}", today);
            return(datamodel);
        }
        public ActionResult JobDetails(int Id, int VacancyId)
        {
            TMSApplicantViewModel model = returnApplicantList(Id, VacancyId);

            return(PartialView("_partialAddJobApplyApplicant", model));
        }