Пример #1
0
        public void UpdateMethodOk()
        {
            clsStaffMemberCollection AllStaffMembers = new clsStaffMemberCollection();
            clsStaffMember           TestItem        = new clsStaffMember();
            Int32 primaryKey = 0;

            TestItem.UserId                 = 2;
            TestItem.PrivilegeLevelId       = 1;
            TestItem.FirstName              = "Peter";
            TestItem.LastName               = "Jackson";
            TestItem.Confirmed              = true;
            TestItem.Allowed                = true;
            AllStaffMembers.ThisStaffMember = TestItem;
            primaryKey             = AllStaffMembers.Add();
            TestItem.StaffMemberId = primaryKey;

            TestItem.UserId                 = 2;
            TestItem.PrivilegeLevelId       = 1;
            TestItem.FirstName              = "Pete";
            TestItem.LastName               = "Jacson";
            TestItem.Confirmed              = false;
            TestItem.Allowed                = false;
            AllStaffMembers.ThisStaffMember = TestItem;
            AllStaffMembers.Update();
            AllStaffMembers.ThisStaffMember.Find(primaryKey);
            Assert.AreEqual(AllStaffMembers.ThisStaffMember, TestItem);
        }
        protected void grdAllStaffMembers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Int32   staffMemberId    = Convert.ToInt32(((Label)grdAllStaffMembers.Rows[e.RowIndex].FindControl("lblStaffMemberId")).Text);
            Int32   privilegeLevelId = Convert.ToInt32(((TextBox)grdAllStaffMembers.Rows[e.RowIndex].FindControl("txtPrivilegeLevelId")).Text);
            string  firstName        = ((TextBox)grdAllStaffMembers.Rows[e.RowIndex].FindControl("txtFirstName")).Text;
            string  lastName         = ((TextBox)grdAllStaffMembers.Rows[e.RowIndex].FindControl("txtLastName")).Text;
            Boolean allowed          = ((CheckBox)grdAllStaffMembers.Rows[e.RowIndex].FindControl("chkAllowed")).Checked;

            clsStaffMemberCollection AllStaffMembers = new clsStaffMemberCollection();

            var staffMemberCheck = AllStaffMembers.ThisStaffMember.Valid(firstName, lastName);

            if (staffMemberCheck.Count != 0)
            {
                foreach (string error in staffMemberCheck)
                {
                    Label lbl1 = new Label();
                    lbl1.Text = error;
                    //Panel1.Controls.Add(lbl1);
                }
            }
            else
            {
                AllStaffMembers.ThisStaffMember.StaffMemberId    = staffMemberId;
                AllStaffMembers.ThisStaffMember.PrivilegeLevelId = privilegeLevelId;
                AllStaffMembers.ThisStaffMember.FirstName        = firstName;
                AllStaffMembers.ThisStaffMember.LastName         = lastName;
                AllStaffMembers.ThisStaffMember.Allowed          = allowed;

                AllStaffMembers.Update();

                grdAllStaffMembers.EditIndex = -1;
                LoadStaffMemberData();
            }
        }
        protected void btnRegisterStaffMember_Click(object sender, EventArgs e)
        {
            bool    editStaffMember  = Convert.ToBoolean(Session["editStaffMember"]);
            string  firstName        = txtNewStaffMemberFirstName.Text;
            string  lastName         = txtNewStaffMemberLastName.Text;
            Int32   userId           = Convert.ToInt32(ddlUserId.SelectedItem.Value);
            Int32   privilegeLevelId = Convert.ToInt32(ddlPrivilegelevel.SelectedValue);
            Boolean suspended        = chkStaffMemberSuspended.Checked;

            clsStaffMemberCollection AllStaffMembers = new clsStaffMemberCollection();

            AllStaffMembers.ThisStaffMember.StaffMemberId    = Convert.ToInt32(Session["StaffMemberId"]);
            AllStaffMembers.ThisStaffMember.UserId           = userId;
            AllStaffMembers.ThisStaffMember.PrivilegeLevelId = privilegeLevelId;
            AllStaffMembers.ThisStaffMember.FirstName        = firstName;
            AllStaffMembers.ThisStaffMember.LastName         = lastName;
            AllStaffMembers.ThisStaffMember.Allowed          = suspended;

            if (editStaffMember)
            {
                userId = Convert.ToInt32(Session["UserId"]);
            }

            var      manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var      user    = manager.FindById(userId);
            clsEmail AnEmail = new clsEmail(user.Email);

            if (editStaffMember)
            {
                if (suspended)
                {
                    DateTime suspendedEndDate = DateTime.Now.AddDays(3);
                    AnEmail.SendUserSuspensionEmail(suspendedEndDate);
                    user.LockoutEnabled    = true;
                    user.LockoutEndDateUtc = suspendedEndDate;
                    manager.Update(user);
                }
                if (privilegeLevelId != originalPrivilegeLevel)
                {
                    AnEmail.SendStaffMemberPrivilegeChangeEmail();
                }
                AllStaffMembers.Update();
            }
            else
            {
                AllStaffMembers.Add();
                AnEmail.SendNewStaffMemberStandardNoticeEmail();
            }

            grdAllStaffMembers.EditIndex = -1;

            pnlNewStaffMember.Visible = false;
            LoadStaffMemberData();
        }