public async Task <Result <AffiliateManageModel> > GetAffiliate(string id) { int idAffiliate = 0; if (id != null && !Int32.TryParse(id, out idAffiliate)) { throw new NotFoundException(); } if (idAffiliate == 0) { var now = DateTime.Now; now = new DateTime(now.Year, now.Month, now.Day); var defaultCountry = _referenceData.DefaultCountry; return(new AffiliateManageModel() { StatusCode = RecordStatusCode.NotActive, IdCountry = defaultCountry?.Id, PaymentType = AffiliateConstants.DefaultPaymentType, //Credit Tier = AffiliateConstants.DefaultTier, CommissionFirst = AffiliateConstants.DefaultCommissionFirst, CommissionAll = AffiliateConstants.DefaultCommissionAll, }); } var item = await _affiliateService.SelectAsync(idAffiliate); if (item == null) { throw new NotFoundException(); } AffiliateManageModel toReturn = await _mapper.ToModelAsync <AffiliateManageModel>(item); var login = await _affiliateUserService.GetAsync(toReturn.Id); if (login == null) { throw new AppValidationException(ErrorMessagesLibrary.Data[ErrorMessagesLibrary.Keys.CantFindLogin]); } toReturn.IsConfirmed = login.IsConfirmed; toReturn.PublicUserId = login.PublicId; CountryFilter filter = new CountryFilter(); var countries = await _countryService.GetCountriesAsync(filter); var country = countries.FirstOrDefault(p => p.Id == toReturn.IdCountry); if (country != null) { toReturn.CountryCode = country.CountryCode; var state = country.States.FirstOrDefault(p => p.Id == toReturn.IdState); if (state != null) { toReturn.StateCode = state.StateCode; } } return(toReturn); }