partial void DeleteUser(User instance);
 partial void InsertUser(User instance);
 partial void UpdateUser(User instance);
		private void attach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Profile = this;
		}
		private void detach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Profile = null;
		}
    private User SaveUser()
    {
        //
        // cria o objeto usuário que irá receber os dados vindo da tela
        //
        var user = new User
        {
            UserName = txtUserName.Text,
            Email = txtUserName.Text,
            Password = txtPassword.Text,
            PasswordAnswer = txtPassword.Text,
            CreationDate = DateTime.Now,
            LastActivityDate = DateTime.Now,
            LastLockoutDate = DateTime.Now,
            LastLoginDate = DateTime.Now,
            LastPasswordChangedDate = DateTime.Now
        };

        if (ViewState["EmployeeProfileId"] != null)
            user.ProfileId = Convert.ToInt32(ViewState["EmployeeProfileId"]);

        user.HasChangePassword = chkHasChangePassword.Checked;
        user.IsActive = chkIsActiveCheckBox.Checked;
        user.IsLockedOut = chkIsLockedOut.Checked;

        return user;
    }
 /// <summary>
 /// This method convert the information of VivinaFramework's User type to DataClasses's User type
 /// </summary>
 /// <param name="membershipEntity"></param>
 /// <param name="user"></param>
 private void CopyMembershipEntityToUser(User membershipEntity, Vivina.Erp.DataClasses.User user)
 {
     user.CreationDate = membershipEntity.CreationDate;
     user.Email = membershipEntity.Email;
     user.FailedPasswordAttemptCount = membershipEntity.FailedPasswordAttemptCount;
     user.HasChangePassword = membershipEntity.HasChangePassword;
     user.IsActive = membershipEntity.IsActive;
     user.IsLockedOut = membershipEntity.IsLockedOut;
     
     user.LastActivityDate = membershipEntity.LastActivityDate;
     user.LastLockoutDate = membershipEntity.LastLockoutDate;
     user.LastLoginDate = membershipEntity.LastLoginDate;
     user.LastPasswordChangedDate = membershipEntity.LastPasswordChangedDate;
     user.LastRemoteHost = membershipEntity.LastRemoteHost;
     user.Password = membershipEntity.Password;
     user.PasswordAnswer = membershipEntity.PasswordAnswer;
     user.PasswordQuestion = membershipEntity.PasswordQuestion;
     user.ProfileId = membershipEntity.ProfileId;
     user.UserId = membershipEntity.UserId;
     user.UserName = membershipEntity.UserName;
 }
        public AccessControlPrincipal(DataEntities.User user, IIdentity identity)
        {
            _user = user ?? new DataEntities.User();
            _user.Profile = _user.Profile ?? new DataEntities.Profile();
            //_user.Profile.Name = (user != null ? _user.Profile.Name : identity.Name);

            _identity = identity;
        }
    protected void RegistrarEmpresa(object sender, EventArgs e)
    {
        var companyManager = new CompanyManager(this);
        var planManager = new PlanManager(this);

        var plan = planManager.GetAllPlans().Where(x => x.Name.Contains(Request["plan"])).FirstOrDefault();
        if (plan == null)
            throw new ArgumentException("O plano não existe!");

        var company = new Company
        {
            PlanId = plan.PlanId,
            StartDate = DateTime.Now,
            ModifiedDate = DateTime.Now,
            NextStatementDueDate = DateTime.Now.AddMonths(1),
            LegalEntityProfile = new LegalEntityProfile
            {
                CNPJ = txtCNPJ.Text,
                CompanyName = txtCompanyName.Text,
                Phone = txtCompanyPhone.Text,
                PostalCode = adrCompanyAddress.PostalCode,
                AddressComp = adrCompanyAddress.AddressComp,
                AddressNumber = adrCompanyAddress.AddressNumber,
                IE = txtIE.Text
            }
        };

        var user = new InfoControl.Web.Security.DataEntities.User
        {
            UserName = txtEmail.Text,
            Email = txtEmail.Text,
            Password = txtSenha.Text,
            PasswordAnswer = txtSenha.Text,
            CreationDate = DateTime.Now,
            LastLockoutDate = DateTime.Now,
            LastLoginDate = DateTime.Now,
            LastPasswordChangedDate = DateTime.Now
        };

        var profile = new Profile
        {
            CPF = txtCPF.Text,
            Name = txtNome.Text,
            ModifiedDate = DateTime.Now,
            Phone = txtPhone.Text,
            PostalCode = adrAdminAddress.PostalCode,
            AddressComp = adrAdminAddress.AddressComp,
            AddressNumber = adrAdminAddress.AddressNumber
        };

        InsertCompanyStatus status = companyManager.InsertMatrixCompany(company, user, profile);

        switch (status)
        {
            case InsertCompanyStatus.Success:
                //txtError.Text = "<b> <font color='red'> Empresa registrada com sucesso!  </font> </b>";
                pnlFormRegister.Visible = false;
                successMessage.Visible = true;
                break;

            case InsertCompanyStatus.DuplicateCNPJ:
                txtError.Text = "<b> <font color='red'>" + Resources.Exception.CNPJAlreadyExist + " </font> </b>";
                break;

            case InsertCompanyStatus.DuplicatedAdminEmail:
                txtError.Text = "<b> <font color='red'>" + Resources.Exception.AdministratorEmailAlreadyExist + " </font> </b>";
                break;

            case InsertCompanyStatus.DuplicatedUserName:
                txtError.Text = "<b> <font color='red'>" + Resources.Exception.AdministratorCPFAlreadyExist + " </font> </b>";
                break;

            case InsertCompanyStatus.InvalidPassword:
                txtError.Text = "<b> <font color='red'>" + Resources.Exception.InvalidUserPassword + " </font> </b>";
                break;

            default:
                txtError.Text = "<b> <font color='red'>" + Resources.Exception.AdministratorEmailAlreadyExist + " </font> </b>";
                break;
        }
    }
        /// <summary>
        /// Create a user
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="passwordQuestion"></param>
        /// <param name="passwordAnswer"></param>
        /// <param name="isApproved"></param>
        /// <param name="providerUserKey"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public override MembershipUser CreateUser(string username,
                 string password,
                 string email,
                 string passwordQuestion,
                 string passwordAnswer,
                 bool isApproved,
                 object providerUserKey,
                 out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            User user = new User();
            user.UserName = username;
            user.Password = password;
            user.Email = email;
            user.PasswordQuestion = passwordQuestion;
            user.PasswordAnswer = passwordAnswer;

            return MembershipManager.Insert(user, out status, _requiresValidEmail);
        }