public async Task <CustomerProfile> GetCustomersAsync(CustomerInquiryFilter customerInquiryFilter) { var query = (from c in _customerInquiryDBContext.Customers.Include("Transactions") select new CustomerProfile { CustomerId = c.CustomerId, Name = c.CustomerName, Email = c.ContactEmail, MobileNumber = c.MobileNumber, RecentTransactions = c.RecentTransactions.OrderByDescending(x => x.TransactionDateTime).Take(5).ToList() }); if (string.IsNullOrEmpty(customerInquiryFilter.Email)) { query = query.Where(x => x.CustomerId == customerInquiryFilter.CustomerId); } else if (customerInquiryFilter.CustomerId == null) { query = query.Where(x => x.Email == customerInquiryFilter.Email); } else { query = query.Where(x => x.CustomerId == customerInquiryFilter.CustomerId && x.Email == customerInquiryFilter.Email); } return(await query.FirstOrDefaultAsync()); }
public async Task <CustomerProfileDTO> GetCustomerProfile(CustomerInquiryFilterDTO customerInquiry) { try { CustomerProfileDTO customerProfileDTO = null; var customerInquiryFilter = new CustomerInquiryFilter { CustomerId = customerInquiry.CustomerId, Email = customerInquiry.Email }; var customerProfile = await _customerRepository.GetCustomersAsync(customerInquiryFilter); if (customerProfile == null) { return(customerProfileDTO); } customerProfileDTO = new CustomerProfileDTO { CustomerId = customerProfile.CustomerId, Name = customerProfile.Name, Email = customerProfile.Email, MobileNumber = customerProfile.Email, RecentTransactions = customerProfile.RecentTransactions.Select(x => new TransactionDTO { TransactionId = x.TransactionId, Amount = x.Amount, Date = x.TransactionDateTime, CurrencyCode = x.CurrencyCode.ToString(), TransactionStatus = x.Status.ToString() }).ToList() }; return(customerProfileDTO); } catch (System.Exception ex) { throw ex; } }