Esempio n. 1
0
        public async Task <BillingsResponse <CurrentAllocatedBilling> > GetCurrentAllocatedBillings([FromRoute] SubjectType subjectType)
        {
            var resp = await(await factory.GetBillingClient())
                       .GetCurrentAllocatedBillingsAsync(new AcademyCloud.Expenses.Protos.Billing.GetCurrentAllocatedBillingsRequest
            {
                SubjectType = subjectType
            });

            // get names
            var subjects = new List <GetNamesRequest.Types.Subject>(resp.Billings.Count * 2);

            resp.Billings.ForEach(x =>
            {
                subjects.Add(new GetNamesRequest.Types.Subject()
                {
                    Type = GetNamesRequest.Types.SubjectType.User, Id = x.PayerId
                });
                subjects.Add(new GetNamesRequest.Types.Subject()
                {
                    Type = (GetNamesRequest.Types.SubjectType)subjectType, Id = x.SubjectId
                });
            });

            var namesResp = await(await factory.GetIdentityInteropClientAsync())
                            .GetNamesAsync(new GetNamesRequest {
                Subjects = { subjects }
            });

            return(new BillingsResponse <CurrentAllocatedBilling>
            {
                Billings = resp.Billings.Select(x => FromGrpc(x, namesResp.IdNameMap)),
            });
        }