Пример #1
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            using (TpsDbContext tps = new TpsDbContext()) {
                StaffRequest request = new StaffRequest();
                request.ContractID = int.Parse(ContractDropDownList.SelectedValue);

                int[] chosenStaff = (int[])ViewState["ChosenStaff"];
                for (int i = 0; i < chosenStaff.Length; i++)
                {
                    int id = chosenStaff[i];
                    if (id == 0)
                    {
                        continue;
                    }
                    if (i == 0)
                    {
                        request.Staff1 = tps.Users.Where(u => u.UserID == id).Single();
                    }
                    else if (i == 1)
                    {
                        request.Staff2 = tps.Users.Where(u => u.UserID == id).Single();
                    }
                    else if (i == 2)
                    {
                        request.Staff3 = tps.Users.Where(u => u.UserID == id).Single();
                    }
                }

                tps.Requests.Add(request);
                tps.SaveChanges();
            }

            Response.Redirect("~/MyStaffingRequests.aspx");
        }
Пример #2
0
        private void RefreshChosenStaffGridView()
        {
            int[] chosenStaff = (int[])ViewState["ChosenStaff"];

            using (TpsDbContext tps = new TpsDbContext()) {
                bool            atLeastOne      = false; // Indicates whether we have at least one staffer chosen
                List <UserInfo> chosenStaffList = new List <UserInfo>();

                for (int i = 0; i < chosenStaff.Length; i++)
                {
                    int id = chosenStaff[i];
                    if (chosenStaff[i] > 0)
                    {
                        atLeastOne = true;
                        chosenStaffList.Add(tps.Users.Where(u => u.UserID == id).Single());
                    }
                }

                if (atLeastOne)
                {
                    InstructionLabel.Visible = false;
                    SubmitButton.Enabled     = true;
                }
                else
                {
                    InstructionLabel.Visible = true;
                    SubmitButton.Enabled     = false;
                }

                ChosenStaffGridView.DataSource = chosenStaffList;
                ChosenStaffGridView.DataBind();
            }
        }
Пример #3
0
        protected void NewContractDetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            // Set the contract's manager to the logged-in user
            TpsDbContext tps     = new TpsDbContext();
            UserInfo     manager = (from u in tps.Users where u.Email == User.Identity.Name select u).Single();

            e.Values["Manager.UserID"] = manager.UserID;
        }
Пример #4
0
 protected void UsersDataSource_Deleting(object sender, EntityDataSourceChangingEventArgs e)
 {
     // Delete the user's contracts
     using (TpsDbContext tps = new TpsDbContext()) {
         UserInfo user = tps.Users.Where(u => u.UserID == ((UserInfo)e.Entity).UserID).Single();
         user.ManagedContracts.ToList().ForEach(c => tps.Contracts.Remove(c));
         user.HeldContracts.ToList().ForEach(c => tps.Contracts.Remove(c));
         tps.SaveChanges();
     }
 }
Пример #5
0
        protected void NewContractDetailsView_DataBound(object sender, EventArgs e)
        {
            // Populate the client list
            DropDownList clientDropDownList = (DropDownList)NewContractDetailsView.FindControl("NewContractClientDropDownList");
            TpsDbContext tps = new TpsDbContext();

            foreach (UserInfo client in (from u in tps.Users where u.SecurityRole == "Client" select u))
            {
                clientDropDownList.Items.Add(new ListItem(client.ToString(), client.UserID.ToString()));
            }
        }
Пример #6
0
        protected void HandleAuthenticate(object sender, AuthenticateEventArgs e)
        {
            TpsDbContext tps  = new TpsDbContext();
            UserInfo     user = UserInfo.Authenticate(UserLogin.UserName, UserLogin.Password);

            if (user != null)
            {
                e.Authenticated = true;
                FormsAuthenticationEx.RedirectFromLoginPage(UserLogin.UserName, user.SecurityRole, UserLogin.RememberMeSet);
            }
            else
            {
                e.Authenticated = false;
            }
        }
Пример #7
0
        protected void RequestsGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            DropDownList staffDropDownList = (DropDownList)RequestsGridView.Rows[e.RowIndex].FindControl("StaffDropDownList");

            using (TpsDbContext tps = new TpsDbContext()) {
                int          requestId = (int)e.Keys[0];
                StaffRequest request   = tps.Requests.Where(r => r.RequestID == requestId).Single();

                if (staffDropDownList.SelectedValue == "0")
                {
                    request.Status = "Denied";
                }
                else
                {
                    int staffId = int.Parse(staffDropDownList.SelectedValue);
                    request.Status         = "Approved";
                    request.Contract.Staff = tps.Users.Where(u => u.UserID == staffId).Single();
                }

                tps.SaveChanges();
            }
        }
Пример #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            FormsAuthenticationEx.RedirectIfUserNotInRole("~/Default.aspx", "Client");

            if (!IsPostBack)
            {
                ViewState["ChosenStaff"] = new int[] { 0, 0, 0 };

                using (TpsDbContext tps = new TpsDbContext()) {
                    foreach (var contract in tps.Contracts.Where(c => c.Client.Email == User.Identity.Name))
                    {
                        ContractDropDownList.Items.Add(new ListItem(string.Format("{0} ({1} - {2})",
                                                                                  contract.Position, contract.StartDate.ToShortDateString(), contract.EndDate.ToShortDateString()),
                                                                    contract.ContractID.ToString()));
                    }

                    if (ContractDropDownList.Items.Count == 0)
                    {
                        NoContractsLabel.Visible = true;
                        FormPanel.Visible        = false;
                    }
                }
            }
        }
Пример #9
0
        protected void SearchButton_Click(object sender, EventArgs e)
        {
            decimal maxSalary = 0;

            decimal.TryParse(SalaryTextBox.Text, out maxSalary);

            using (TpsDbContext tps = new TpsDbContext()) {
                var staff = tps.Users.Where(u => u.SecurityRole == "Staff");

                if (JobCategoryDropDownList.SelectedValue != "Any")
                {
                    staff = staff.Where(u => u.DesiredJobCategory == JobCategoryDropDownList.SelectedValue);
                }

                if (maxSalary > 0)
                {
                    staff = staff.Where(u => u.DesiredSalary <= maxSalary);
                }

                if (!string.IsNullOrWhiteSpace(CityTextBox.Text))
                {
                    staff = staff.Where(u => u.City.ToUpper() == CityTextBox.Text.ToUpper());
                }

                if (!string.IsNullOrWhiteSpace(StateTextBox.Text))
                {
                    staff = staff.Where(u => u.State.ToUpper() == StateTextBox.Text.ToUpper());
                }

                if (RelocateCheckBox.Checked)
                {
                    staff = staff.Where(u => u.CanRelocate == true);
                }

                var staffList = staff.ToList();

                staffList.RemoveAll(s => {
                    // This is so horrible, but just go with it
                    if (EducationLevelDropDownList.SelectedValue == "High School")
                    {
                        return(false);
                    }
                    if (EducationLevelDropDownList.SelectedValue == "Some College" && s.EducationLevel != "High School")
                    {
                        return(false);
                    }
                    if (EducationLevelDropDownList.SelectedValue == "Undergraduate" &&
                        (s.EducationLevel != "Some College" && s.EducationLevel != "High School"))
                    {
                        return(false);
                    }
                    if (EducationLevelDropDownList.SelectedValue == "Graduate" && s.EducationLevel == "Graduate")
                    {
                        return(false);
                    }
                    return(true);
                });

                SearchResultsGridView.DataSource = staffList;
                SearchResultsGridView.DataBind();
            }
        }