Beispiel #1
0
        private void CreateRecord(string userName, string password, string email, string firstName, string lastName, int?companyID, int?functionalAreaID, Boolean?isManager, Boolean?isExecutive, Boolean?isLockedOut)
        {
            MembershipCreateStatus status = WebSecurity.Register(userName, password, email, true, firstName, lastName, companyID == 0 ? null : companyID, functionalAreaID == 0 ? null : functionalAreaID, isManager, isExecutive);

            if (status == MembershipCreateStatus.Success)
            {
                WebSecurity.LockUser(userName, (bool)isLockedOut);

                if (ddlMembershipRole.SelectedValue.Equals("0"))
                {
                    System.Web.Security.Roles.AddUserToRole(userName, "User");
                }
                else
                {
                    System.Web.Security.Roles.AddUserToRole(userName, ddlMembershipRole.SelectedItem.Text);
                }

                GridView           gv       = ProductionUnitGrid.GetGridView();
                CheckBox           selected = null;
                HiddenField        pid      = null;
                UserProductionUnit upu      = null;
                Guid userId = WebSecurity.GetUserId(userName);

                using (var db = new Models.SmizeeContext())
                {
                    foreach (GridViewRow currentRow in gv.Rows)
                    {
                        selected = currentRow.FindControl("SelectRowCheckBox") as CheckBox;
                        if (selected.Checked)
                        {
                            pid                  = currentRow.FindControl("ProductionUnitIDHidden") as HiddenField;
                            upu                  = new UserProductionUnit();
                            upu.UserID           = userId;
                            upu.ProductionUnitID = int.Parse(pid.Value);
                            db.UserProductionUnits.Add(upu);
                        }
                    }
                    db.SaveChanges();
                }

                BackPanel.Visible          = true;
                ConfirmButtonPanel.Visible = false;
                DetailPanel.Visible        = false;
                ShowInfo(MessagePanel, Resources.Resource.mUserCreateOK);
            }
            else
            {
                ShowError(ErrorPanel, status.ToString());
            }
        }
Beispiel #2
0
        private void UpdateRecord(string userName, string password, string email, string firstName, string lastName, int?companyID, int?functionalAreaID, Boolean?isManager, Boolean?isExecutive, Boolean?isLockedOut)
        {
            //Query the database for the rows to be deleted.
            using (var db = new Models.SmizeeContext())
            {
                var myItem = (from c in db.Users where c.Username == userName select c).First();
                if (myItem != null)
                {
                    myItem.FirstName        = firstName;
                    myItem.LastName         = lastName;
                    myItem.Email            = email;
                    myItem.CompanyID        = companyID;
                    myItem.FunctionalAreaID = functionalAreaID;
                    myItem.IsManager        = isManager;
                    myItem.IsExecutive      = isExecutive;
                    db.SaveChanges();
                }

                WebSecurity.LockUser(userName, (bool)isLockedOut);

                string roleName = CurrentRoleNameHidden.Value;
                if (!string.IsNullOrEmpty(roleName))
                {
                    System.Web.Security.Roles.RemoveUserFromRole(userName, roleName);
                }

                if (ddlMembershipRole.SelectedValue.Equals("0"))
                {
                    System.Web.Security.Roles.AddUserToRole(userName, "User");
                }
                else
                {
                    System.Web.Security.Roles.AddUserToRole(userName, ddlMembershipRole.SelectedItem.Text);
                }

                // remove all country export records associated to the current formId
                CxUserProductionUnit.Delete(myItem.UserId);

                GridView           gv       = ProductionUnitGrid.GetGridView();
                CheckBox           selected = null;
                HiddenField        pid      = null;
                UserProductionUnit upu      = null;
                Guid userId = WebSecurity.GetUserId(userName);

                foreach (GridViewRow currentRow in gv.Rows)
                {
                    selected = currentRow.FindControl("SelectRowCheckBox") as CheckBox;
                    if (selected.Checked)
                    {
                        pid                  = currentRow.FindControl("ProductionUnitIDHidden") as HiddenField;
                        upu                  = new UserProductionUnit();
                        upu.UserID           = userId;
                        upu.ProductionUnitID = int.Parse(pid.Value);
                        db.UserProductionUnits.Add(upu);
                    }
                }
                db.SaveChanges();
            }

            BackPanel.Visible          = true;
            ConfirmButtonPanel.Visible = false;
            DetailPanel.Visible        = false;
            ShowInfo(MessagePanel, Resources.Resource.mUserUpdateOK);
        }