private void LoadUser() { User user = MembershipManager.GetUser(Convert.ToInt32(Page.ViewState["UserId"])); // load the profile data ucProfile.ProfileEntity = ProfileManager.GetProfileByUser(Convert.ToInt32(Page.ViewState["UserId"])); chkHasChangePassword.Checked = user.HasChangePassword; var representantUser = RepresentantManager.GetRepresentantUser(Convert.ToInt32(Page.ViewState["UserId"])); if (representantUser != null) { cboRepresentant.SelectedValue = Convert.ToString(representantUser.RepresentantId); } chkIsActiveCheckBox.Checked = user.IsActive; chkIsLockedOut.Checked = user.IsLockedOut; txtUserName.Text = user.UserName; txtPassword.ValidationGroup = "dummy"; txtConfirmPassword.ValidationGroup = "dummy"; Deposit deposit = CompanyManager.GetCurrentDeposit(Convert.ToInt32(Page.ViewState["UserId"]), Company.CompanyId); if (deposit != null) { cboDeposit.SelectedValue = deposit.DepositId.ToString(); } }
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); }
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { InfoControl.Web.Security.MembershipManager mManager = new InfoControl.Web.Security.MembershipManager(this); InfoControl.Web.Security.DataEntities.User user = mManager.GetUserByName(CreateUserWizard1.UserName.ToString()); Profile profile = new Profile(); ProfileManager pManager = new ProfileManager(this); profile.Name = (CreateUserWizard1.FindControl("txtName") as TextBox).Text; profile.CPF = (CreateUserWizard1.FindControl("txtCPF") as TextBox).Text; //profile.Address = (CreateUserWizard1.FindControl("txtAddress") as TextBox).Text; profile.Phone = (CreateUserWizard1.FindControl("txtPhone") as TextBox).Text; //profile.Neighborhood = (CreateUserWizard1.FindControl("txtNeighborhood") as TextBox).Text; profile.PostalCode = (CreateUserWizard1.FindControl("txtPostalCode") as TextBox).Text; profile.ModifiedDate = DateTime.Now; //profile.UserId = user.UserId; //profile.StateId = (CreateUserWizard1.FindControl("cboState") as DropDownList).SelectedValue; try { pManager.Insert(profile); } catch (Exception ex) { if (ex != null) { return; } } Context.Items.Add("UserId", user.UserId); Server.Transfer("User.aspx"); }
public override InfoControl.Web.Auditing.Event LogErrorInDatabase(Exception ex) { var eventEntity = base.LogErrorInDatabase(ex); HttpContext context = HttpContext.Current; if (context != null && context.Session != null) { using (var customerManager = new CustomerManager(null)) using (var companyManager = new CompanyManager(null)) using (var membershipManager = new MembershipManager(null)) { Company hostCompany = companyManager.GetHostCompany(); Company company = companyManager.GetCompanyByContext(context); Customer customer = customerManager.GetCustomerByLegalEntityProfile(hostCompany.CompanyId, company.LegalEntityProfileId); if (customer != null) { var customerCall = new CustomerCall(); customerCall.EventId = eventEntity.EventId; customerCall.Subject = (ex.Message.Length > 100 ? ex.Message.Substring(0, 90) + " ..." : ex.Message); customerCall.CallNumber = Util.GenerateUniqueID(); customerCall.CompanyId = hostCompany.CompanyId; customerCall.CustomerId = customer.CustomerId; customerCall.OpenedDate = customerCall.ModifiedDate = DateTime.Now.Date; customerCall.Description = String.Empty; customerCall.CustomerCallTypeId = CustomerCallType.ERROR; customerCall.CustomerCallStatusId = CustomerCallStatus.New; customerCall.Rating = 5; customerCall.CallNumberAssociated = context.Request.RawUrl; customerCall.Sector = Convert.ToString(context.Session["_lastPageTitle"]); if (context.User != null) { if (context.User.Identity != null) { if (context.User.Identity.IsAuthenticated) { User user = membershipManager.GetUserByEmail(context.User.Identity.Name); if (user != null) { customerCall.UserId = user.UserId; } } } } customerManager.InsertCustomerCall(customerCall, null, null, null); } } } return(eventEntity); }
/// <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; }
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> /// This method creates an user for an existing customer /// </summary> public MembershipCreateStatus InsertUserForCustomer(Customer originalCustomer, User user) { var membershipManager = new MembershipManager(this); MembershipCreateStatus status; membershipManager.Insert(user, out status, true); if (status == MembershipCreateStatus.Success) { originalCustomer.UserId = user.UserId; DbContext.SubmitChanges(); return MembershipCreateStatus.Success; } return status; }
/// <summary> /// This method insert an customer and an user atached /// this method return true when customer and user inserted /// </summary> public MembershipCreateStatus Insert(Customer customer, User user) { MembershipCreateStatus status; var companyManager = new CompanyManager(this); var membershipManager = new MembershipManager(this); membershipManager.Insert(user, out status, true); // // creates an new user // if (status == MembershipCreateStatus.Success) { customer.UserId = user.UserId; customer.CreatedDate = customer.ModifiedDate = DateTime.Now; Insert(customer); return MembershipCreateStatus.Success; } return status; }
/// <summary> /// This method updates an user /// </summary> /// <param name="userId">Can't be null</param> /// <param name="companyId">Can't be null</param> /// <param name="depositId"></param> /// <param name="user">Can't be null</param> public void UpdateUser(int userId, int companyId, int? depositId, User user) { // // Save User // var mManager = new MembershipManager(this); User original_user = mManager.GetUser(userId); mManager.Update(original_user, user); // // Deposit // ChangeDeposit(companyId, userId, depositId); // // Associate the User with company // if (GetCompanyUser(companyId, userId) == null) AssociateUser(companyId, userId, depositId, true); }
/// <summary> /// This method updates a user, profile and deposit /// </summary> /// <param name="userId"></param> /// <param name="companyId"></param> /// <param name="depositId"></param> /// <param name="profile"></param> /// <param name="user"></param> public void UpdateUser(Int32 companyId, Int32 userId, Int32? depositId, Int32? representantId, Profile profile, User user) { // // Save Profile // var profileManager = new ProfileManager(this); profileManager.SaveProfile(profile); if (representantId.HasValue) { RemoveRepresentantFromUser(userId); AddRepresentantToUser(companyId, userId, (int)representantId); } else RemoveRepresentantFromUser(userId); AttachProfileEntityToUser(companyId, userId, profile.ProfileId); UpdateUser(userId, companyId, depositId, user); }
/// <summary> /// This method delete a user /// </summary> /// <param name="newUser"></param> public void DeleteUser(User newUser) { var membershipManager = new MembershipManager(this); newUser = membershipManager.GetUser(newUser.UserId); membershipManager.Delete(newUser); }
public void UpdateUser(Int32 companyId, User user, Profile originalProfile, Profile profile) { // - atualizar o user // - atualizar o perfil // - associar o perfil ao usuário // - associá-lo a uma compania }
/// <summary> /// M�todo usado para criar a primeira companhia, utilizado na tela de registro /// </summary> /// <param name="newCompany"></param> /// <param name="newUser"></param> /// <param name="newProfile"></param> /// <returns></returns> public InsertCompanyStatus InsertMatrixCompany(Company newCompany, User newUser, Profile profile) { // // Insert the profile // var pManager = new ProfileManager(this); // Profile profile = pManager.GetProfile(newProfile.CPF) ?? newProfile; //if (profile.ProfileId == 0) pManager.Insert(profile); //else //{ // profile.Name = newProfile.Name; // profile.Email = newProfile.Email; // profile.PostalCode = newProfile.PostalCode; // //profile.Address = newProfile.Address; // profile.AddressComp = newProfile.AddressComp; // profile.AddressNumber = newProfile.AddressNumber; // profile.Phone = newProfile.Phone; // DbContext.SubmitChanges(); //} // //Insert Admin user // Int32 UserId; //newUser.ProfileId DataClasses.User original_User = GetUserByUserName(newUser.Email); if (original_User != null) { UserId = original_User.UserId; } else { MembershipCreateStatus status; var membershipManager = new MembershipManager(this); newUser.ProfileId = profile.ProfileId; membershipManager.Insert( newUser, out status, (Membership.Provider as VivinaMembershipProvider).RequiresValidEmail); // //verify if the status of the inclusion are ok // if (status != MembershipCreateStatus.Success) { DataManager.Rollback(); switch (status) { case MembershipCreateStatus.DuplicateUserName: return InsertCompanyStatus.DuplicatedUserName; case MembershipCreateStatus.InvalidPassword: return InsertCompanyStatus.InvalidPassword; case MembershipCreateStatus.DuplicateEmail: return InsertCompanyStatus.DuplicatedAdminEmail; default: return InsertCompanyStatus.InvalidUser; } } UserId = newUser.UserId; } if (newCompany.LegalEntityProfile.IsLiberalProfessional) newCompany.LegalEntityProfile.CompanyName = newCompany.LegalEntityProfile.FantasyName = profile.Name; var insertCompanyStatus = InsertCompany(newCompany, UserId, 0); newCompany.ReferenceCompanyId = newCompany.CompanyId; newCompany.MatrixId = newCompany.CompanyId; DbContext.SubmitChanges(); return insertCompanyStatus; }
/// <summary> /// This method inserts a user /// </summary> /// <param name="companyId">Can't be null</param> /// <param name="user">Can't be null. This entity can't be attached in db</param> /// <param name="depositId">can be null</param> /// <returns>a status based on InsertCompanyStatus</returns> public InsertCompanyStatus InsertUser(int companyId, int? depositId, int? representantId, User user, Profile profile) { var membershipManager = new MembershipManager(this); // //method to insert a new user // var provider = Membership.Provider as VivinaMembershipProvider; MembershipCreateStatus status; membershipManager.Insert(user, out status, provider.RequiresValidEmail); // //verifies if the status of the inclusion is ok // if (status != MembershipCreateStatus.Success) { DataManager.Rollback(); switch (status) { case MembershipCreateStatus.InvalidPassword: return InsertCompanyStatus.InvalidPassword; case MembershipCreateStatus.DuplicateEmail: return InsertCompanyStatus.DuplicatedAdminEmail; } } if (profile.ProfileId == 0) new ProfileManager(this).Insert(profile); AttachProfileEntityToUser(companyId, user.UserId, profile.ProfileId); if (representantId.HasValue) AddRepresentantToUser(companyId, user.UserId, Convert.ToInt32(representantId)); // // Associate the User with company // if (!IsCompanyUser(companyId, user.UserId)) AssociateUser(companyId, user.UserId, depositId, true); return InsertCompanyStatus.Success; }
public InsertCompanyStatus InsertUser(int companyId, User user, Profile profile, int? depositId) { // // If ProfileId equal 0 then the profile no exists in bd // var pManager = new ProfileManager(this); if (profile.ProfileId == 0) pManager.Insert(profile); // //method to insert a new user // var provider = Membership.Provider as VivinaMembershipProvider; MembershipCreateStatus status; var membershipManager = new MembershipManager(this); user.ProfileId = profile.ProfileId; membershipManager.Insert(user, out status, provider.RequiresValidEmail); // //verify if the status of the inclusion is ok // if (status != MembershipCreateStatus.Success) { DataManager.Rollback(); switch (status) { case MembershipCreateStatus.InvalidPassword: return InsertCompanyStatus.InvalidPassword; case MembershipCreateStatus.DuplicateEmail: return InsertCompanyStatus.DuplicatedAdminEmail; } } // // Associate the User with company // AssociateUser(companyId, user.UserId, depositId, true); // // Insert a Employee // var humanResourcesManager = new HumanResourcesManager(this); var employee = new Employee(); employee.IsActive = true; employee.ProfileId = profile.ProfileId; employee.CompanyId = companyId; humanResourcesManager.InsertEmployee(employee, new List<EmployeeAdditionalInformation>()); return InsertCompanyStatus.Success; }