コード例 #1
0
        private async Task <Result> ApplyBonus(MaterializationData data)
        {
            var applyBonusTask = data.ScopeType switch
            {
                SubjectMarkupScopeTypes.Agency => ApplyAgencyScopeBonus(),
                SubjectMarkupScopeTypes.Agent => ApplyAgentScopeBonus(),
                _ => Task.FromResult(Result.Failure($"MarkupPolicyScopeType {data.ScopeType} is not supported"))
            };

            return(await applyBonusTask);


            Task <Result> ApplyAgentScopeBonus()
            {
                var agentInAgency = AgentInAgencyId.Create(data.SubjectScopeId);

                return(ApplyAgencyBonus(data.PolicyId, data.ReferenceCode, agentInAgency.AgencyId, data.Amount));
            }

            async Task <Result> ApplyAgencyScopeBonus()
            {
                var parentAgencyId = await _context.Agencies
                                     .Where(a => a.Id.ToString() == data.SubjectScopeId)
                                     .Select(a => a.ParentId)
                                     .SingleOrDefaultAsync();

                if (parentAgencyId is null)
                {
                    return(Result.Failure($"Cannot retrieve parent agency for agency id '{data.SubjectScopeId}'"));
                }

                return(await ApplyAgencyBonus(data.PolicyId, data.ReferenceCode, parentAgencyId.Value, data.Amount));
            }
        }
コード例 #2
0
        private async Task <Result <MarkupPolicy> > GetAgentPolicy(AgentAgencyRelation relation, int policyId)
        {
            var agentInAgencyId = AgentInAgencyId.Create(agentId: relation.AgentId, agencyId: relation.AgencyId).ToString();
            var policy          = await _context.MarkupPolicies
                                  .SingleOrDefaultAsync(p => p.Id == policyId && p.SubjectScopeType == SubjectMarkupScopeTypes.Agent && p.SubjectScopeId == agentInAgencyId);

            return(policy ?? Result.Failure <MarkupPolicy>("Could not find agent policy"));
        }
コード例 #3
0
        private Task <List <MarkupPolicy> > GetAgentPolicies(int agentId, int agencyId)
        {
            var agentInAgencyId = AgentInAgencyId.Create(agentId: agentId, agencyId: agencyId).ToString();

            return(_context.MarkupPolicies
                   .Where(p => p.SubjectScopeType == SubjectMarkupScopeTypes.Agent && p.SubjectScopeId == agentInAgencyId)
                   .OrderBy(p => p.Order)
                   .ToListAsync());
        }
コード例 #4
0
        private async Task <string> GetAgentMarkupFormula(int agentId, int agencyId)
        {
            var agentScopeId = AgentInAgencyId.Create(agentId, agencyId).ToString();
            var policies     = await _context.MarkupPolicies
                               .Where(p => p.SubjectScopeId == agentScopeId && p.SubjectScopeType == SubjectMarkupScopeTypes.Agent)
                               .OrderBy(p => p.Order)
                               .ToListAsync();

            return(policies.Any()
                ? _markupPolicyTemplateService.GetMarkupsFormula(policies)
                : string.Empty);
        }
コード例 #5
0
ファイル: MarkupPolicyScope.cs プロジェクト: happy-travel/edo
 public void Deconstruct(out SubjectMarkupScopeTypes type, out int?agencyId, out int?agentId, out string agentScopeId)
 {
     type         = Type;
     agentScopeId = Type switch
     {
         SubjectMarkupScopeTypes.Global => "",
         SubjectMarkupScopeTypes.Country => LocationId,
         SubjectMarkupScopeTypes.Locality => LocationId,
         SubjectMarkupScopeTypes.Agency => AgencyId.ToString(),
         SubjectMarkupScopeTypes.Agent => AgentInAgencyId.Create(AgentId.Value, AgencyId.Value).ToString(),
         _ => throw new ArgumentOutOfRangeException(nameof(type), Type, "Wrong AgentMarkupScopeType")
     };
     agencyId = AgencyId;
     agentId  = AgentId;
 }
コード例 #6
0
        public void Markups_for_specific_agent_should_be_returned()
        {
            var markupSubject = new MarkupSubjectInfo
            {
                AgencyAncestors = new List <int>(),
                AgencyId        = 1,
                AgentId         = 1,
                CountryHtId     = "Russia",
                LocalityHtId    = "Moscow"
            };

            var markupDestination = GetDummyMarkupDestination();

            var markupPolicies = new List <MarkupPolicy>
            {
                new()
                {
                    Id                   = 1,
                    Order                = 1,
                    SubjectScopeType     = SubjectMarkupScopeTypes.Agent,
                    SubjectScopeId       = AgentInAgencyId.Create(agentId: 1, agencyId: 1).ToString(),
                    DestinationScopeType = DestinationMarkupScopeTypes.Global
                },
                new()
                {
                    Id                   = 2,
                    Order                = 2,
                    SubjectScopeType     = SubjectMarkupScopeTypes.Agent,
                    SubjectScopeId       = AgentInAgencyId.Create(agentId: 2, agencyId: 1).ToString(),
                    DestinationScopeType = DestinationMarkupScopeTypes.Global,
                },
                new()
                {
                    Id                   = 3,
                    Order                = 1,
                    SubjectScopeType     = SubjectMarkupScopeTypes.Agent,
                    SubjectScopeId       = AgentInAgencyId.Create(agentId: 1, agencyId: 2).ToString(),
                    DestinationScopeType = DestinationMarkupScopeTypes.Global
                }
            };

            var service = MarkupPolicyServiceMock.Create(markupPolicies);

            var policies = service.Get(markupSubject, markupDestination, default);

            Assert.Single(policies);
            Assert.Equal(1, policies[0].Id);
        }
コード例 #7
0
        public Task <Result> Add(int agentId, MarkupPolicySettings settings, AgentContext agent)
        {
            return(ValidateSettings(agentId, agent.AgencyId, settings)
                   .Bind(() => GetAgentAgencyRelation(agentId, agent.AgencyId))
                   .Bind(SavePolicy)
                   .Tap(WriteAuditLog)
                   .Bind(UpdateDisplayedMarkupFormula));


            async Task <Result <MarkupPolicy> > SavePolicy(AgentAgencyRelation agentAgencyRelation)
            {
                var(_, isFailure, destinationScopeType, error) = await GetDestinationScopeType(settings.DestinationScopeId);

                if (isFailure)
                {
                    return(Result.Failure <MarkupPolicy>(error));
                }

                var now             = _dateTimeProvider.UtcNow();
                var agentInAgencyId = AgentInAgencyId.Create(agentAgencyRelation.AgentId, agentAgencyRelation.AgencyId);

                var policy = new MarkupPolicy
                {
                    Description          = settings.Description,
                    Order                = settings.Order,
                    Target               = MarkupPolicyTarget.AccommodationAvailability,
                    SubjectScopeType     = SubjectMarkupScopeTypes.Agent,
                    SubjectScopeId       = agentInAgencyId.ToString(),
                    DestinationScopeType = destinationScopeType,
                    DestinationScopeId   = settings.DestinationScopeId,
                    TemplateSettings     = settings.TemplateSettings,
                    Currency             = settings.Currency,
                    Created              = now,
                    Modified             = now,
                    TemplateId           = settings.TemplateId
                };

                _context.MarkupPolicies.Add(policy);
                await _context.SaveChangesAsync();

                return(policy);
            }

            Task WriteAuditLog(MarkupPolicy policy)
            => _markupPolicyAuditService.Write(MarkupPolicyEventType.AgentMarkupCreated,
                                               new AgentMarkupPolicyData(policy.Id, agentId, agent.AgencyId),
                                               agent.ToApiCaller());
        }
コード例 #8
0
        public void Specific_agent_and_specific_hotel()
        {
            var markupSubject = new MarkupSubjectInfo
            {
                AgencyAncestors = new List <int>(),
                AgencyId        = 1,
                AgentId         = 1,
                CountryHtId     = "Russia",
                LocalityHtId    = "Moscow"
            };

            var markupDestination = new MarkupDestinationInfo
            {
                AccommodationHtId = "President Hotel",
                CountryHtId       = "UAE",
                LocalityHtId      = "Dubai"
            };

            var markupPolicies = new List <MarkupPolicy>
            {
                new()
                {
                    Id                   = 1,
                    Order                = 1,
                    SubjectScopeType     = SubjectMarkupScopeTypes.Agent,
                    SubjectScopeId       = AgentInAgencyId.Create(agentId: 1, agencyId: 1).ToString(),
                    DestinationScopeType = DestinationMarkupScopeTypes.Accommodation,
                    DestinationScopeId   = "President Hotel"
                },
                new()
                {
                    Id                   = 2,
                    Order                = 2,
                    SubjectScopeType     = SubjectMarkupScopeTypes.Agent,
                    SubjectScopeId       = AgentInAgencyId.Create(agentId: 2, agencyId: 1).ToString(),
                    DestinationScopeType = DestinationMarkupScopeTypes.Accommodation,
                    DestinationScopeId   = "President Hotel"
                }
            };

            var service = MarkupPolicyServiceMock.Create(markupPolicies);

            var policies = service.Get(markupSubject, markupDestination, default);

            Assert.Single(policies);
            Assert.Equal(1, policies[0].Id);
        }
    }
コード例 #9
0
        public void Ordering_by_subject_scope_type()
        {
            var markupSubject = new MarkupSubjectInfo
            {
                AgencyAncestors = new List <int>(),
                AgencyId        = 1,
                AgentId         = 1,
                CountryHtId     = "Russia",
                LocalityHtId    = "Moscow"
            };

            var markupDestination = new MarkupDestinationInfo
            {
                AccommodationHtId = "President Hotel",
                CountryHtId       = "UAE",
                LocalityHtId      = "Dubai"
            };

            var markupPolicies = new List <MarkupPolicy>
            {
                new()
                {
                    Id                   = 9,
                    Order                = 1,
                    SubjectScopeType     = SubjectMarkupScopeTypes.Agent,
                    SubjectScopeId       = AgentInAgencyId.Create(agentId: 1, agencyId: 1).ToString(),
                    DestinationScopeType = DestinationMarkupScopeTypes.Global
                },
                new()
                {
                    Id                   = 7,
                    Order                = 4,
                    SubjectScopeType     = SubjectMarkupScopeTypes.Global,
                    DestinationScopeType = DestinationMarkupScopeTypes.Global
                },
                new()
                {
                    Id                   = 5,
                    Order                = 1,
                    SubjectScopeType     = SubjectMarkupScopeTypes.Country,
                    SubjectScopeId       = "Russia",
                    DestinationScopeType = DestinationMarkupScopeTypes.Global
                },
                new()
                {
                    Id                   = 2,
                    Order                = 2,
                    SubjectScopeType     = SubjectMarkupScopeTypes.Agency,
                    SubjectScopeId       = "1",
                    DestinationScopeType = DestinationMarkupScopeTypes.Global
                },
                new()
                {
                    Id                   = 8,
                    Order                = 2,
                    SubjectScopeType     = SubjectMarkupScopeTypes.Locality,
                    SubjectScopeId       = "Moscow",
                    DestinationScopeType = DestinationMarkupScopeTypes.Global
                }
            };

            var service = MarkupPolicyServiceMock.Create(markupPolicies);

            var policies = service.Get(markupSubject, markupDestination, default);

            Assert.Equal(SubjectMarkupScopeTypes.Global, policies[0].SubjectScopeType);
            Assert.Equal(SubjectMarkupScopeTypes.Country, policies[1].SubjectScopeType);
            Assert.Equal(SubjectMarkupScopeTypes.Locality, policies[2].SubjectScopeType);
            Assert.Equal(SubjectMarkupScopeTypes.Agency, policies[3].SubjectScopeType);
            Assert.Equal(SubjectMarkupScopeTypes.Agent, policies[4].SubjectScopeType);
        }
    }
コード例 #10
0
        private Task <Result> UpdateDisplayedMarkupFormula(MarkupPolicy policy)
        {
            var agentInAgencyId = AgentInAgencyId.Create(policy.SubjectScopeId);

            return(_displayedMarkupFormulaService.UpdateAgentFormula(agentInAgencyId.AgentId, agentInAgencyId.AgencyId));
        }