Ejemplo n.º 1
0
        public async Task SetFirmOrgIdListAsync(FirmOrg firmorg, int opportunityId, List <int> idList, CancellationToken cancel)
        {
            var oldIdList = await GetFirmOrgIdListAsync(firmorg, opportunityId, cancel);

            var removeIdList = oldIdList.Where(i => !idList.Contains(i)).ToList();
            var addIdList    = idList.Where(i => !oldIdList.Contains(i)).ToList();

            foreach (var i in removeIdList)
            {
                var request = _client.NewRequest("opportunities/{id}/{firmorg}/{oid}", Method.DELETE);
                request.AddUrlSegment("id", opportunityId.ToString());
                request.AddUrlSegment("firmorg", firmorg.ToString());
                request.AddUrlSegment("oid", i.ToString());
                await _client.ExecuteAsync(request, cancel);
            }

            if (addIdList.Any())
            {
                var fc = new FirmOrgContext();

                var request = _client.NewRequest("opportunities/{id}/{firmorg}", Method.POST);
                request.AddUrlSegment("id", opportunityId.ToString());
                request.AddUrlSegment("firmorg", firmorg.ToString());
                request.AddBody(addIdList.Select(
                                    i => new Dictionary <string, int> {
                    { fc.GetPrimaryKeyName(firmorg), i }
                }));

                await _client.ExecuteAsync(request, cancel);
            }
        }
Ejemplo n.º 2
0
        public async Task <List <int> > GetFirmOrgIdListAsync(FirmOrg firmorg, int opportunityId, CancellationToken cancel)
        {
            var fc = new FirmOrgContext();

            var request = _client.NewRequest("opportunities/{id}/{firmorg}");

            request.AddUrlSegment("id", opportunityId.ToString());
            request.AddUrlSegment("firmorg", firmorg.ToString());
            request.AddQueryParameter("fields", fc.GetPrimaryKeyName(firmorg));

            switch (firmorg)
            {
            case FirmOrg.Offices:
                var officeResponse = await _client.ExecuteAsync <List <Office> >(request, cancel);

                return(officeResponse.Data.Where(x => x.OfficeID.HasValue).Select(x => x.OfficeID.Value).ToList());

            case FirmOrg.Divisions:
                var divisionResponse = await _client.ExecuteAsync <List <Division> >(request, cancel);

                return(divisionResponse.Data.Where(x => x.DivisionID.HasValue).Select(x => x.DivisionID.Value).ToList());

            case FirmOrg.Studios:
                var studioResponse = await _client.ExecuteAsync <List <Studio> >(request, cancel);

                return(studioResponse.Data.Where(x => x.StudioID.HasValue).Select(x => x.StudioID.Value).ToList());

            case FirmOrg.PracticeAreas:
                var practiceAreasResponse = await _client.ExecuteAsync <List <PracticeArea> >(request, cancel);

                return(practiceAreasResponse.Data.Where(x => x.PracticeAreaID.HasValue).Select(x => x.PracticeAreaID.Value).ToList());

            case FirmOrg.Territories:
                var territoryResponse = await _client.ExecuteAsync <List <Territory> >(request, cancel);

                return(territoryResponse.Data.Where(x => x.TerritoryID.HasValue).Select(x => x.TerritoryID.Value).ToList());

            default:
                throw new ArgumentOutOfRangeException(nameof(firmorg), firmorg, null);
            }
        }