protected void ButtonCreate_Click(object sender, EventArgs e) { ParticipantTitle applicantLabel = (ParticipantTitle)(Enum.Parse(typeof(ParticipantTitle), this.DropApplicantLabel.SelectedValue)); ParticipantTitle activistLabel = (ParticipantTitle)(Enum.Parse(typeof(ParticipantTitle), this.DropActivistLabel.SelectedValue)); ParticipantTitle peopleLabel = (ParticipantTitle)(Enum.Parse(typeof(ParticipantTitle), this.DropPersonLabel.SelectedValue)); string asRoot = this.DropCreateChild.SelectedValue; string currencyCode = this.DropCurrencies.SelectedValue; string newOrgName = this.TextOrganizationName.Text; if (string.IsNullOrEmpty(newOrgName)) { throw new ArgumentException("Organization name can't be empty"); } if (activistLabel == ParticipantTitle.Unknown || peopleLabel == ParticipantTitle.Unknown || asRoot == "0" || currencyCode == "0") { throw new ArgumentException("Necessary argument was not supplied (did client-side validation run?)"); } Currency newOrgCurrency = Currency.FromCode(currencyCode); Organization parent = CurrentOrganization; if (asRoot == "Root") { parent = null; } Organization newOrganization = Organization.Create(parent == null ? 0 : parent.Identity, newOrgName, newOrgName, newOrgName, string.Empty, newOrgName, Geography.RootIdentity, true, true, 0); newOrganization.EnableEconomy(newOrgCurrency); newOrganization.ApplicantLabel = applicantLabel; newOrganization.RegularLabel = peopleLabel; newOrganization.ActivistLabel = activistLabel; PositionTitle titleType = (PositionTitle)(Enum.Parse(typeof(PositionTitle), this.DropPositionLabel.SelectedValue)); Positions.CreateOrganizationDefaultPositions(newOrganization, titleType); Participation.Create(CurrentUser, newOrganization, Constants.DateTimeHigh); Positions.ForOrganization(newOrganization).AtLevel(PositionLevel.OrganizationExecutive)[0].Assign( CurrentUser, null /* assignedby */, null /* assigned by position */, "Initial executive", null /* expires */); string successMessage = String.Format(Resources.Pages.Admin.CreateOrganization_Success, Participant.Localized(peopleLabel, TitleVariant.Ship)); DashboardMessage.Set(successMessage); // Log in to new organization, then redirect to Edit Response.Redirect( "/Pages/v5/Security/SetCurrentOrganization.aspx?OrganizationId=" + newOrganization.Identity.ToString(CultureInfo.InvariantCulture) + "&ReturnUrl=/Admin/OrgSettings", true); }
protected void ButtonSubmit_Click(object sender, EventArgs e) { DateTime dateOfBirth = new DateTime(1800, 1, 1); // null equivalent if (this.TextDateOfBirth.Text.Length > 0) { dateOfBirth = DateTime.Parse(this.TextDateOfBirth.Text); } string street = this.TextStreet1.Text; if (!string.IsNullOrEmpty(this.TextStreet2.Text)) { street += "|" + this.TextStreet2.Text; } Person newPerson = Person.Create(this.TextName.Text, this.TextMail.Text, string.Empty, this.TextPhone.Text, street, this.TextPostal.Text, this.TextCity.Text, this.DropCountries.SelectedValue, dateOfBirth, (PersonGender)Enum.Parse(typeof(PersonGender), this.DropGenders.SelectedValue)); DateTime participationExpiry = Constants.DateTimeHigh; ParticipantMailType welcomeMailType = ParticipantMailType.ParticipantAddedWelcome_NoExpiry; int participationDurationMonths = Int32.Parse(CurrentOrganization.Parameters.ParticipationDuration); if (participationDurationMonths < 1000) { participationExpiry = DateTime.Today.AddMonths(participationDurationMonths); welcomeMailType = ParticipantMailType.ParticipantAddedWelcome; } Participation newParticipation = Participation.Create(newPerson, CurrentOrganization, participationExpiry); OutboundComm.CreateParticipantMail(welcomeMailType, newParticipation, CurrentUser); newPerson.LastLogonOrganizationId = CurrentOrganization.Identity; SwarmopsLogEntry logEntry = SwarmopsLog.CreateEntry(newPerson, new Swarmops.Logic.Support.LogEntries.PersonAddedLogEntry(newParticipation, CurrentUser)); logEntry.CreateAffectedObject(newParticipation); logEntry.CreateAffectedObject(CurrentUser); // Clear form and make way for next person this.TextName.Text = string.Empty; this.TextStreet1.Text = string.Empty; this.TextStreet2.Text = string.Empty; this.TextMail.Text = string.Empty; this.TextPhone.Text = string.Empty; this.TextPostal.Text = string.Empty; this.TextCity.Text = string.Empty; this.TextDateOfBirth.Text = string.Empty; this.DropGenders.SelectedValue = "Unknown"; this.TextName.Focus(); this.LiteralLoadAlert.Text = Resources.Pages.Swarm.AddPerson_PersonSuccessfullyRegistered; }
public async Task <IActionResult> Register(long eventId) { long userId = 1; //TODO: var participations = await _participationService.GetByEventId(eventId); if (participations.Select(x => x.UserId).Contains(userId)) { return(Ok("Already registered")); } var participation = Participation.Create(eventId, userId); await _participationService.Add(participation); return(Ok("Successful registered")); }
protected void Page_Load(object sender, EventArgs e) { if (CurrentUser == null) { throw new UnauthorizedAccessException("No"); // may cause problems on login screen? } PageAccessRequired = new Access(AccessAspect.Null); string returnUrlString = Request.QueryString["ReturnUrl"]; string organizationIdString = Request.QueryString["OrganizationId"]; int organizationId = Int32.Parse(organizationIdString); Organization suggestedOrganization = null; try { suggestedOrganization = Organization.FromIdentity(organizationId); } catch (ArgumentException) { suggestedOrganization = null; } if (suggestedOrganization.Identity == Organization.SandboxIdentity && !CurrentUser.ParticipatesInOrganization(suggestedOrganization)) { // Add a forever participation in Sandbox Participation.Create(CurrentUser, Organization.Sandbox, Constants.DateTimeHigh); } else if (suggestedOrganization == null || !CurrentUser.ParticipatesInOrganization(suggestedOrganization)) { // Some work here on PPSE pilot - we want everybody to be able to switch to Sandbox, which is #1 // except for in PPSE installation, where it is... #3 or something // TODO: Allow logon to organization if there is a Position active throw new UnauthorizedAccessException(); } // when we get here, we are authorized to log on to the suggested organization. // The reason we're modifying the existing Authority object instead of creating a new one // is to minimize the risk for impersonation exploits: The only way to assign a Person identity // to an Authority object is on login. Authority newAuthority = CurrentAuthority; newAuthority.SetOrganization(suggestedOrganization); // will/can also modify Position CurrentUser.LastLogonOrganizationId = suggestedOrganization.Identity; if (suggestedOrganization.Identity == Organization.SandboxIdentity) { // Set a dashboard message that the user is now working in Sandbox Response.SetCookie(new HttpCookie("DashboardMessage", CommonV5.JavascriptEscape(Resources.Global.Global_EnteringSandbox))); } if (!string.IsNullOrEmpty(returnUrlString)) { FormsAuthentication.SetAuthCookie(newAuthority.ToEncryptedXml(), true); Response.Redirect(returnUrlString); } else { FormsAuthentication.RedirectFromLoginPage(newAuthority.ToEncryptedXml(), true); } }