예제 #1
0
        public static Position Create(Organization organization, PositionLevel level, Person createdByPerson, Position createdByPosition, PositionType positionType,
                                      PositionTitle positionTitle, bool volunteerable, bool overridable, Position reportsTo, Position dotReportsTo,
                                      int minCount, int maxCount)
        {
            if (level == PositionLevel.Geography)
            {
                throw new ArgumentException(
                          "Cannot use the geographyless creator to create geography-specific positions.");
            }

            if (organization == null && level != PositionLevel.SystemWide)
            {
                throw new ArgumentException("Cannot use null organization with any other level than PositionLevel.SystemWide");
            }

            int positionId = SwarmDb.GetDatabaseForWriting()
                             .CreatePosition(
                level, organization == null? 0 : organization.Identity, 0 /* geographyId */, 0 /*overridesHigherId */,
                createdByPerson == null ? 0 : createdByPerson.Identity, createdByPosition == null ? 0 : createdByPosition.Identity,
                positionType.ToString(), positionTitle.ToString(),
                false /*inheritsDownward*/, volunteerable, overridable,
                reportsTo == null ? 0 : reportsTo.Identity,
                dotReportsTo == null ? 0 : dotReportsTo.Identity,
                minCount, maxCount);

            return(FromIdentityAggressive(positionId));
        }
예제 #2
0
        public static string Localized(PositionType type, PositionTitle title, bool plural = false)
        {
            if (title == PositionTitle.Custom)
            {
                throw new InvalidOperationException("Can't fetch generic name for customized title");
            }

            string titleStringUntyped = type.ToString();
            string titleStringTyped   = titleStringUntyped + "_" + title.ToString();

            if (plural && title != PositionTitle.UxElement)
            {
                titleStringUntyped += "_Plural";
                titleStringTyped   += "_Plural";
            }

            string testResult = Logic_Swarm_Position.ResourceManager.GetString("Position_" + titleStringTyped);

            if (!String.IsNullOrEmpty(testResult))
            {
                return(testResult);
            }

            return(Logic_Swarm_Position.ResourceManager.GetString("Position_" + titleStringUntyped));
        }
예제 #3
0
        public async Task <JsonResult> AddPositionTitle([FromBody] PositionTitle positionTitle)
        {
            var errors = positionTitle.VerifyPositionTitleData();

            if (errors.Length != 0)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Data = errors
                }));
            }

            var organization = await _organizationService.GetOrganizationById(positionTitle.OrganizationId);

            if (organization == null)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while getting data."
                }));
            }

            positionTitle.OrganizationId = organization.Id;
            positionTitle.AddedOn        = DateTime.UtcNow;

            var saveResult = await _organizationService.InsertNewPositionTitle(positionTitle);

            return(!saveResult.HasValue || saveResult.Value < 1
                ? new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while removing data."
            })
                : new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success, Data = saveResult.Value
            }));
        }
예제 #4
0
        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);
        }
예제 #5
0
        public async Task <JsonResult> UpdatePositionTitle(PositionTitle positionTitle)
        {
            var updateResult = await _organizationService.UpdatePositionTitle(positionTitle);

            return(!updateResult.HasValue || !updateResult.Value
                ? new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while removing data."
            })
                : new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success
            }));
        }
예제 #6
0
        public static Position Create(PositionLevel level, Person createdByPerson, Position createdByPosition, PositionType positionType,
                                      PositionTitle positionTitle, bool volunteerable, bool overridable, Position reportsTo, Position dotReportsTo,
                                      int minCount, int maxCount)
        {
            if (level != PositionLevel.SystemWide)
            {
                throw new ArgumentException(
                          "Can only create system-wide positions (e.g. sysadmin) with this organizationless Position.Create() version.");
            }

            // Use more general Create() do to the actual work

            return(Create(null, level, createdByPerson, createdByPosition, positionType, positionTitle, volunteerable,
                          overridable, reportsTo, dotReportsTo, minCount, maxCount));
        }
예제 #7
0
        public async Task <JsonResult> CreateOrganization([FromHeader] int userId, [FromBody] Organization organization)
        {
            var errors = organization.VerifyOrganizationData();

            if (errors.Count != 0)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Data = errors
                }));
            }

            await _organizationService.StartTransaction();

            var saveAddressResult = await _addressService.SaveNewAddress(organization.Address);

            if (!saveAddressResult.HasValue || saveAddressResult.Value < 1)
            {
                await _organizationService.RevertTransaction();

                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while saving data."
                }));
            }

            organization.AddressId = saveAddressResult.Value;
            var organizationUniqueId        = string.Empty;
            var isOrganizationUniqueIdValid = false;

            while (!isOrganizationUniqueIdValid)
            {
                organizationUniqueId        = Helpers.GenerateRandomString(SharedConstants.DefaultUniqueIdLength);
                isOrganizationUniqueIdValid = await _organizationService.IsOrganizationUniqueIdAvailable(organizationUniqueId);

                if (isOrganizationUniqueIdValid)
                {
                    organizationUniqueId = organizationUniqueId.ToUpper();
                }
            }

            organization.UniqueId = organizationUniqueId;
            var saveOrganizationResult = await _organizationService.InsertNewOrganization(organization);

            if (!saveOrganizationResult.HasValue || saveOrganizationResult.Value < 1)
            {
                await _organizationService.RevertTransaction();

                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while saving data."
                }));
            }

            var defaultUserRole = DepartmentRole.GetDefaultManagerialInstance();

            defaultUserRole.OrganizationId = saveOrganizationResult.Value;
            defaultUserRole.AddedById      = userId;

            var saveRoleResult = await _departmentRoleService.InsertNewDepartmentRole(defaultUserRole);

            if (!saveRoleResult.HasValue || saveRoleResult.Value < 1)
            {
                await _organizationService.RevertTransaction();

                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while saving data."
                }));
            }

            var defaultUserPosition = PositionTitle.GetDefaultManagerialTitle();

            defaultUserPosition.OrganizationId = saveOrganizationResult.Value;

            var savePositionResult = await _organizationService.InsertNewPositionTitle(defaultUserPosition);

            if (!savePositionResult.HasValue || savePositionResult.Value < 1)
            {
                await _organizationService.RevertTransaction();

                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while saving data."
                }));
            }

            var userOrganization = new UserOrganization {
                UserId           = userId,
                DepartmentRoleId = saveRoleResult.Value,
                OrganizationId   = saveOrganizationResult.Value,
                PositionId       = savePositionResult.Value,
                IsActive         = true,
                JointOn          = DateTime.UtcNow
            };

            var saveUserOrgResult = await _organizationService.InsertNewUserOrganization(userOrganization);

            if (!saveUserOrgResult.HasValue || saveUserOrgResult.Value < 1)
            {
                await _organizationService.RevertTransaction();

                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while saving data."
                }));
            }

            await _organizationService.CommitTransaction();

            return(new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success, Data = saveOrganizationResult.Value
            }));
        }
예제 #8
0
        public static void CreateOrganizationDefaultPositions(Organization organization, PositionTitle titleType = PositionTitle.Default)
        {
            // Verify this is indeed a bootstrap - must fail if there are already positions at this level

            if (Positions.ForOrganization(organization).Count > 0)
            {
                throw new InvalidOperationException("Can't re-initialize organization positions - already initialized");
            }

            /* STRATEGIC POSITIONS */

            Position chairperson = Position.Create(organization, PositionLevel.OrganizationStrategic, null, null,
                                                   PositionType.Strategic_BoardChairperson, titleType, false, false, null, null, 1, 1);

            /*Position deputyChairs =*/ Position.Create(organization, PositionLevel.OrganizationStrategic, null, null,
                                                        PositionType.Strategic_BoardChairpersonDeputy, titleType, false, false, chairperson, null, 0,
                                                        0);

            /*Position members =*/ Position.Create(organization, PositionLevel.OrganizationStrategic, null, null,
                                                   PositionType.Strategic_BoardMember, titleType, false, false, null, null, 0, 0);

            /*Position deputies =*/ Position.Create(organization, PositionLevel.OrganizationStrategic, null, null,
                                                    PositionType.Strategic_BoardDeputy, titleType, false, false, null, null, 0, 0);

            Position auditors = Position.Create(organization, PositionLevel.OrganizationStrategic, null, null,
                                                PositionType.Strategic_Auditor, titleType, false, false, null, null, 1, 0);

            /*Position auditorDeputies =*/ Position.Create(organization, PositionLevel.OrganizationStrategic, null, null,
                                                           PositionType.Strategic_AuditorDeputy, titleType, false, false, auditors, null, 0, 0);

            /*Position auditorAssistants =*/ Position.Create(organization, PositionLevel.OrganizationStrategic, null, null,
                                                             PositionType.Strategic_AuditorAssistant, titleType, false, false, auditors, null, 0, 0);

            /*Position observers=*/ Position.Create(organization, PositionLevel.OrganizationStrategic, null, null,
                                                    PositionType.Strategic_Observer, titleType, false, false, null, null, 0, 0);


            /* EXECUTIVE POSITIONS (positions at the "Global" geographic level) */

            Position ceo = Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                                           PositionType.Executive_ChiefExecutiveOfficer, titleType, false, false, null, null, 1, 1);


            /*Position vp =*/ Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                                              PositionType.Executive_CeoAssistant, titleType, false, false, ceo, null, 0, 0);

            /*Position vp =*/ Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                                              PositionType.Executive_VicePresident, titleType, false, false, ceo, null, 0, 0);

            /*Position cto =*/
            Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                            PositionType.Executive_ChiefTechnologyOfficer, titleType, false, false, ceo, null, 0, 1);

            Position cmo = Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                                           PositionType.Executive_ChiefMarketingOfficer, titleType, false, false, ceo, null, 0, 1);

            /*Position cmoAssistant =*/ Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                                                        PositionType.Executive_MarketingAssistant, titleType, false, false, cmo, null, 0, 0);

            Position cfo = Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                                           PositionType.Executive_ChiefFinancialOfficer, titleType, false, false, ceo, null, 0, 1);

            /*Position cfoAssistant =*/ Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                                                        PositionType.Executive_CfoAssistant, titleType, false, false, cfo, null, 0, 0);

            /*Position cio =*/ Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                                               PositionType.Executive_ChiefInformationOfficer, titleType, false, false, ceo, null, 0, 1);

            Position coo = Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                                           PositionType.Executive_ChiefOperationsOfficer, titleType, false, false, ceo, null, 0, 1);

            Position chiefHr = Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                                               PositionType.Executive_ChiefHrOfficer, titleType, false, false, ceo, null, 0, 1);

            /*Position staffAssistant =*/ Position.Create(organization, PositionLevel.OrganizationExecutive, null, null,
                                                          PositionType.Executive_HrAssistant, titleType, false, false, chiefHr, null, 0, 0);


            /* LOCAL DEFAULT POSITIONS */

            Position localLeader = Position.Create(organization, PositionLevel.GeographyDefault, null, null,
                                                   PositionType.Geographic_Leader, titleType, true, false, null, null, 1, 1);

            /*Position localDeputies =*/ Position.Create(organization, PositionLevel.GeographyDefault, null, null,
                                                         PositionType.Geographic_Deputy, titleType, true, false, localLeader, null, 1, 0);

            /*Position localAssistants =*/ Position.Create(organization, PositionLevel.GeographyDefault, null, null,
                                                           PositionType.Geographic_Assistant, titleType, false, false, localLeader, null, 0, 0);

            Position localOutreachLead = Position.Create(organization, PositionLevel.GeographyDefault, null, null,
                                                         PositionType.Geographic_OutreachLeader, titleType, true, true, localLeader, cmo, 0, 1);

            /*Position localOutreachAssistant =*/ Position.Create(organization, PositionLevel.GeographyDefault, null, null,
                                                                  PositionType.Geographic_OutreachLeaderAssistant, titleType, true, true, localOutreachLead, null, 0, 0);

            Position localActivismLead = Position.Create(organization, PositionLevel.GeographyDefault, null, null,
                                                         PositionType.Geographic_ActivismLeader, titleType, true, true, localLeader, coo, 0, 1);

            /*Position localActivismAssistant =*/ Position.Create(organization, PositionLevel.GeographyDefault, null, null,
                                                                  PositionType.Geographic_ActivismLeaderAssistant, titleType, true, true, localActivismLead, null, 0, 0);

            Position localSwarmLead = Position.Create(organization, PositionLevel.GeographyDefault, null, null,
                                                      PositionType.Geographic_SwarmLeader, titleType, true, true, localLeader, chiefHr, 0, 1);

            /*Position localSwarmLeadAssistant =*/ Position.Create(organization, PositionLevel.GeographyDefault, null, null,
                                                                   PositionType.Geographic_SwarmLeaderAssistant, titleType, true, true, localSwarmLead, null, 0, 0);

            Position localInfoLead = Position.Create(organization, PositionLevel.GeographyDefault, null, null,
                                                     PositionType.Geographic_InfoLeader, titleType, true, true, localLeader, chiefHr, 0, 1);

            /*Position localInfoLeadAssistant =*/ Position.Create(organization, PositionLevel.GeographyDefault, null, null,
                                                                  PositionType.Geographic_InfoLeaderAssistant, titleType, true, true, localInfoLead, null, 0, 0);
        }