Пример #1
0
    protected void Insert(object sender, EventArgs e)
    {
        var newEmployee = new Employee { FirstName = txtFirstNameAdd.Text, Surname = txtSurnameAdd.Text };

        var da = new EmployeeDataAccess();
        da.AddEmployee(newEmployee);
        da.SaveChanges();

        var hubContext = GlobalHost.ConnectionManager.GetHubContext<StatusHub>();
        hubContext.Clients.All.broadcastMessage("New employee added! (This is a push message from Signal-R, open other web clients and you will receive this message on both clients.)");

        txtFirstNameAdd.Text = String.Empty;
        txtSurnameAdd.Text = String.Empty;

        this.BindGrid();
    }
Пример #2
0
    protected void AddItem(object sender, ImageClickEventArgs e)
    {
        var imageButton = (ImageButton)sender;
        if (imageButton == null) return;
        var repeater = imageButton.Parent;
        var ddl = (DropDownList)repeater.FindControl("ddlRoles");
        if (ddl == null) return;
        var selectedItem = ddl.SelectedItem;
        if (selectedItem == null) return;

        var employeeDataAccess = new EmployeeDataAccess();
        var employees = employeeDataAccess.GetEmployees();
        var employee = employees[employeeGridView.EditIndex];

        var daRoles = new RoleDataAccess();
        var role = daRoles.GetRole(selectedItem.Value);

        var daEmployeeRoles = new EmployeeRoleDataAccess();
        daEmployeeRoles.AddRole(employee.EmployeeId, role.RoleId);
        daEmployeeRoles.SaveChanges();
        this.BindGrid();
    }
Пример #3
0
    protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int employeeId = Convert.ToInt32(employeeGridView.DataKeys[e.RowIndex].Values[0]);

        var da = new EmployeeDataAccess();
        var employee = da.GetEmployees().FirstOrDefault(emp => emp.EmployeeId == employeeId);
        da.RemoveEmployee(employee);
        da.SaveChanges();

        this.BindGrid();
    }
Пример #4
0
 private void BindGrid()
 {
     var da = new EmployeeDataAccess();
     employeeGridView.DataSource = da.GetEmployees();
     employeeGridView.DataBind();
 }
Пример #5
0
    protected void RemoveItem(object sender, ImageClickEventArgs e)
    {
        var imageButton = (ImageButton)sender;
        if (imageButton == null) return;
        var panel = (Panel)imageButton.Parent;
        if (panel == null) return;
        var roleLabel = (Label)panel.FindControl("Label1");
        if (roleLabel == null) return;

        var employeeDataAccess = new EmployeeDataAccess();
        var employees = employeeDataAccess.GetEmployees();
        var employee = employees[employeeGridView.EditIndex];

        var daRoles = new RoleDataAccess();
        var role = daRoles.GetRole(roleLabel.Text);

        var daEmployeeRoles = new EmployeeRoleDataAccess();
        daEmployeeRoles.RemoveRole(employee, role);
        daEmployeeRoles.SaveChanges();

        Roles.Add(role.Role1);
        this.BindGrid();
    }
Пример #6
0
    protected void OnRowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int employeeId = Convert.ToInt32(employeeGridView.DataKeys[e.RowIndex].Values[0]);

        GridViewRow row = employeeGridView.Rows[e.RowIndex];
        string firstname = (row.FindControl("txtFirstName") as TextBox).Text;
        string surname = (row.FindControl("txtSurname") as TextBox).Text;

        var da = new EmployeeDataAccess();
        var employee = da.GetEmployees().First(emp => emp.EmployeeId == employeeId);
        employee.FirstName = firstname;
        employee.Surname = surname;
        da.SaveChanges();

        employeeGridView.EditIndex = -1;
        this.BindGrid();
    }
Пример #7
0
 public List<string> GetEmployees()
 {
     var da = new EmployeeDataAccess(_connectionUtil.GetConnectionString(1));
     return da.GetEmployees().Select(e => string.Format("{0} {1}", e.FirstName, e.Surname)).ToList();
 }