protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { Company company = new Company(); // Clone the original company for the linq track changes if (originalCompany != null) { company.CopyPropertiesFrom(originalCompany); } // // Set the company properties // company.ReferenceCompanyId = Company.ReferenceCompanyId; company.MatrixId = String.IsNullOrEmpty(cboMatrixId.SelectedValue) ? company.CompanyId : Convert.ToInt32(cboMatrixId.SelectedValue); company.StartDate = DateTime.Now; company.NextStatementDueDate = DateTime.Now; company.ModifiedDate = DateTime.Now; company.LegalEntityProfileId = Profile_LegalEntity1.CompanyProfileEntity.LegalEntityProfileId; // // Add entity for insert // if (company.LegalEntityProfileId == 0) { company.LegalEntityProfile = Profile_LegalEntity1.CompanyProfileEntity; } if (Page.ViewState["CompanyId"] == null && Page.ViewState["ProfileExists"] != "0") { InsertCompanyStatus status = companyManager.InsertCompany(company, User.Identity.UserId, Company.CompanyId); if (status != InsertCompanyStatus.Success) { ShowError("Ocorreu um erro ao inserir uma empresa!"); return; } } else { companyManager.Update(originalCompany, company); } Page.ClientScript.RegisterStartupScript(this.GetType(), "", "top.ResetHeader();", true); if (!String.IsNullOrEmpty(Request["host"])) { Response.Redirect("~/Infocontrol/Host/Companies.aspx"); } else { Response.Redirect("Companies.aspx"); } } }
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; } }
protected void btnSave_Click(object sender, EventArgs e) { int?depositId = null; int?representantId = null; if (!String.IsNullOrEmpty(cboDeposit.SelectedValue)) { depositId = Convert.ToInt32(cboDeposit.SelectedValue); } if (!String.IsNullOrEmpty(cboRepresentant.SelectedValue)) { representantId = Convert.ToInt32(cboRepresentant.SelectedValue); } // //Update User // if (!String.IsNullOrEmpty(Request["UserId"])) { var originalUser = CompanyManager.GetUser(Company.CompanyId, Convert.ToInt32(Page.ViewState["UserId"])); if (originalUser.UserName != txtUserName.Text && CompanyManager.ExistsUserInCompany(Company.CompanyId, txtUserName.Text)) { ShowError(Exception.ExistentMail); return; } CompanyManager.UpdateUser(Company.CompanyId, Convert.ToInt32(Page.ViewState["UserId"]), depositId, representantId, ucProfile.ProfileEntity, SaveUser()); RefreshDeposit(); RefreshCredentials(); Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "parent.location='Users.aspx'", true); return; } // // Verifies if the User already exist in company // if (CompanyManager.ExistsUserInCompany(Company.CompanyId, txtUserName.Text)) { ShowError(Exception.ExistentMail); return; } var oldUser = MembershipManager.GetUserByName(txtUserName.Text); if (oldUser != null) { CompanyManager.UpdateUser(Company.CompanyId, oldUser.UserId, depositId, representantId, ucProfile.ProfileEntity, SaveUser()); RefreshCredentials(); Response.Redirect("User.aspx?UserId=" + oldUser.UserId); return; } // // Insert user // var newUser = SaveUser(); InsertCompanyStatus status = CompanyManager.InsertUser(Company.CompanyId, depositId, representantId, newUser, ucProfile.ProfileEntity); switch (status) { case InsertCompanyStatus.InvalidPassword: ShowError(Exception.InvalidPassword); break; case InsertCompanyStatus.InvalidUser: case InsertCompanyStatus.DuplicateCNPJ: case InsertCompanyStatus.DuplicatedAdminEmail: case InsertCompanyStatus.DuplicatedUserName: ShowError(Exception.ExistentMail); break; case InsertCompanyStatus.Success: Response.Redirect("User.aspx?UserId=" + newUser.UserId); break; } RefreshCredentials(); }