Пример #1
0
        public async Task <IActionResult> Update([FromRoute] Guid organizationId,
                                                 [FromBody] MarketingOrganizationInput input)
        {
            var result = await _organizationService
                         .UpdateOrganization(_marketingAgencyOwner.Value, input);

            if (result.Succeeded)
            {
                return(await Get(organizationId));
            }

            return(Ok(result));
        }
Пример #2
0
        public async Task <OrganizationResult> UpdateOrganization(IMarketingAgencyOwner agencyOwner, MarketingOrganizationInput input)
        {
            _logger.LogInformation(GetLogMessage("Organization:{0}; input:{@input}"), agencyOwner.OrganizationId, input);

            var marketingOrganization = await Repository.Queryable()

                                        .Include(x => x.MarketingOrganization)
                                        .Include(x => x.Marketers)

                                        .Where(x => x.Id == agencyOwner.OrganizationId)
                                        .Select(x => x.MarketingOrganization)
                                        .FirstAsync();

            var organization = await Repository.Queryable()
                               .Where(x => x.Id == agencyOwner.OrganizationId)
                               .FirstOrDefaultAsync();

            return(await UpdateMarketingOrganization(marketingOrganization, input, organization));
        }
Пример #3
0
        public Task <OrganizationResult> UpdateMarketingOrganization(MarketingOrganization marketingOrganization, MarketingOrganizationInput input, Organization organization)
        {
            _logger.LogInformation(GetLogMessage("Organization:{0}; input:{@input}"), marketingOrganization.Id, input);

            marketingOrganization.InjectFrom(input);

            marketingOrganization.Updated      = DateTimeOffset.UtcNow;
            marketingOrganization.ObjectState  = ObjectState.Modified;
            marketingOrganization.Discoverable = input.Discoverable;

            marketingOrganization.MarketerStream        = input.MarketerStream;
            marketingOrganization.MarketerBonus         = input.MarketerBonus;
            marketingOrganization.MarketingAgencyStream = input.MarketingAgencyStream;
            marketingOrganization.MarketingAgencyBonus  = input.MarketingAgencyBonus;

            organization.MarketingOrganization = marketingOrganization;

            var result = Repository.InsertOrUpdateGraph(organization, true);

            _logger.LogDebug(GetLogMessage("{0} Records updated"), result);

            return(Task.FromResult(new OrganizationResult()
            {
                OrganizationId = organization.Id,
                Succeeded = result > 0
            }));
        }
        public async Task <OrganizationResult> UpgradeOrganization(IOrganizationCustomer organizationCustomer,
                                                                   OrganizationUpgradeInput input)
        {
            _logger.LogInformation(GetLogMessage("Upgrade Organization Id: {input}"), organizationCustomer.OrganizationId);

            var retVal = new OrganizationResult()
            {
                OrganizationId = organizationCustomer.OrganizationId
            };

            var organization = await Repository.Queryable()
                               .Include(x => x.ProviderOrganization)
                               .Include(x => x.MarketingOrganization)
                               .Include(x => x.RecruitingOrganization)
                               .Include(x => x.OrganizationPeople)
                               .ThenInclude(x => x.Marketer)
                               .Include(x => x.OrganizationPeople)
                               .ThenInclude(x => x.Customer)
                               .Include(x => x.OrganizationPeople)
                               .ThenInclude(x => x.Contractor)
                               .Include(x => x.OrganizationPeople)
                               .ThenInclude(x => x.ProjectManager)
                               .Include(x => x.OrganizationPeople)
                               .ThenInclude(x => x.AccountManager)
                               .Include(x => x.OrganizationPeople)
                               .ThenInclude(x => x.Recruiter)
                               .Where(x => x.Id == organizationCustomer.OrganizationId)
                               .FirstAsync();

            _logger.LogDebug(GetLogMessage("Organization Found: {Organization}"), organization.OrganizationType.ToString());

            var upgradeProviderOrg   = (input.ProviderOrganizationInput != null);
            var upgradeMarketingOrg  = (input.MarketingOrganizationInput != null);
            var upgradeRecruitingOrg = (input.RecruitingOrganizationInput != null);

            _logger.LogDebug(GetLogMessage("Upgrade Provider Org: {Provider}; Upgrade Marketing Org: {Marketing}; Upgrade Recruiting Org {Recruiting}"),
                             upgradeProviderOrg,
                             upgradeMarketingOrg,
                             upgradeRecruitingOrg);

            var orgPerson = organization
                            .OrganizationPeople
                            .First(x => x.PersonId == organizationCustomer.CustomerId);

            _logger.LogDebug(GetLogMessage("Person: {PersonId}"), orgPerson.PersonId);


            orgPerson.ObjectState = ObjectState.Modified;

            organization.CategoryId  = input.CategoryId;
            organization.UpdatedById = _userInfo.Value.UserId;
            organization.ObjectState = ObjectState.Modified;
            organization.Updated     = DateTimeOffset.UtcNow;

            if (upgradeProviderOrg)
            {
                if (organization.ProviderOrganization != null)
                {
                    retVal.ErrorMessage = "Provider organization is already upgraded";
                    return(retVal);
                }

                _logger.LogInformation(GetLogMessage("Upgrading to Provider Organization..."));

                var upgradeResult = UpgradeToProviderOrganization(input.ProviderOrganizationInput, organization, orgPerson, true);

                if (!upgradeMarketingOrg && organization.MarketingOrganization == null)
                {
                    // add so we have a default marketer in the org
                    orgPerson.Marketer = new OrganizationMarketer()
                    {
                        Updated        = DateTimeOffset.UtcNow,
                        Created        = DateTimeOffset.UtcNow,
                        MarketerId     = orgPerson.PersonId,
                        OrganizationId = orgPerson.OrganizationId,
                        MarketerStream = 0,
                        MarketerBonus  = 0,
                        ObjectState    = ObjectState.Added
                    };
                }

                if (!upgradeRecruitingOrg && organization.RecruitingOrganization == null)
                {
                    // add so we have a default recruiter
                    orgPerson.Recruiter = new OrganizationRecruiter()
                    {
                        Updated         = DateTimeOffset.UtcNow,
                        Created         = DateTimeOffset.UtcNow,
                        RecruiterId     = orgPerson.PersonId,
                        OrganizationId  = orgPerson.OrganizationId,
                        RecruiterStream = 0,
                        ObjectState     = ObjectState.Added,
                    };
                }
            }


            if (upgradeMarketingOrg)
            {
                if (organization.MarketingOrganization != null)
                {
                    throw new ApplicationException("Marketing organization is already upgraded");
                }

                _logger.LogDebug(GetLogMessage("Upgrading to Marketing Organization..."));

                var newMarketingOrgInput = new MarketingOrganizationInput()
                {
                    DefaultMarketerId = orgPerson.PersonId
                }.InjectFrom(input.MarketingOrganizationInput) as MarketingOrganizationInput;


                retVal = UpgradeToMarketingOrganization(newMarketingOrgInput, organization, orgPerson, true);
            }

            if (upgradeRecruitingOrg)
            {
                if (organization.RecruitingOrganization != null)
                {
                    retVal.ErrorMessage = "Recruiting organization is already upgraded";
                    return(retVal);
                }

                _logger.LogDebug(GetLogMessage("Upgrading to Recruiting Organization..."));

                retVal = UpgradeToRecruitingOrganization(input.RecruitingOrganizationInput, organization, orgPerson, true);
            }

            return(retVal);
        }