public async Task <CustomerAddress> Address(string id) { REPO.Customer _cust = (from c in context.Customers where c.CustomerNumber == id select c).FirstOrDefault(); IEnumerable <REPO.Address> _addresses = _cust.Addresses.Where(a => a.AddressTypeCode == "01" || a.AddressTypeCode == "02"); CustomerAddress _custsaddr = new CustomerAddress(); _custsaddr.CustomerNumber = _cust.CustomerNumber; foreach (REPO.Address a in _addresses) { this.TransformAddress(a, _custsaddr); } ServicePartitionClient <HttpCommunicationClient> partitionClient = new ServicePartitionClient <HttpCommunicationClient>(communicationFactory, serviceUri, new ServicePartitionKey()); await partitionClient.InvokeWithRetryAsync( async (client) => { IEnumerable <Code> _request = CollectionBuilder.BuildAddressCodesRequest(_custsaddr); HttpResponseMessage response = await client.HttpClient.PostAsJsonAsync(new Uri(client.Url, "Services/Codes"), _request); IEnumerable <Code> _codes = await response.Content.ReadAsAsync <IEnumerable <Code> >(); _custsaddr = this.AddEnterpriseCodesToAddress(_custsaddr, _codes); }); return(_custsaddr); }
private async Task <Customer> EnrichCustomer(REPO.Customer cust) { Customer _final = this.TransformCustomer(cust); _final.HomePhone = cust.Phones.Where(p => p.PhoneTypeID == "01").FirstOrDefault() != null?cust.Phones.Where(p => p.PhoneTypeID == "01").FirstOrDefault().PhoneNumber : null; _final.MobilePhone = cust.Phones.Where(p => p.PhoneTypeID == "04").FirstOrDefault() != null?cust.Phones.Where(p => p.PhoneTypeID == "04").FirstOrDefault().PhoneNumber : null; string _accessToken = (User as ClaimsPrincipal).FindFirst("token").Value; ServicePartitionClient <HttpCommunicationClient> partitionClient = new ServicePartitionClient <HttpCommunicationClient>(communicationFactory, serviceUri, new ServicePartitionKey()); await partitionClient.InvokeWithRetryAsync( async (client) => { IEnumerable <Code> _request = CollectionBuilder.BuildCustomerCodesRequest(_final); client.HttpClient.SetBearerToken(_accessToken); HttpResponseMessage response = await client.HttpClient.PostAsJsonAsync(new Uri(client.Url, "Services/Codes"), _request); IEnumerable <Code> _codes = await response.Content.ReadAsAsync <IEnumerable <Code> >(); _final = this.AddEnterpriseCodesToCustomer(_final, _codes); }); return(_final); }
// GET services/customer/get/5 public async Task <Customer> Get(string id) { REPO.Customer _cust = (from c in context.Customers where c.CustomerNumber == id select c).FirstOrDefault(); Customer _final = await EnrichCustomer(_cust); return(_final); }
private Customer TransformCustomer(REPO.Customer c) { return(new Customer { BirthDate = c.BirthDate, CivilID = c.CivilID, CountryOfBirthCode = c.CountryOfBirth, OriginCountryCode = c.CountryOriginCode, GroupType = c.CustomerGroup, CustomerNumber = c.CustomerNumber, StatusCode = c.CustomerStatus, CustTypeCode = c.NBKCustomerType, EducationCode = c.EducationCode, FullNameArabic = c.FullNameArabic, FullNameEnglish = c.FullNameEnglish, Gender = c.GenderCode, IdentExpiryDate = c.IDExpiryDate, IdentNumber = c.IDNumber, IdentTypeCode = c.IDTypeCode, IdIssuePlaceCode = c.IDNationalityCode, IncomeSourceCode = c.CustomerIncomeTypeID, JobRankCode = c.Role_PositionCode, LanguageCode = c.LanguageCode, MaritalStatusCode = c.MaritalStatusCode, //NationalityCode = c.NationalityCode, NationalityCode = c.CountryOriginCode, OccupationCode = c.OccupationCode, PackageCode = c.PackageTypeCode, ResidencyStatusCode = c.ResidencyStatusCode, SalaryAmount = c.SalaryAmount, SalaryRangeCode = c.SalaryRangeCode, ShortName = c.ShortName, Title = c.Title, WorkplaceCode = c.EmployerCode, Email = c.Email }); }