Exemplo n.º 1
0
    /// <summary>
    /// Button click method for dealing with the user administration section.
    /// Behavior changes depending on the selected radio button option
    /// Create: Button click creates a new users depending on entered details
    /// Edit: Button click edits selected user depending on details as changed or shown
    /// Shows a completion overlay on success
    /// </summary>
    /// <param name="sender">not used in our code</param>
    /// <param name="e">not used in our code</param>
    protected void btnUserNew_Click(object sender, EventArgs e)
    {
        switch (rblUsers.SelectedValue)
        {
        case "Create":
            if (Page.IsValid)
            {
                BCCAModel.User u = new BCCAModel.User()
                {
                    userName = tbUsername.Text,
                    password = ASP.global_asax.Hash_Password(tbPassword.Text),
                    roleNo   = Convert.ToInt32(rblUserRole.SelectedValue),
                    deptNo   = (!(ddlDepartments.SelectedValue == "") ? Convert.ToInt32(ddlDepartments.SelectedValue) : (int?)null)
                };

                try
                {
                    ctx.AddToUsers(u);
                    ctx.SaveChanges();
                }
                catch (Exception ex)
                {
                    Popup_Overlay(ex.Message, Color.Red);
                    return;
                }
                User_Pass_Clear();
                Popup_Overlay("User succesfully added.", Color.Green);
                lbxUsers.DataBind();
            }
            break;

        case "Edit":
            int            userNo = Convert.ToInt32(tbUsernameID.Text);
            BCCAModel.User user   = ctx.Users
                                    .Select(us => us)
                                    .Where(us => us.userNo == userNo)
                                    .First();
            user.password = ASP.global_asax.Hash_Password(tbPassword.Text);
            try
            {
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                Popup_Overlay(ex.Message, Color.Red);
                return;
            }
            Popup_Overlay("User's password changed.", Color.Green);
            break;

        default:
            throw new System.SystemException("Default case of switch should never be reached");
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Deletes the user that is currently selected in the listbox from the System using the ID
    /// in the hidden text box.
    /// </summary>
    /// <param name="sender">not used in our system</param>
    /// <param name="e">not used in our system</param>
    protected void btnUserDelete_Click(object sender, EventArgs e)
    {
        int userNo = Convert.ToInt32(tbUsernameID.Text);

        BCCAModel.User user = ctx.Users
                              .Select(us => us)
                              .Where(us => us.userNo == userNo)
                              .First();
        try
        {
            ctx.DeleteObject(user);
            ctx.SaveChanges();
        }
        catch (Exception ex)
        {
            Popup_Overlay(ex.Message, Color.Red);
            return;
        }
        Popup_Overlay("User successfully deleted.", Color.Green);
        lbxUsers.DataBind();
    }
Exemplo n.º 3
0
    /// <summary>
    /// Button click method for dealing with the user administration section.
    /// Behavior changes depending on the selected radio button option
    /// Create: Button click creates a new users depending on entered details
    /// Edit: Button click edits selected user depending on details as changed or shown
    /// Shows a completion overlay on success
    /// </summary>
    /// <param name="sender">not used in our code</param>
    /// <param name="e">not used in our code</param>
    protected void btnUserNew_Click(object sender, EventArgs e)
    {
        switch (rblUsers.SelectedValue)
        {
            case "Create":
                if (Page.IsValid)
                {
                    BCCAModel.User u = new BCCAModel.User()
                    {
                        userName = tbUsername.Text,
                        password = ASP.global_asax.Hash_Password(tbPassword.Text),
                        roleNo = Convert.ToInt32(rblUserRole.SelectedValue),
                        deptNo = (!(ddlDepartments.SelectedValue == "") ? Convert.ToInt32(ddlDepartments.SelectedValue) : (int?)null)
                    };

                    try
                    {
                        ctx.AddToUsers(u);
                        ctx.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Popup_Overlay(ex.Message, Color.Red);
                        return;
                    }
                    User_Pass_Clear();
                    Popup_Overlay("User succesfully added.", Color.Green);
                    lbxUsers.DataBind();
                }
                break;
            case "Edit":
                int userNo = Convert.ToInt32(tbUsernameID.Text);
                BCCAModel.User user = ctx.Users
                    .Select(us => us)
                    .Where(us => us.userNo == userNo)
                    .First();
                user.password = ASP.global_asax.Hash_Password(tbPassword.Text);
                try
                {
                    ctx.SaveChanges();
                }
                catch (Exception ex)
                {
                    Popup_Overlay(ex.Message, Color.Red);
                    return;
                }
                Popup_Overlay("User's password changed.", Color.Green);
                break;
            default:
                throw new System.SystemException("Default case of switch should never be reached");
        }
    }