Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string currentPageFileName = new FileInfo(this.Request.Url.AbsolutePath).Name;

            var PermMgr = new PermissionManager(Session);

            if (PermMgr.IsAdmin || PermMgr.CanManageTestBatches)
            {
                if (!IsPostBack)
                {
                    //Bind Active Batch DropDownList
                    var activeBatches = _db.T_Batch.Where(s => (s.BatchType == ErecruitHelper.BatchType.Multiple.ToString() || s.BatchType == null) && s.IsActive.Value == true).ToList();
                    Batches.DataSource = activeBatches;
                    if (Session["ToBeSelected"] != null)
                    {
                        Batches.SelectedIndex = int.Parse(Session["ToBeSelected"].ToString());
                    }
                    Batches.DataBind();

                    //Bind Active Candidate ListBox
                    var cands = _db.T_Candidate.Where(s => s.ApprovalStatus == ErecruitHelper.ApprovalStatus.APPROVED.ToString() && s.IsActive.Value == true).Select(a => new CandidateDropDownModel
                    {
                        ID   = a.Id,
                        Name = a.Code + " - " + a.LastName + " " + a.FirstName
                    }).ToList();
                    ActiveCandidateList.DataSource = cands;
                    ActiveCandidateList.DataBind();

                    //Bind Active Batch Content ListBox

                    var x             = string.IsNullOrEmpty(Batches.SelectedValue) ? "0" : Batches.SelectedValue;
                    var selectedBatch = long.Parse(x);
                    var batch         = new T_Batch();
                    if (selectedBatch == 0)
                    {
                        batch = new T_Batch
                        {
                            Id   = 0,
                            Name = "No Active batch."
                        };
                    }
                    else
                    {
                        batch = _db.T_Batch.FirstOrDefault(s => s.Id == selectedBatch);
                    }

                    List <BatchContentDropDownModel> activeContent = _db.T_BatchSet.Where(s => s.BatchId == selectedBatch).Select(a => new BatchContentDropDownModel
                    {
                        ID   = a.CandidateId.Value,
                        Name = _db.T_Candidate.FirstOrDefault(s => s.Id == a.CandidateId).Code + " - " + _db.T_Candidate.FirstOrDefault(s => s.Id == a.CandidateId).FirstName + " " + _db.T_Candidate.FirstOrDefault(s => s.Id == a.CandidateId).LastName
                    }).ToList();

                    if (activeContent.Count > 0)
                    {
                        ActiveContentList.DataSource = activeContent;
                        ActiveContentList.DataBind();
                        SendInvite.Enabled = true;
                    }
                    else
                    {
                        activeContent = new List <BatchContentDropDownModel>();
                        activeContent.Add(new BatchContentDropDownModel
                        {
                            ID   = 0,
                            Name = "---" + batch.Name + " is Empty---"
                        });
                        ActiveContentList.DataSource = activeContent;
                        ActiveContentList.DataBind();
                        SendInvite.Enabled = false;
                    }

                    //Bind DropDownList1 ListBox
                    var cs = _db.T_Candidate.Where(s => s.ApprovalStatus == ErecruitHelper.ApprovalStatus.APPROVED.ToString() && s.IsActive.Value == true).Select(a => new CandidateDropDownModel
                    {
                        ID   = a.Id,
                        Name = a.Code + " - " + a.LastName + " " + a.FirstName
                    }).ToList();
                    DropDownList1.DataSource = cs;
                    DropDownList1.DataBind();
                }
            }
            else
            {
                Response.Redirect("NoPermission.aspx", false);
            }
        }
Пример #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                var sb = Batches.SelectedValue;
                if (string.IsNullOrEmpty(sb))
                {
                    return;
                }
                var selectedBatch = long.Parse(Batches.SelectedValue);
                var selectedIndex = Batches.SelectedIndex;
                var batch         = _db.T_Batch.FirstOrDefault(s => s.Id == selectedBatch);

                int[] selectedCandidates = ActiveCandidateList.GetSelectedIndices();
                var   contentIds         = new List <int>();
                var   cids = selectedCandidates.Select(i => int.Parse(ActiveCandidateList.Items[i].Value)).ToList();

                foreach (int x in cids)
                {
                    if (x == 0)
                    {
                    }
                    else
                    {
                        contentIds.Add(x);
                    }
                }
                foreach (int x in contentIds)
                {
                    var            x1           = x;
                    var            hasActive    = false;
                    var            prevBatchSet = _db.T_BatchSet.Where(s => s.CandidateId == x1).Select(s => s.BatchId);
                    List <T_Batch> prevBatch    = null;
                    if (prevBatchSet.Any())
                    {
                        prevBatch = _db.T_Batch.Where(s => prevBatchSet.Contains(s.Id)).ToList();
                    }
                    if (prevBatch != null && prevBatch.Count > 0)
                    {
                        foreach (var batch1 in prevBatch)
                        {
                            if (batch1.IsActive == true)
                            {
                                hasActive = true;
                            }
                        }
                    }
                    if (hasActive)
                    {
                        //Session["Status"] = "";
                    }
                    else
                    {
                        var existing = _db.T_BatchSet.FirstOrDefault(s => s.BatchId == batch.Id && s.CandidateId == x);

                        if (existing == null)
                        {
                            if (batch != null)
                            {
                                _db.T_BatchSet.Add(new T_BatchSet
                                {
                                    CandidateId = x,
                                    BatchId     = batch.Id,
                                    Finished    = false,
                                    IsLive      = false
                                });
                            }
                        }
                    }
                }

                _db.SaveChanges();
                Session["ToBeSelected"] = selectedIndex;

                Response.Redirect("AddCandidateToBatch.aspx", false);
            }
            catch (Exception ex)
            {
                ErecruitHelper.SetErrorData(ex, Session);
                Response.Redirect("ErrorPage.aspx", false);
            }
        }