//Add candidate feedback for position
        public void addcandidatefeedbackposition(candidatefeedback CF)
        {
            using (RecrutmentsysEntities db = new RecrutmentsysEntities())
            {
                CANDIDATE_POSITION          cp  = db.CANDIDATE_POSITION.Where(o => o.CandidateCode == CF.candidatecode).FirstOrDefault();
                CANDIDATE_FEEDBACK_POSITION cfp = new CANDIDATE_FEEDBACK_POSITION();
                cfp.CandidateCode     = cp.CandidateCode;
                cfp.CandidateEmail    = cp.CandidateEmail;
                cfp.Candidate_Yof_exp = cp.Candidate_Yof_exp;
                cfp.CompanyId         = cp.CompanyId;
                cfp.DepartmentCode    = cp.DepartmentCode;

                COMPANY_JOB_OPENING cjo = db.COMPANY_JOB_OPENING.Where(o => o.DepartmentCode == cp.DepartmentCode).FirstOrDefault();
                cfp.DepartmentName           = cjo.DepartmentName;
                cfp.RequestedBy              = cjo.RequestedBy;
                cfp.HrId                     = cjo.HrId;
                cfp.HrEmail                  = cjo.HrEmail;
                cfp.Name_of_Vacancy          = cjo.Name_of_Vacancy;
                cfp.Number_of_Position       = cjo.Number_of_Position;
                cfp.Required_Technical_Skill = cjo.Required_Technical_Skill;
                cfp.Special_Technical_Skill  = cjo.Special_Technical_Skill;
                cfp.Min_Yearof_Experience    = cjo.Min_Yearof_Experience;
                cfp.Min_Qualification        = cjo.Min_Qualification;
                cfp.Deadline_Date            = cjo.Deadline_Date;
                cfp.Requested_Date           = cjo.Requested_Date;
                cfp.RoundingPercentage       = CF.rounding_percent;
                cfp.OfferLatter              = "No";
                cfp.Feedbackprocess          = false;

                db.CANDIDATE_FEEDBACK_POSITION.Add(cfp);
                db.SaveChanges();

                Round_Detail_feedback rdf = new Round_Detail_feedback();
                rdf.CompanyId      = cfp.CompanyId;
                rdf.CandidateCode  = cfp.CandidateCode;
                rdf.DepartmentCode = cfp.DepartmentCode;
                rdf.HrId           = cfp.HrId;
                rdf.RoundOne       = CF.round1;
                rdf.RoundOne_per   = CF.round1P;
                rdf.RoundTwo       = CF.round2;
                rdf.RoundTwo_per   = CF.round2P;
                rdf.RoundThree     = CF.round3;
                rdf.RoundThree_per = CF.round3P;
                rdf.totalround_per = CF.rounding_percent;

                db.Round_Detail_feedback.Add(rdf);
                db.SaveChanges();

                CANDIDATE_POSITION canp = db.CANDIDATE_POSITION.Find(cp.CandidateId);
                canp.ISActive = false;
                db.SaveChanges();
            }
        }
        public void AddCompanyaccount(RecrutmentSignupView rsv)
        {
            using (RecrutmentsysEntities db = new RecrutmentsysEntities())
            {
                COMPANY_REGISTER CR = new COMPANY_REGISTER();
                CR.ComapanyName   = rsv.ComapanyName;
                CR.CompanyEmail   = rsv.CompanyEmail;
                CR.CompanyContect = rsv.CompanyContect;
                CR.CompanyAddress = rsv.CompanyAddress;
                db.COMPANY_REGISTER.Add(CR);
                db.SaveChanges();


                //string password = RandomString(8);

                COMPANY_REGISTER_REFRENCES CRF = new COMPANY_REGISTER_REFRENCES();
                CRF.CompanyId       = CR.CompanyId;
                CRF.CompanyEmailRef = rsv.CompanyEmail;
                CRF.CompanyPassword = rsv.CompanyPassword;
                CRF.CompanyType     = "Admin";
                CRF.ConfirmedEmail  = false;
                db.COMPANY_REGISTER_REFRENCES.Add(CRF);
                db.SaveChanges();
                rsv.ComapnyrefId = CRF.ComapanyRefId;

                //using (MailMessage mm = new MailMessage())
                //{

                //    mm.To.Add(new MailAddress(rsv.CompanyEmail));
                //    mm.From = new MailAddress("*****@*****.**");
                //    mm.Subject = "Email confirmation !";
                //   // mm.Body = "This email create is company use of term and condition <br/> Your Email:- " + rsv.CompanyEmail + " <br/> you Password:-" + password + " ";
                //    mm.Body = string.Format("Dear {0}<BR/>Thank you for your registration, please click on the below link to complete your registration: <a href=\"{1}\" title=\"User Email Confirm\">{1}</a>", CR.ComapanyName, Url.Action("ConfirmEmail", "Account", new { Token = CRF.ComapanyRefId, Email = CRF.CompanyEmailRef }, Request.Url.Scheme));
                //    mm.IsBodyHtml = true;

                //    using (SmtpClient smtp = new SmtpClient())
                //    {
                //        smtp.Host = "smtp.gmail.com";
                //        smtp.EnableSsl = true;
                //        NetworkCredential networkcred = new NetworkCredential("*****@*****.**", "connectists@57confuse");
                //        smtp.UseDefaultCredentials = true;
                //        smtp.Credentials = networkcred;
                //        smtp.Port = 587;
                //        smtp.Send(mm);


                //    }
                //}
            }
        }
        public void Updatejobsdata(UsersJob UJ)
        {
            using (RecrutmentsysEntities db = new RecrutmentsysEntities())
            {
                //db.Database.Connection.Open();
                //using (var dbcontexttransection = db.Database.Connection.BeginTransaction())
                //{
                //    try
                //    {
                COMPANY_JOB_OPENING CJO = db.COMPANY_JOB_OPENING.Find(UJ.DepatmentID);
                CJO.DepartmentName           = UJ.DepartmentName;
                CJO.RequestedBy              = UJ.RequestedBy;
                CJO.Name_of_Vacancy          = UJ.Name_of_Vacancy;
                CJO.Number_of_Position       = UJ.Number_of_Position;
                CJO.Required_Technical_Skill = UJ.Required_Technical_Skill;
                CJO.Special_Technical_Skill  = UJ.Special_Technical_Skill;
                CJO.Min_Yearof_Experience    = UJ.Min_Yearof_Experience;
                CJO.Min_Qualification        = UJ.Min_Qualification;
                CJO.Deadline_Date            = UJ.Deadline_Date;
                db.SaveChanges();


                //    dbcontexttransection.Commit();
                //}
                //catch
                //{
                //    dbcontexttransection.Rollback();
                //}

                //}
            }
        }
        /////if the hr or particulaer person register.

        public void AddUseraccount(UserSignup US, string LoginName)
        {
            using (RecrutmentsysEntities db = new RecrutmentsysEntities())
            {
                COMPANY_REGISTER_REFRENCES CRF = db.COMPANY_REGISTER_REFRENCES.Where(o => o.CompanyEmailRef.Equals(LoginName)).FirstOrDefault();
                COMPANY_HR_REGISTER        CHR = new COMPANY_HR_REGISTER();
                CHR.CompanyId = CRF.CompanyId;
                CHR.HrName    = US.HrName;
                CHR.HrContact = US.HrContact;
                CHR.HrEmail   = US.HrEmail;

                db.COMPANY_HR_REGISTER.Add(CHR);
                db.SaveChanges();

                string password = RandomString(8);

                COMPANY_REGISTER_REFRENCES CRR = new COMPANY_REGISTER_REFRENCES();
                CRR.CompanyId       = CHR.CompanyId;
                CRR.CompanyEmailRef = US.HrEmail;
                CRR.CompanyPassword = password;
                CRR.CompanyType     = "Other";
                db.COMPANY_REGISTER_REFRENCES.Add(CRR);
                db.SaveChanges();

                using (MailMessage mm = new MailMessage())
                {
                    mm.To.Add(new MailAddress(US.HrEmail));
                    mm.From       = new MailAddress("*****@*****.**");
                    mm.Subject    = "Your Password Genrated for by Admin!";
                    mm.Body       = "This email create is company use of term and condition <br/> Your Email:- " + US.HrEmail + " <br/> you Password:-" + password + " ";
                    mm.IsBodyHtml = true;

                    using (SmtpClient smtp = new SmtpClient())
                    {
                        smtp.Host      = "smtp.gmail.com";
                        smtp.EnableSsl = true;
                        NetworkCredential networkcred = new NetworkCredential("*****@*****.**", "connectists@57confuse");
                        smtp.UseDefaultCredentials = true;
                        smtp.Credentials           = networkcred;
                        smtp.Port = 587;
                        smtp.Send(mm);
                    }
                }
            }
        }
 public void Fogot_to_new(forgetpassword FP, string mail, string token)
 {
     using (RecrutmentsysEntities db = new RecrutmentsysEntities())
     {
         COMPANY_REGISTER_REFRENCES crr = db.COMPANY_REGISTER_REFRENCES.Where(o => o.CompanyEmailRef.Equals(mail)).FirstOrDefault();
         crr.CompanyPassword = FP.newpassword;
         db.SaveChanges();
     }
 }
 public void approvalisactiveuser(candidatepostion can)
 {
     using (RecrutmentsysEntities db = new RecrutmentsysEntities())
     {
         CANDIDATE_POSITION cp = db.CANDIDATE_POSITION.Find(can.canid);
         cp.ISActive = can.Isactive;
         db.SaveChanges();
     }
 }
 //@@@@@@@********************* approval jobs
 public void approvaljob(UsersJob UJ)
 {
     using (RecrutmentsysEntities db = new RecrutmentsysEntities())
     {
         COMPANY_JOB_OPENING CJO = db.COMPANY_JOB_OPENING.Find(UJ.DepatmentID);
         CJO.Approval = UJ.Approval_admin;
         db.SaveChanges();
     }
 }
        public void DeleteJob(int depetid)
        {
            using (RecrutmentsysEntities db = new RecrutmentsysEntities())
            {
                var CJ = db.COMPANY_JOB_OPENING.Where(o => o.DepatmentID == depetid);

                if (CJ.Any())
                {
                    db.COMPANY_JOB_OPENING.Remove(CJ.FirstOrDefault());
                    db.SaveChanges();
                }

                var CJR = db.COMPANY_JOB_OPENING_REFRENCES.Where(o => o.Job_refrenceId == depetid);

                if (CJR.Any())
                {
                    db.COMPANY_JOB_OPENING_REFRENCES.Remove(CJR.FirstOrDefault());
                    db.SaveChanges();
                }
            }
        }
        // far to the new job opening

        public void AddnewjobIsopen(NewJobView NJV, string Loginname)
        {
            using (RecrutmentsysEntities db = new RecrutmentsysEntities())
            {
                COMPANY_HR_REGISTER CHR = db.COMPANY_HR_REGISTER.Where(o => o.HrEmail.Equals(Loginname)).FirstOrDefault();
                COMPANY_JOB_OPENING CJO = new COMPANY_JOB_OPENING();
                CJO.CompanyId                = Convert.ToInt32(CHR.CompanyId);
                CJO.HrId                     = CHR.HrId;
                CJO.DepartmentName           = NJV.DepartmentName;
                CJO.RequestedBy              = NJV.RequestedBy;
                CJO.HrEmail                  = Loginname;
                CJO.Name_of_Vacancy          = NJV.Name_of_Vacancy;
                CJO.Number_of_Position       = NJV.Number_of_Position;
                CJO.Required_Technical_Skill = NJV.Required_Technical_Skill;
                CJO.Special_Technical_Skill  = NJV.Special_Technical_Skill;
                CJO.Min_Yearof_Experience    = NJV.Min_Yearof_Experience;
                CJO.Min_Qualification        = NJV.Min_Qualification;
                CJO.Deadline_Date            = NJV.Deadline_Date;
                CJO.Requested_Date           = DateTime.Now;
                CJO.Approval                 = false;

                db.COMPANY_JOB_OPENING.Add(CJO);
                db.SaveChanges();

                COMPANY_JOB_OPENING_REFRENCES CJOR = new COMPANY_JOB_OPENING_REFRENCES();
                CJOR.CompanyId          = CJO.CompanyId;
                CJOR.HrId               = CJO.HrId;
                CJOR.DepartmentCode     = Convert.ToString(CJO.DepartmentCode);
                CJOR.Number_of_Position = CJO.Number_of_Position;
                CJOR.RowcreatedDate     = DateTime.Now;
                CJOR.RowModifiddate     = DateTime.Now;

                db.COMPANY_JOB_OPENING_REFRENCES.Add(CJOR);
                db.SaveChanges();
            }
        }
        public async Task <ActionResult> ConfirmEmail(string Token, string Email)
        {
            //ApplicationUser user = this.UserManager.FindById(Token);
            using (RecrutmentsysEntities db = new RecrutmentsysEntities())
            {
                //var user = from i in db.COMPANY_REGISTER_REFRENCES
                //           where i.ComapanyRefId == Convert.ToInt32(Token)
                //           select i.CompanyEmailRef;

                //var user=db.COMPANY_REGISTER_REFRENCES.Find(Token);
                COMPANY_REGISTER_REFRENCES CRF = db.COMPANY_REGISTER_REFRENCES.Find(Convert.ToInt32(Token));

                int CRFID = CRF.ComapanyRefId;

                if (CRFID != null)
                {
                    string mail = CRF.CompanyEmailRef;
                    if (mail == Email)
                    {
                        COMPANY_REGISTER_REFRENCES crr = db.COMPANY_REGISTER_REFRENCES.Find(Convert.ToInt32(Token));
                        crr.ConfirmedEmail = true;
                        db.SaveChanges();

                        var  istrue = db.COMPANY_REGISTER_REFRENCES.Where(o => o.CompanyEmailRef.Equals(mail));
                        bool check  = Convert.ToBoolean(istrue.FirstOrDefault().ConfirmedEmail);
                        if (check == true)
                        {
                            TempData["msg"] = "Account Created ! Please Login Here";
                            return(RedirectToAction("Login", "Account"));
                        }
                        else
                        {
                            return(RedirectToAction("Confirm", "Account", new { Email = mail }));
                        }

                        //return RedirectToAction("Index", "Home", new { ConfirmedEmail = mail });
                    }
                    else
                    {
                        return(RedirectToAction("Confirm", "Account", new { Email = mail }));
                    }
                }
                else
                {
                    return(RedirectToAction("Confirm", "Account", new { Email = "" }));
                }
            }
        }
 public void addcandidateposition(candidatepostion CP, string code)
 {
     using (RecrutmentsysEntities db = new RecrutmentsysEntities())
     {
         COMPANY_JOB_OPENING data = db.COMPANY_JOB_OPENING.Where(o => o.DepartmentCode == code).FirstOrDefault();
         if (data != null)
         {
             CANDIDATE_POSITION CANP = new CANDIDATE_POSITION();
             CANP.CompanyId         = data.CompanyId;
             CANP.DepartmentCode    = data.DepartmentCode;
             CANP.DepartmentName    = data.DepartmentName;
             CANP.HrId              = data.HrId;
             CANP.CandidateEmail    = CP.email;
             CANP.Candidate_Yof_exp = CP.year_of_experience;
             CANP.ISActive          = false;
             db.CANDIDATE_POSITION.Add(CANP);
             db.SaveChanges();
         }
     }
 }