public async Task <GetCustomerForViewDto> GetCustomerForView(int id) { var customer = await _customerRepository.GetAll().FirstOrDefaultAsync(b => b.Id == id); if (customer == null) { throw new UserFriendlyException($"No Customer With Id {id}"); } var country = await _countryRepository.FirstOrDefaultAsync(c => c.Id == customer.CountryId); var nationality = await _countryRepository.FirstOrDefaultAsync(c => c.Id == customer.NationalityId); var gender = await _lookupRepository.FirstOrDefaultAsync(c => c.Id == customer.GenderId); Region region = null; if (customer.RegionId.HasValue && customer.RegionId > 0) { region = await _regionRepository.FirstOrDefaultAsync(c => c.Id == customer.RegionId); } City city = null; if (customer.CityId.HasValue && customer.CityId > 0) { city = await _cityRepository.FirstOrDefaultAsync(c => c.Id == customer.CityId); } Lookup maritalStatus = null; if (customer.MaritalStatusId.HasValue && customer.MaritalStatusId > 0) { maritalStatus = await _lookupRepository.FirstOrDefaultAsync(l => l.Id == customer.MaritalStatusId); } var output = new GetCustomerForViewDto { Id = customer.Id, Code = customer.Code, FullName = customer.FullName.CurrentCultureText, DateOfBirth = customer.DateOfBirth, Email = customer.Email, NoOfDependencies = customer.NoOfDependencies, Notes = customer.Notes, PrimaryMobileNumber = customer.PrimaryMobileNumber, SecondaryMobileNumber = customer.SecondaryMobileNumber, PersonalPhoto = customer.PersonalPhoto, IsActive = customer.IsActive, Country = country?.Name.CurrentCultureText, Nationality = nationality?.Nationality.CurrentCultureText, Region = region?.Name.CurrentCultureText, City = city?.Name.CurrentCultureText, Gender = gender?.Name.CurrentCultureText, MaritalStatus = maritalStatus?.Name.CurrentCultureText, Address = customer.Address }; return(output); }
public async Task <GetCustomerForViewDto> GetCustomerForView(int id) { var customer = await _customerRepository.GetAsync(id); var output = new GetCustomerForViewDto { Customer = ObjectMapper.Map <CustomerDto>(customer) }; return(output); }
public async Task <GetCustomerForViewDto> GetCustomerForView(int?id) { // START UPDATE // Add this code to enable the Customer Profile to work -- NB: made 'id' nullable and updated the Interface accordingly Customer currentCustomer; int customerId; if (id == null) { currentCustomer = _customerRepository.GetAll().Where(e => e.TenantId == AbpSession.TenantId).FirstOrDefault(); if (currentCustomer == null) { return(new GetCustomerForViewDto()); } customerId = currentCustomer.Id; } else { customerId = (int)id; } var customer = await _customerRepository.GetAsync(customerId); // END UPDATE // var output = new GetCustomerForViewDto { Customer = ObjectMapper.Map <CustomerDto>(customer) }; if (output.Customer != null) { var _lookupCustomerType = await _lookup_customerTypeRepository.FirstOrDefaultAsync((int)output.Customer.CustomerTypeId); output.CustomerTypeType = _lookupCustomerType.Type.ToString(); } if (output.Customer.CurrencyId != null) { var _lookupCurrency = await _lookup_currencyRepository.FirstOrDefaultAsync((int)output.Customer.CurrencyId); output.CurrencyCode = _lookupCurrency.Code.ToString(); } if (!string.IsNullOrWhiteSpace(output.Customer.LogoUrl)) { int length = (output.Customer.LogoUrl.Length >= 36) ? 36 : output.Customer.LogoUrl.Length; output.Customer.LogoUrl = string.Format("{0}...", output.Customer.LogoUrl.Substring(0, 36)); } if (!string.IsNullOrWhiteSpace(output.Customer.Website)) { int length = (output.Customer.Website.Length >= 36) ? 36 : output.Customer.Website.Length; output.Customer.Website = string.Format("{0}...", output.Customer.Website.Substring(0, 36)); } return(output); }
public async Task <GetCustomerForViewDto> GetCustomerForView(int id) { var customer = await _customerRepository.GetAsync(id); var output = new GetCustomerForViewDto { Customer = ObjectMapper.Map <CustomerDto>(customer) }; if (output.Customer.CustomerCategoryId != null) { var _lookupCustomerCategory = await _lookup_customerCategoryRepository.FirstOrDefaultAsync((int)output.Customer.CustomerCategoryId); output.CustomerCategoryName = _lookupCustomerCategory?.Name?.ToString(); } return(output); }