public static void ReleaseResultToDB(ResultModel resultModel, User user)
        {
            SqlConnection con = DBUtils.getDBConnection();
            con.Open();
            SqlCommand command;

            List<CandidateResult> selectedCandidates = new List<CandidateResult>();
            int count = 0;
            foreach (var item in resultModel.Candidates)
            {
                if (item.IsSelected)
                {
                    selectedCandidates.Add(item);
                    count++;

                    command = new SqlCommand("UPDATE Application SET status_code='S', status='Selected' WHERE candidate_id=" + item.UserID + " ;", con);
                    command.ExecuteNonQuery();

                    command = new SqlCommand("UPDATE Users SET state='Selected' WHERE user_id=" + item.UserID + " ;", con);
                    command.ExecuteNonQuery();
                }
                else
                {
                    command = new SqlCommand("UPDATE Application SET status_code='R', status='Rejected' WHERE candidate_id=" + item.UserID + " ;", con);
                    command.ExecuteNonQuery();

                    command = new SqlCommand("UPDATE Users SET state='Blocked', account_act_date='"+DateTime.Now.AddDays(90).ToShortDateString()+"' WHERE user_id=" + item.UserID + " ;", con);
                    command.ExecuteNonQuery();
                }
            }
            resultModel.numOfCandidatesSelected = count;

            string selectedCandidatesSet = String.Join(",", selectedCandidates.Select(x => x.UserID.ToString()).ToArray());
            command = new SqlCommand("INSERT INTO dbo.Results (job_id, declaration_date, num_of_candidates_selected, candidates, released_by) values (" + resultModel.JobId + ", '" + DateTime.Now.ToShortDateString() + "', " + resultModel.numOfCandidatesSelected + ", '" + selectedCandidatesSet + "', " + user.user_id + " );", con);
            command.ExecuteNonQuery();

            command = new SqlCommand("UPDATE Job SET status='R' WHERE job_id=" + resultModel.JobId + " ;", con);
            command.ExecuteNonQuery();

            con.Close();
        }
 public ActionResult ReleaseResults(ResultModel resultModel)
 {
     if (!Navigator.IsUserLoggedIn(Session))
     {
         @ViewBag.Message = "Sorry! You need to login to view this page.";
         return View("Message");
         //return RedirectToAction("Login", "Account");
     }
     else if (!Navigator.UserRoleValidation(Session, "manager"))
     {
         @ViewBag.Message = "Access Denied !   You are not allowed to visit this page.";
         return View("Message");
         //return RedirectToAction("Login", "Account");
     }
     User user = ((User)Session["user"]);
     ASCommonDAL.ReleaseResultToDB(resultModel, user);
     @ViewBag.Layout = "~/Views/Shared/_LayoutPageManager.cshtml";
     @ViewBag.Message = "Result Released for Job - [" + resultModel.JobId + "] " + resultModel.JobDesc + ".";
     return View("Message");
 }
 public ActionResult ReleaseResultsDialog(JobModel jobModel)
 {
     if (!Navigator.IsUserLoggedIn(Session))
     {
         @ViewBag.Message = "Sorry! You need to login to view this page.";
         return View("Message");
         //return RedirectToAction("Login", "Account");
     }
     else if (!Navigator.UserRoleValidation(Session, "manager"))
     {
         @ViewBag.Message = "Access Denied !   You are not allowed to visit this page.";
         return View("Message");
         //return RedirectToAction("Login", "Account");
     }
     ResultModel model = new ResultModel();
     model.JobId = jobModel.JobId;
     model.JobDesc = jobModel.JobDesc;
     model.Vacancies = jobModel.Vacancies;
     model.Candidates = ASCommonDAL.GetApplicantForTheJob(jobModel.JobId);
     @ViewBag.Layout = "~/Views/Shared/_LayoutPageManager.cshtml";
     @ViewBag.Controller = "Admin";
     return PartialView("../Staff/_PartialReleaseResults", model);
 }
        public ActionResult ReleaseResultsDialog(JobModel jobModel)
        {
            if (!Navigator.IsUserLoggedIn(Session))
            {
                @ViewBag.Message = "Sorry! You need to login to continue.";
                return PartialView("_PartialMessage");
                //return RedirectToAction("Login", "Account");
            }
            else if (!Navigator.UserRoleValidation(Session, "staff"))
            {
                @ViewBag.Message = "Access Denied !   You are not allowed to continue.";
                return PartialView("_PartialMessage");
                //return RedirectToAction("Login", "Account");
            }
            else if (!Navigator.IsStaffAllowed(Session, "RightToPublish"))
            {
                @ViewBag.Message = "User Rights Denied! You don't have permission for this.";
                return PartialView("_PartialMessage");
                //return RedirectToAction("Login", "Account");
            }

            ResultModel model = new ResultModel();
            model.JobId = jobModel.JobId;
            model.JobDesc = jobModel.JobDesc;
            model.Vacancies = jobModel.Vacancies;
            model.Candidates = ASCommonDAL.GetApplicantForTheJob(jobModel.JobId);
            @ViewBag.Layout = "~/Views/Shared/_LayoutPageStaff.cshtml";
            @ViewBag.Controller = "Staff";
            return PartialView("_PartialReleaseResults", model);
        }